Make a numerical iteration using while loop

3 visualizzazioni (ultimi 30 giorni)
Ornella Fanais
Ornella Fanais il 23 Mar 2017
Commentato: Ornella Fanais il 24 Mar 2017
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

Risposte (1)

Roger Stafford
Roger Stafford il 23 Mar 2017
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 Commento
Ornella Fanais
Ornella Fanais il 24 Mar 2017
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

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by