Store values from a for loop in matrix and plot them.

18 ビュー (過去 30 日間)
Jerin Thomas
Jerin Thomas 2021 年 11 月 8 日
編集済み: Chris 2021 年 11 月 8 日
I'm sure there's a better way to do this but i'm not sure how to go about it. I'm trying to store the values from my for loops into matrix, and trying to plot it after. So far it just gives me all the values in a 1*1 matrix and try to plot just one value ( which doesn't even shows up on the graph). I don't see any errors that pops up .
R=287;
Qr=43400000; %heat reaction value
Pa=187500; % atmospher
Ta=216.7; % outside temprature
M=.73; % mach number
gd=1.4; %gama
% variables
B=5; %bypass ratio
To4=1875; %turbine inlet temperature
%Prf= not given; %Fan pressure ratio
%Efficiencies and gamma for specific heat
d=.97; gamad=1.4; %diffuser
c=.85; gamac=1.37; %compressor
b=1; gamab=1.35; %burner
t=.9; gamat=1.33; %turben
nz=.98; gamanz=1.36; %nozzle
fan=.85; fangamenz=1.4; %fan
fan_nozzle=.97; %fan nozzle
%flight velocity equation
U=M*sqrt(gd*R*Ta);
%compressor inlet temperature calculation
T0a=Ta*(1+(gamad-1)/2*M^2);
T02=T0a;
%compressor inlet pressure calculation
P02=Pa*(1+d*(T02/Ta-1))^(gd/(gd-1));
%compressor outlet pressure calculation
for Prc=7:1:27 ; %compressor ratio
P03=P02*Prc;
P04=P03;
%compressor outlet temperature calculation
T03=T02*(1+1/c*(Prc^((gamac-1)/gamac)-1));
%Cp calculations
Cpb=(gamab/(gamab-1))*R;
Cpc=(gamac/(gamac-1))*R;
Cpt=(gamat/(gamat-1))*R;
%fuel to air flow rate ratio
f=(To4-T03)/(Qr/Cpb-To4);
%fan pressure ratio
Prf=1; % i start with one so i can put in a loop after
%fan pressure and temperature calculation
P08=P02*Prf;
T08=T02*(1+1/fan*(Prf^((fangamenz-1)/fangamenz)-1));
%turbine outlet condition calculations
T05=To4-(T03-T02)-B*(T08-T0a);
P05=P04*(1-1/t*(1-T05/To4))^(gamat/(gamat-1));
%nozzle inlet conditions
P06=P05;
T06=T05;
P05==P08;
if P05==P08;
continue
else
for Prf=1:001:2;
P08=P02*Prf;
T08=T02*(1+1/fan*(Prf^((fangamenz-1)/fangamenz)-1));
%turbine outlet condition calculations
T05=To4-(T03-T02)-B*(T08-T0a);
P05=P04*(1-1/t*(1-T05/To4))^(gamat/(gamat-1));
%nozzle inlet conditions
P06=P05;
T06=T05;
end
%exit flight velocities calculations
Ue=sqrt(2*nz*gamanz/(gamanz-1)*R*T06*(1-(Pa/P06)^((gamanz-1)/gamanz)));
Uef=sqrt(2*fan_nozzle*fangamenz/(fangamenz-1)*R*T08*(1-(Pa/P08)^((fangamenz-1)/fangamenz)));
%specific thrust and TSFC calculations
specthrust=(1+f)*Ue+B*Uef-(1+B)*U;
%fprintf('your specific thrust is %f', specthrust)
format bank
%disp(num2str(specthrust,'%.0f'))
TSFC=f/specthrust;
format bank
%disp(num2str(TSFC,'%.0f'));
%overall efficiency calculations
A=((1+f)*Ue^2/2+B*Uef^2/2-(1+B)*U^2/2);
ep=specthrust*U/A;
eth=A/(Qr*f);
eoa=ep*eth;
format bank
%disp(num2str(eoa,'%.0f'));
fprintf(' for Prc: %d\n', Prc)
fprintf('your specific thrust is %f', specthrust)
figure(1)
plot(Prc,specthrust)
end
end

採用された回答

Chris
Chris 2021 年 11 月 8 日
You need an index to keep track of your loop iterations. You can do this one of two ways:
idx = 0
for Prc = Prc=7:1:27
idx = idx+1;
...
specthrust(idx) = (1+f)*Ue+B*Uef-(1+B)*U;
end
or
PrcArray = 7:1:27;
for idx = 1:numel(PrcArray)
Prc = PrcArray(idx);
...
specthrust(idx) = (1+f)*Ue+B*Uef-(1+B)*U;
end
Then you should be able to plot everything at once.
The reason the plot doesn't show up as it is is that plot() needs at least two x points and two y points to draw a line.
scatter() would be a better tool for plotting single points.
  3 件のコメント
Chris
Chris 2021 年 11 月 8 日
編集済み: Chris 2021 年 11 月 8 日
You would need to turn hold on, to prevent the plot from being overwritten.
figure(1)
hold on
for Prc = 7:27
specthrust = sqrt(Prc);
figure(1)
scatter(Prc,specthrust,'b*');
end
To plot outside the loop, all you would need is the two vectors.
Prc = 7:27;
specthrust = sqrt(Prc);
figure
plot(Prc,specthrust,'*')
Jerin Thomas
Jerin Thomas 2021 年 11 月 8 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by