plotting values that comes from a if else loop
2 ビュー (過去 30 日間)
古いコメントを表示
I'm having issues with plotting in my if else statements, the PRF it's supposed to cycles through numbers and in the end plot B vs Prf. why is it not plotting Prf ?
clc
clear all
close all
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
BArray = 5:1:10; %bypass ratio
for idx = 1:numel(BArray)
B = BArray(idx);
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
% PrcArray = 7:1:27;% compressor ratio
% for idx = 1:numel(PrcArray)
Prc = 24;
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
PrfArray = 1:00001:2; %prf % what i'm trying to plot
for a = 1:numel(PrfArray)
%Prf= PrfArray(a);
%for Prf=1:00001: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;
Prf= PrfArray(a);
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(idx) = (1+f)*Ue+B*Uef-(1+B)*U;
specific_Thrust=max(specthrust);
%fprintf('your specific thrust is %f', specthrust)
%format bank
%disp(num2str(specthrust,'%.0f'))
TSFC=f./specthrust;
%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;
end
end
%figure
hold on
u=5:1:10; %bypass
scatter(u,specthrust, 'd','r','filled')
ylabel('Specific Thrsut (kN*s/kg)')
xlabel('ByPass ratio')
%axis([4 12 1400 1800])
grid on
title('ByPass ratio vs Specific Thrust')
figure(2)
scatter(u,TSFC,'d','filled')
ylabel('TSFC')
xlabel('ByPass ratio')
%axis([5 30 200000 230000])
grid on
title('ByPass ratio vs TSFC')
figure(3)
scatter(u,eoa, 'd','g','filled')
ylabel('overall efficiency of the engine')
xlabel('ByPass ratio')
axis([4 12 .21 .26])
grid on
title('ByPass ratio vs overall efficiency of the engine')
figure(4)
scatter(u,Prf, 'd','g','filled')
ylabel('Fan Pressure Ratio')
xlabel('ByPass ratio')
%axis([4 12 .21 .26])
grid on
title('ByPass ratio vs Fan Pressure Ratio')
0 件のコメント
回答 (1 件)
Star Strider
2021 年 11 月 10 日
I am not certain what you are doing, so I cannot suggest specific changes.
The ‘Prf’ value plots, however it is a scalar so the result is a horizontal line of green diamonds at 2. (The ‘PrfArray’ vector contains only 2 values anyway.)
The ‘eoa’ plot is blank, however that is because of the axis call. That neds to be changed or removed.
Consider vectorising the code to make it more efficient and easier to read and troubleshoot. See the documentation section on Vectorization for more information.
.
2 件のコメント
Star Strider
2021 年 11 月 10 日
No worries!
Unless the code changed from previously (before it was closed), those variables as are I described them.
The for loop only executes when P05 ~= P08 although I did not look closely at all the results, only the variables mentioned in the question.
It always helps to see what the variables are before plotting them (I did just that when I ran the code earlier.)
See the Debugging and Analysis documentation section for help in understanding what the code is actually doing.
I strongly recommend vectorising the code, since that will significantly reduce its complexity and make it easier to read and troubleshoot.
.
参考
カテゴリ
Help Center および File Exchange で Pulsed Waveforms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!