How do I plot the variables outside of the for loop for all iterations?
2 次查看(过去 30 天)
显示 更早的评论
I need to calculate different equations with 2 changing variables, the second variable depends on the first. I can plot inside the for loop, but I can't replicate the plot once it has been put outside of the for loop, it only plots the last iteration of the loop. Any advice?
clc;
close all;
clear all;
Patm = 18750;
Tatm = 216.7;
U = 250;
R = 287;
gamma_air = 1.4;
T04 = 1500;
Qr = 45000000;
B = 6;
eta_d=0.97;
eta_c=0.85;
eta_b=1;
eta_t=0.9;
eta_n=0.98;
eta_f=0.85;
eta_fn=0.97;
gamma_d=1.4;
gamma_c=1.37;
gamma_b=1.35;
gamma_t=1.33;
gamma_n=1.36;
gamma_f=1.4;
gamma_fn=1.4;
cp_c=(gamma_c/(gamma_c-1))*R;
cp_b=(gamma_b/(gamma_b-1))*R;
cp_n=(gamma_n/(gamma_n-1))*R;
cp_f=(gamma_f/(gamma_f-1))*R;
for Prc=5:0.5:40
Mach=U/sqrt(gamma_air*R*Tatm);
T02=(Tatm*(1+((gamma_d-1)/2)*Mach^2));
P02=(Patm*(1+eta_d*((T02/Tatm)-1))^(gamma_d/(gamma_d-1)));
P03=P02*Prc;
T03=(T02*(1+(1/eta_c)*(Prc^((gamma_c-1)/gamma_c)-1)));
for Prf=1:0.0001:5
P08=P02*Prf;
T08=(T02*(1+(1/eta_f)*(Prf^((gamma_f-1)/gamma_f)-1)));
T05=T04-(T03-T02)-(T08-T02)*B;
P05=P03*(1-(1/eta_t)*(1-T05/T04))^(gamma_t/(gamma_t-1));
P06=P05;
f=(T04-T03)/(Qr/cp_c-T04);
Ue=sqrt(2*eta_n*(gamma_n/(gamma_n-1))*R*T05*(1-(Patm/P05)^((gamma_n-1)/gamma_n)));
Uef=sqrt(2*eta_fn*(gamma_f/(gamma_f-1))*R*T08*(1-(Patm/P08)^((gamma_f-1)/gamma_f)));
SpecificThrust=(1+f)*(Ue+B)*(Uef-(1+B))*U;
TSFC=f/SpecificThrust;
break
end
end
figure(1)
hold on
plot(Prc,SpecificThrust,'-','LineWidth',2);
ylabel('Specific Thrsut (kN*s/kg)')
xlabel('Compressor Pressure Ratio')
grid on
title('Compression Ratio vs Specific Thrust')
2 个评论
Image Analyst
2019-12-7
Then why not just put the plotting code inside the Prc loop right after the end of the Prf loop?
回答(1 个)
David Hill
2019-12-8
clc;
close all;
clear;
Patm = 18750;
Tatm = 216.7;
U = 250;
R = 287;
gamma_air = 1.4;
T04 = 1500;
Qr = 45000000;
B = 6;
eta_d=0.97;
eta_c=0.85;
eta_b=1;
eta_t=0.9;
eta_n=0.98;
eta_f=0.85;
eta_fn=0.97;
gamma_d=1.4;
gamma_c=1.37;
gamma_b=1.35;
gamma_t=1.33;
gamma_n=1.36;
gamma_f=1.4;
gamma_fn=1.4;
cp_c=(gamma_c/(gamma_c-1))*R;
cp_b=(gamma_b/(gamma_b-1))*R;
cp_n=(gamma_n/(gamma_n-1))*R;
cp_f=(gamma_f/(gamma_f-1))*R;
Mach=U/sqrt(gamma_air*R*Tatm);
T02=(Tatm*(1+((gamma_d-1)/2)*Mach^2));
P02=(Patm*(1+eta_d*((T02/Tatm)-1))^(gamma_d/(gamma_d-1)));
Prc= linspace(5,40,10000);%need to match number of Prf (used 10,000)
P03=P02*Prc;
T03=(T02*(1+(1/eta_c)*(Prc.^((gamma_c-1)/gamma_c)-1)));
Prf = linspace(1,5,10000);%need to match number of Prc (used 10,000)
P08 = P02*Prf;
T08 = (T02*(1+(1/eta_f)*(Prf.^((gamma_f-1)/gamma_f)-1)));
T05=T04-(T03-T02)-(T08-T02)*B;
P05=P03.*(1-(1/eta_t)*(1-T05/T04)).^(gamma_t/(gamma_t-1));
P06=P05;
f=(T04-T03)/(Qr/cp_c-T04);
Ue=sqrt(2*eta_n*(gamma_n/(gamma_n-1))*R*T05.*(1-(Patm./P05).^((gamma_n-1)/gamma_n)));
Uef=sqrt(2*eta_fn*(gamma_f/(gamma_f-1))*R*T08.*(1-(Patm./P08).^((gamma_f-1)/gamma_f)));
SpecificThrust=(1+f).*(Ue+B).*(Uef-(1+B))*U;
TSFC=f./SpecificThrust;
figure(1)
hold on
plot(Prc,SpecificThrust,'-','LineWidth',2);
ylabel('Specific Thrsut (kN*s/kg)')
xlabel('Compressor Pressure Ratio')
grid on
title('Compression Ratio vs Specific Thrust')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!