看板 MATLAB 關於我們 聯絡資訊
小弟我剛學MATLAB 我想用梯形法求exp(-x^2)積分 [0,2] 切n=500 不知道哪裡出錯了 麻煩高手指導一下 謝謝 a=0; b=2; n=500; A=0; for x=a:(b-a)/n:b   if x==a    f1= exp(-x^2);   else    f2 = exp(-x^2);    A = A+0.5*(f1+f2)*(b-a)/n;    f1 = f2;   end end disp('梯形積分法面積='); A -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.117.243.84
Rasin:沒有錯喔 實際值0.88208... 梯形0.8821 12/03 14:30
handsomepow:但是我跑不出來 0.0||| 12/03 15:14
他跑出 ??? Error: File: Untitled2.m Line: 6 Column: 1 The input character is not valid in MATLAB statements or expressions. ※ 編輯: handsomepow 來自: 122.117.243.84 (12/03 15:18)
Rasin:那些空格(空白字元)有問題 迴圈那些前面的空格刪掉重空 12/03 15:55
Rasin:再步行乾脆就別空 12/03 15:55
handsomepow:謝謝 可以了 可以幫我看上上篇那題嗎 12/03 15:57
Rasin:已經有人說了 12/03 15:59
handsomepow:但是我不太懂 12/03 16:03
Rasin:你把分號拿掉 讓它顯示值 12/03 16:06
handsomepow:會一直跑不停 =.= 12/03 16:13
Rasin:CTRL+C 12/03 16:14