Make a numerical iteration using while loop

3 次查看(过去 30 天)
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