plotting a for loop returns Empty Graph

조회 수: 3 (최근 30일)
Niall
Niall 2021년 10월 16일
편집: Niall 2021년 10월 16일
I cannot seem to get the output graph to work. I need to show at what pressure ratios (Rp and Pr) the thermal efficiency is at its heighest (Nth_IC).
%% Variables
Rp = 50; %% pressure ratio
Pr = 50; %% P2/P1
%% for loop
for i = 0:0.5:Rp
for j = 0:0.5:Pr
%% Low Pressure Compressor
T2 = T1*Pr^(0.4/1.4);
W2s = 1005*(T1-T2); %% specific work from 1 to 2s
W2 = W2s * Nc;
%% Intercooler
T3 = T1; %% assume ideal intercooler
q3 = 1005*(T3 - T2);
%% High Pressure Compressor
T4 = T3*(Rp/Pr)^(0.4/1.4);
W4s = 1005*(T3 - T4);
W4 = W4s * Nc;
%% Combustion Chamber
q5 = 1005*(T5 - T4);
%% Turbine
T6 = T5*(1/Rp)^(0.4/1.4);
W6s = 1005*(T5 - T6);
W6 = W6s * Nt;
%% Calculations for Intercooled
NWO_IC = W6 + W2; %% Net Work Output for Intercooled
Nth_IC = NWO_IC/q5; %% Thermal Efficiency for Intercooled
Wout_IC = m*(W4 + W2 + W6); %% Output Power for Intercooled
figure(1); plot(j,Nth_IC);
end
figure(2); plot(i,Nth_IC);
end

답변 (2개)

John D'Errico
John D'Errico 2021년 10월 16일
편집: John D'Errico 2021년 10월 16일
You are not plotting ANYTHING in a for loop. You may think you are. Where are the plot statements? AFTER THE LOOP TERMINATES. After the end statement for the loop.
So we have two plots made:
figure(1); plot(i,Nth_IC);
figure(2); plot(j,Nth_IC);
What are i, j, and Nth_IC, after the loop terminates?
>> i
i =
50
>> Nth_IC
Nth_IC =
0.293033227395743
>> j
j =
50
What does plot do when you tell it to plot, but with no third argument?
It connects the points with a simple line. Not even a symbol.
How many points are in that plot? ONE point. So what did plot do? It connected that single point with a line. Only one point, so all you see is a blank figure.
Note that all of ths could have been seen by you, had you simply looked at what are the arguments to those plot calls, and what values do they take on.
What should you have done? It is often a good idea to simply collect all of those values in the loop in a vector, and then plot them all after the loop has terminated in one call to plot. If you want to connect them with a line, then you cannot do that when you plot only one point at a time, even if you do have the plots inside your loop.

Star Strider
Star Strider 2021년 10월 16일
I’m not certain what you want, however it is necessary to subscript the varialbes to be plotted.
This runs without error and produces some plots, however they may not be the desired results.
%% INTERCOOLED BRAYTON CYCLE
%% Variables
Rp = 50; %% pressure ratio
m = 1; %% mass flow rate
Pr = 50; %% P2/P1
T5 = 1496; %% max value for T5
%% Given Conditions
T1 = 300;
P1 = 97E+3;
Nc = 0.9; %% compressor efficiency
Nt = 0.9; %% turbine efficiency
Power = 36e+9; %% power Generation
Ne = 0.96; %% electric generator efficiency
Net_Power = Power*Ne;
%% for loop
iv = 0:0.5:Rp;
jv = 0:0.5:Pr;
for i = 1:numel(iv)
for j = 1:numel(jv)
Rp - iv(i);
Pr = jv(j);
%% Low Pressure Compressor
T2 = T1*Pr^(0.4/1.4);
W2s = 1005*(T1-T2); %% specific work from 1 to 2s
W2 = W2s * Nc;
%% Intercooler
T3 = T1; %% assume ideal intercooler
q3 = 1005*(T3 - T2);
%% High Pressure Compressor
T4 = T3*(Rp/Pr)^(0.4/1.4);
W4s = 1005*(T3 - T4);
W4 = W4s * Nc;
%% Combustion Chamber
q5 = 1005*(T5 - T4);
%% Turbine
T6 = T5*(1/Rp)^(0.4/1.4);
W6s = 1005*(T5 - T6);
W6 = W6s * Nt;
%% Calculations for Intercooled
NWO_IC = W6 + W2; %% Net Work Output for Intercooled
Nth_IC(i,j) = NWO_IC/q5; %% Thermal Efficiency for Intercooled
Wout_IC = m*(W4 + W2 + W6); %% Output Power for Intercooled
end
end
figure(1); plot(iv,Nth_IC);
figure(2); plot(jv,Nth_IC.');
figure(3)
surf(iv,jv,Nth_IC, 'EdgeColor','none')
view(30,30)
xlabel('Rp')
ylabel('Pr')
zlabel('Nth_{IC}')
Experimment to get the desired result.
.

카테고리

Help CenterFile Exchange에서 Oil, Gas & Petrochemical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by