Why does my loop only run once
7 ビュー (過去 30 日間)
古いコメントを表示
Raquel Terrer van Gool
2020 年 4 月 14 日
コメント済み: Raquel Terrer van Gool
2020 年 4 月 14 日
function I=trapezoidal(f,a,b,n)
h=(b-a)/n; % length of the interval
total=0;
x=a;
fa=f;
x=b;
fb=f;
for i=n
x=i;
fn=f+total
total=fn
end
I=fa+fb+2*fn;
end
0 件のコメント
採用された回答
Peng Li
2020 年 4 月 14 日
I assume that your parameter n is a scalar? If you want to let your script loop from 1 through n, you use for i = 1:n.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!