Why does my loop only run once
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Raquel Terrer van Gool
am 14 Apr. 2020
Kommentiert: Raquel Terrer van Gool
am 14 Apr. 2020
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 Kommentare
Akzeptierte Antwort
Peng Li
am 14 Apr. 2020
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!