Why does my loop only run once

11 次查看(过去 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

采纳的回答

Peng Li
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by