Why does my loop only run once
조회 수: 8 (최근 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!