Plotting graphs with changing values for variables
60 次查看(过去 30 天)
显示 更早的评论
So I'm trying to plot 4 different graphs. Each graph will have 2 plots. However, is there a way for me to change the value of the variable down the line? For example, for #4 graph, I only want to change Ma to linspace and not use the original Ma=0.92 value that was inputted in the very beginning of my code. I've attached my code below. Not sure what I'm doing wrong but I'm sure I may be missing some commands. Thank you for the help.
%% Problem 2.10
alt=0;
Ma=0.92;
deltaH=18100;
Pa=14.69;
mdot=100;
T_t4=2450;
T_a=518.7;
gamma=1.4;
g=gamma-1;
R=53.35;
Cp=0.2399565;
rho_8=1.308126E-03;
pi_c=2.223813
%Diffuser
aa=sqrt(gamma*R*32.17*T_a);
ua=Ma*aa;
T_ta=(1+0.5*(gamma-1)*Ma^2)*T_a;
P_ta=Pa*(T_ta./T_a).^(gamma/g);
T_t2=T_ta;
P_t2=P_ta;
pi_c=linspace(5,20);
%Compressor
P_t3=pi_c.*P_t2;
tau_c=pi_c.^((gamma-1)./gamma);
T_t3=tau_c.*T_t2;
%Primary Combustor
P_t4=P_t3;
m_dotf=(mdot.*Cp.*(T_t4-T_t3))./deltaH;
%Turbine
T_t5=([(m_dotf.*Cp.*(T_t3-T_t2))./(mdot.*Cp)]-T_t4).*-1;
tau_t=T_t5./T_t4;
tau_t=T_t5./T_t4;
pi_t=0.2827511;
P_t5=pi_t.*P_t4;
%Primary Nozzle
T_t6=T_t5;
P_t6=P_t5;
P_8= 14.69; %exit pressure matches ambient pressure
T_8=T_t6.*((P_8./P_t6).^((gamma-1)/gamma));
u_8=[2*Cp.*(T_t6-T_8)*32.17*778.16].^0.5;
a_8=(gamma*R*T_8.*32.17).^0.5;
M_8=u_8./a_8;
A_8=m_dotf.*144./(rho_8.*u_8*32.17);
%Total Thrust and TSFC
F=mdot.*u_8-mdot.*ua;
nDF=(F.*32.17)./(mdot.*aa);
TSFC=mdot.*3600./F;
TSFCaa=TSFC.*aa;
%%% Graphs
%% 1.
pi_c=linspace(5,20)
f1=figure(1);clf;
plot (pi_c,TSFCaa,'k')
title('Figure 1. TSFC_a vs. \pi_c');
xlabel('\pi_c')
ylabel('TSFC_a_a')
f2=figure(2);clf;
plot(pi_c,nDF,'k')
title ('Figure 2. nDF_a vs. \pi_c');
xlabel('\pi_c')
ylabel('F/m_a_a')
%% 2.
T_a=linspace(0.5,1.2);
f3=figure(3);clf;
plot(T_a,TSFCaa,'k')
title ('Figure 3. TSFC_a_a vs. T_a/T_s_t_p');
xlabel('T_a/T_s_t_p')
ylabel('TSFC_a')
f4=figure(4);clf;
plot(Ta_Tstp,nDF,'k')
title ('Figure 4. nDF_a vs. T_a/T_s_t_p');
xlabel('T_a/T_s_t_p')
ylabel('F/m_a_a')
%% 3.
T_t4=linspace(4,8);
f5=figure(5);clf;
plot(T_t4,TSFCaa,'k')
title('Figure 5. TSFC_a_a vs (T_t_4/T_a)')
xlabel('T_t_4/T_a')
ylabel('TSFC_a_a')
f6=figure(6);clf;
plot(T_t4,nDF,'k')
title('Figure 5. nDF vs (T_t_4/T_a)')
xlabel('T_t_4/T_a')
ylabel('F/m_a_a')
%% 4
Ma=linspace(0,5);
f7=figure(7);clf;
plot(Ma, TSFCaa,'k')
title('Figure 6. TSFC_a_a vs Ma')
xlabel('Ma')
ylabel('TSFC_a_a')
f8=figure(8);clf;
plot(Ma,nDF,'k')
title('Figure 6. nDF vs Ma')
xlabel('Ma')
ylabel('F/m_a_a')
1 个评论
Ankit
2022-3-1
You can include your calculation in a function and then pass Ma as constant and vector values
回答(1 个)
Pavan Sahith
2023-10-16
Hi Marie,
I understand you are trying to plot multiple graphs and want to change the value of the variables down the line.
For that you can use function which plots the graph according to the variables being passed
For example :
% sample data
Ma=0.92;
TSFCaa=linspace(5,20);
% changing Ma
Ma = linspace(0, 5);
% calling the function plotFn
plotFn(Ma, TSFCaa,'TSFC_a vs. Ma','Ma','TSFC_a_a')
function plotFn(X,Y,title1,xlabel1,ylabel1)
plot (X,Y,'k')
title(title1);
xlabel(xlabel1);
ylabel(ylabel1);
end
If you want to plot 2 graphs in same figure you can use ‘subplot’ or ‘tiledlayout’
Please refer to the following MathWorks documentation links to know more about them.
Hope it helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!