MATLAB: Does the loop only run once

loop

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

Best Answer

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.
Related Question