Why does my loop only run once

14 vues (au cours des 30 derniers jours)
Raquel Terrer van Gool
Raquel Terrer van Gool le 14 Avr 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

Réponse acceptée

Peng Li
Peng Li le 14 Avr 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.
  1 commentaire
Raquel Terrer van Gool
Raquel Terrer van Gool le 14 Avr 2020
Okay, thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by