How do I put the code below into one big loop so I do not have to copy and paste no more?
조회 수: 1 (최근 30일)
이전 댓글 표시
h = 0.01;
A = 8000/11;
T(1)=80;
x(1)=0;
prompt = ('Guess initial Z value');
Z(1) = input(prompt);
for i=2:5
x(i) = x(i-1)+h;
T(i) = T(i-1) + h*Z(i-1)
Z(i) = Z(i-1) + h*(A*(T(i-1)-20));
end
Z1(1) = Z(1) - Z(4)
T1(1)= 80
for j=2:5
x(j) = x(j-1)+h;
T1(j) = T1(j-1) + h*Z1(j-1)
Z1(j) = Z1(j-1) + h*(A*(T1(j-1)-20));
end
Z2(1) = Z1(1) - Z1(4)
T2(1)= 80
for k=2:5
x(k) = x(k-1)+h;
T2(k) = T2(k-1) + h*Z2(k-1)
Z2(k) = Z2(k-1) + h*(A*(T2(k-1)-20));
end
Z3(1) = Z2(1) - Z2(4)
T3(1) = 80
for p=2:5
x(p) = x(p-1)+h;
T3(p) = T3(p-1) + h*Z3(p-1)
Z3(p) = Z3(p-1) + h*(A*(T3(p-1)-20));
end
댓글 수: 2
Jan
2019년 1월 4일
You forgot to mention, what you want to change inside the loop. But actually, either for or while will solve your problem.
답변 (1개)
참고 항목
카테고리
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!