Make a numerical iteration using while loop
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Roger Stafford
el 23 de Mzo. de 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.]
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!