Make a numerical iteration using while loop
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello everyone, I'm new!! How can I make a iteration process whit While Loop?
- I have this formula: T_tc=((sigma*ew*(Tw^4-Tb^4))/h)+Tinf
- I know sigma, ew,Tw,h,Tinf
- I have to start the iteration process to Tb value for example 20
- for the next iteration I have to use the result of T_tc.
- the condition is: I have to stop when I find a steady result.
The script that I write is:
Tb=20
T_tc=((sigma*ew*(Tw^4-Tb^4))/h)+Tinf
while T_tc<Tb
Tb=T_tc
end
Thanks
댓글 수: 0
답변 (1개)
Roger Stafford
2017년 3월 23일
You need to place the computation of T_tc inside the while loop. As it stands, there will be no change to Tb after the first trip through. Also the “steady” condition probably needs to be changed to some tolerated absolute difference.
Tb=20;
T_tc=((sigma*ew*(Tw^4-Tb^4))/h)+Tinf;
while abs(T_tc-Tb) > tol % ’tol’ is some tolerated difference
Tb=T_tc;
T_tc=((sigma*ew*(Tw^4-Tb^4))/h)+Tinf;
end
[Note: Equality of your equation will be with one of the four roots of a quartic equation. Which of the four is found may depend on what initial value for Tb you begin with.]
참고 항목
카테고리
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!