Multiple line with different variable in a plot

Hello people, I am current working on a homework. I am supposed to have a plot that contain multiple data line with varying B and pi_o. I tried to put it into a loop but it does not seem to work, Any help will be appreciated.
Pa = 23771;
Ta = 218.789;
R = 287;
gamma = 1.4;
Mf = 0.85;
fan_isen = 0.91;
nozzle_isen = 0.985;
ec = 0.915;
press_drop_CC = 0.04;
cpg = 1148;
cp = 1005;
Qr = 43800*(10^3);
cc_burner_eff = 0.99;
mecha_eff = 0.985;
et_HP = 0.93;
gammag = 1.333;
et_LP = 0.92;
%custom
pi_fb = 1.5; %<2.1
pi_fc = 1.5; %<2.1
% pi_o = 42; %<52
T04 = 1600; %Tet<2050K
% B = 8; %<11
B = 0:0.5:10;
pi_o = 2:2:30;
for k = 1:length(pi_hp)
vf = Mf * ((gamma*Ta*R)^(1/2));
T02 = Ta * (1+((gamma-1)/2)*0.85^2);
P02 = Pa * (1+((gamma-1)/2)*0.85^2)^(gamma/(gamma-1));
%Bypass
P013 = pi_fb * P02;
T013 = T02*(1+((1/fan_isen)*((P013/P02)^(((gamma-1)/gamma)))-1));
P019 = P013;
T019 = T013;
critical_pressure_ratio = 1/(1-((1/nozzle_isen)*((gamma-1)/(gamma+1))))^(gamma/(gamma-1));
P19 = P019/critical_pressure_ratio;
T19 = T019/(1/((1-((1/nozzle_isen)*((gamma-1)/(gamma+1))))));
V19 = (gamma*R*T19)^(1/2)
%Core
P023 = pi_fc * P02;
tau_c = pi_fc^((gamma-1)/(gamma*ec));
T023 = tau_c*T02;
pi_hp = pi_o/pi_fc;
P03 = pi_hp*P023;
comp_isen = (((pi_fc^((gamma-1)/(gamma))))-1)/((pi_fc^((gamma-1)/(gamma*ec)))-1);
T03s = T023*(P03/P023).^((gamma-1)/gamma);%added dot
T03 = T023 + ((T03s-T023)/comp_isen);
P04 = (1-press_drop_CC)*P03;
f = ((cpg*T04)-(cp*T03))/(Qr - (cpg*T04));
fa = f/cc_burner_eff;
T045 = T04 - (cp*(T03-T023))/(mecha_eff*(1+fa)*cpg);
tau_t_HP = T045/T04;
HP_turb_isen = (1-tau_t_HP)/(1-(tau_t_HP^(1/et_HP)));
P045 = P04*(1-((1-(T045/T04))/(HP_turb_isen)))^(gammag/(gammag-1));
T05 = T045 - ((cp.*(T023-T02))+(B.*cp.*(T013-T02))).*(((mecha_eff.*(1+fa).*cpg))).^-1;
tau_t_LP = T05/T045;
LP_turb_isen = (1-tau_t_LP)/(1-(tau_t_LP.^(1/et_LP)));
P05 = P045.*(1-((1-tau_t_LP)/(LP_turb_isen))).^(gammag/(gammag-1));
P9 = Pa;
T9s = T05.*(((P9.*P05.^-1).^(gammag-1).*(gammag)).^-1);
T9 = nozzle_isen*(T9s-T05)+T05;
V9 = (2*cpg*(T05-T9)).^(1/2);
Ratio_of_exit_velocities = V19*(V9.^-1);
Fs = ((1.*(B+1).^-1).*((1+fa).*V9-vf))+((((1+fa).*R.*T9).*((V9.*P9.*(B+1))).^-1).*(P9-Pa))+((B./(B+1)).*(V19-vf))+(((R.*T19.*B)/(V19.*P19.*(B+1))).*(P19-Pa));
sfc = fa/((B+1).*Fs)
h = plot(pi_o, Fs);
end

 Accepted Answer

Here is an example. Loop for each B but use pi_o as a vector in your calculations.
clear;
pi_o = 2:2:30;
B=[3 5 8];
figure;
hold on;
% make lines for each B
for iiB=B
V9=sqrt(pi_o); % use pi_o as a vector
%...
Fs=V9*iiB;
plot(pi_o,Fs,'displayname',['B=' num2str(iiB)])
end
hold off;
legend('show');
An alternative would be 2 loops, populate a matrix in a loop, and plot each row (or column) after.

4 Comments

Thank you very much, exactly what I was looking for
Just one more question, what should I do if i want to make the change the desgin of the line like add in circle, square so that each line will be less similar. And also, how can I plot multiple graph like, have a nother plot of maybe Ft vs pi_o? I would be very grateful if you could help me on this.
@Yixiang Guice you can make a list of the "styles" that correspond to the diffrent B's
Note the for loop initialization changed compared to the first example because now you need an index (in this case ii=1,2,3) rather than the B value directly
clear;
close all;
pi_o = 2:2:30;
B_vec=[3 5 8];
Bstyles = {'-ro','-b^','-kx'};
% make lines for each B
for ii=1:numel(B_vec)
Bii=B_vec(ii);
% calculations
V9=pi_o.^0.5; % use pi_o as a vector
%...
Fs=V9*Bii;
Ft=V9*Bii;
% update plots
figure(1);
plot(pi_o,Fs,Bstyles{ii},'displayname',['B=' num2str(Bii)])
hold on;
figure(2);
plot(pi_o,Ft,Bstyles{ii},'displayname',['B=' num2str(Bii)])
hold on;
end
% make plots pretty
figure(1);
hold off;
xlabel('B');
ylabel('Fs')
grid on; box on;
legend('show');
figure(2);
hold off;
xlabel('B');
ylabel('Fs2')
grid on; box on;
legend('show');
If you want change more properties you can try something like this, but now plots might looks ugly.
clear;
close all;
pi_o = 2:2:30;
B_vec=[3 5 8];
Bstyles = {...
{'-mo','linewidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',8};...
{'--r^','MarkerFaceColor','none','MarkerSize',9}; ...
{':kd','MarkerSize',13}...
};
% make lines for each B
for ii=1:numel(B_vec)
Bii=B_vec(ii);
% calculations
V9=pi_o.^0.5; % use pi_o as a vector
%...
Fs=V9*Bii;
% update plots
figure(1);
plot(pi_o,Fs,Bstyles{ii}{:},'displayname',['B=' num2str(Bii)])
hold on;
end
% make plots pretty
figure(1);
hold off;
xlabel('B');
ylabel('Fs')
grid on; box on;
legend('show');

Sign in to comment.

More Answers (0)

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!