How to plot a values inside a while loop .

I need help , i want to plot the evelotion of time t and Temperateurs T1-T2-T3-T4-T5-T6-T7-T8-Tout but all i got is a blank graph when i use the plot . i know that i need to store all the values in an array , but i couldnt do it . so i need also to see how i can store all the iterations insode a big array , and how can i plot the temperateurs in function of tima t .
please help ;
Thank you .
clc; clear;
LmdC=1.6;
LmdIn=0.04;
RoC=1800;
RoIn=100;
CpC=900;
CpIn=1100;
h=10;
DxC=0.02;
DxIn=0.05;
Dt=200;
t=0;
AC=(LmdC/DxC); %constant
AIn=(LmdIn/DxIn); %constant
DC=(Dt/(DxC*CpC*RoC)); %constant
DIn=(Dt/(DxIn*CpIn*RoIn)); %constant
AlphaC=(1/((DxC/2*LmdC)+(DxIn/2*LmdIn))); %constant
AlphaAir=(1/((DxIn/(2*LmdIn))+(1/h))); %constant
Tin=10;
TExt=0;
T1=0;
T2=0;
T3=0;
T4=0;
T5=0;
T6=0;
T7=0;
T8=0;
Tout=0;
while t<176400
H=3600;
fprintf('\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\n',t,T1,T2,T3,T4,T5,T6,T7,T8,Tout);
Tout=8*sin((pi/(12*H))*t);
T1=(AC*DC*(2*Tin-3*T1+T2))+T1;
T2=(AC*DC*(T1-2*T2+T3))+T2;
T3=(AC*DC*(T2-2*T3+T4))+T3;
T4=(AC*DC*(T3-2*T4+T5))+T4;
T5=((AC*(T4-T5)-(AlphaC*(T5-T6)))*DC)+T5;
T6=((AlphaC*(T5-T6)-(AIn*(T6-T7)))*DIn)+T6;
T7=(AIn*DIn*(T6-2*T7+T8))+T7;
T8=(AIn*(T7-T8)-(AlphaAir*(T8-Tout)))*DIn+T8;
%plot(t,T1,t,T2,t,T3,t,T4,t,T5,t,T6,t,T7,t,T8,t,Tout)
t=t+Dt;
end

Réponses (1)

Star Strider
Star Strider le 21 Sep 2020
The easiest way is to store the intermediate results, then plot them at the end:
while t<176400
H=3600;
fprintf('\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\t\t%g\n',t,T1,T2,T3,T4,T5,T6,T7,T8,Tout);
Tout=8*sin((pi/(12*H))*t);
T1=(AC*DC*(2*Tin-3*T1+T2))+T1;
T2=(AC*DC*(T1-2*T2+T3))+T2;
T3=(AC*DC*(T2-2*T3+T4))+T3;
T4=(AC*DC*(T3-2*T4+T5))+T4;
T5=((AC*(T4-T5)-(AlphaC*(T5-T6)))*DC)+T5;
T6=((AlphaC*(T5-T6)-(AIn*(T6-T7)))*DIn)+T6;
T7=(AIn*DIn*(T6-2*T7+T8))+T7;
T8=(AIn*(T7-T8)-(AlphaAir*(T8-Tout)))*DIn+T8;
Tm(i,:) = [t T1 T2 T3 T4 T5 T6 T7 T8 Tout]; % <— ADD THIS
i = i+1; % <— ADD THIS
t=t+Dt;
end
figure
plot(Tm(:,1),Tm(:,2:end))
grid
Then the plot appears after the loop.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by