Why does my loop only run once
12 次查看(过去 30 天)
显示 更早的评论
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!