What is this error in my iterative program?
Mostrar comentarios más antiguos
Im to solve for the temperature of the plate Tw, but to do so I need to know coefficient of convection h which is dependent on Tw. This is done via an iterative solution, only,
I'm not sure what the errors are that I am seeing here.
In addition to troubleshooting the error here, I am open to any advice of how the program can be improved (better method, clarity, formatting, etc.).
Thanks yall, I will respond to any questions as soon as possible.
flatplate_iteration.m
clear;
clc;
airProp=readtable('airProp_table.txt');
Tw= 30;
Ti=25;
ui=3;
L=.25;
A=L^2;
h=800/(Tw-Ti);
Nu=0;
k=0;
h_calc=Nu*k/L;
S=10;
while S>.001
i=1;
T1=airProp.Temperature(i);
Tf=(Tw-Ti)/2;
difference=Tf-T1;
while difference>=5
i=i+1;
T1=airProp.Temperature(i);
difference=Tf-T1;
end
if difference==0
d=airProp.Density(i);
mu=airProp.DynamicViscosity(i);
Pr=airProp.PrandtlNumber(i);
k=airProp.ThermalConductivity(i);
else
clear T2 d1 d2 mu1 mu2 Pr1 Pr2 k1 k2;
T2=airProp.Temperature(i+1);
d1=airProp.Density(i);
d2=airProp.Density(i+1);
d=d1+(Tf-T1)*(d2-d1)/(T2-T1);
mu1=airProp.DynamicViscosity(i);
mu2=airProp.DynamicViscosity(i+1);
mu=mu1+(Tf-T1)*(mu2-mu1)/(T2-T1);
Pr1=airProp.PrandtlNumber(i);
Pr2=airProp.PrandtlNumber(i+1);
Pr=Pr1+(Tf-T1)*(Pr2-Pr1)/(T2-T1);
k1=airProp.ThermalConductivity(i);
k2=airProp.ThermalConductivity(i+1);
k=k1+(Tf-T1)*(k2-k1)/(T2-T1);
end
Re=d*ui*L/mu;
Nu=.664*Re^(1/2)*Pr^(1/3);
h_calc=Nu*k/L;
h=800/(Tw-Ti);
T_calc=Tw;
Tw=Tw+.1;
S=abs(h_calc-h);
end
2 comentarios
Tommy
el 7 de Abr. de 2020
The error I get occurs when i equals 30. This line:
T2=airProp.Temperature(i+1);
fails because your table airProp only has 30 rows and you are trying to access row #31. This happens after many iterations. I see that you are updating Tw on every iteration of the (outer) loop. How can you be sure that this code:
i=1;
T1=airProp.Temperature(i);
Tf=(Tw-Ti)/2;
difference=Tf-T1;
while difference>=5
i=i+1;
T1=airProp.Temperature(i);
difference=Tf-T1;
end
always leaves i with a value equal to 29 or less? (At the moment, it doesn't.)
Rik
el 7 de Abr. de 2020
You could also replace this entire loop by an array comparison.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!