Make a numerical iteration using while loop

조회 수: 2 (최근 30일)
Ornella Fanais
Ornella Fanais 2017년 3월 23일
댓글: Ornella Fanais 2017년 3월 24일
Hello everyone, I'm new!! How can I make a iteration process whit While Loop?
  1. I have this formula: T_tc=((sigma*ew*(Tw^4-Tb^4))/h)+Tinf
  2. I know sigma, ew,Tw,h,Tinf
  3. I have to start the iteration process to Tb value for example 20
  4. for the next iteration I have to use the result of T_tc.
  5. 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

답변 (1개)

Roger Stafford
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.]
  댓글 수: 1
Ornella Fanais
Ornella Fanais 2017년 3월 24일
how can i do if don't use while loop, and I use for loop ? For example for i=293:1273 T(i)=(((sigma*ew*(Tw^4-Tb(i)^4))/h)+Tinf) end I do to start the cicle to 293=Tb and I need to get all value of T because I would to create a plot. Thanks for your help

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by