clear all;
close all;
for PressureRatio = 10:1:60
% Initialise ideal gas properties
gas = IdealGasMix('air.xml');
mw = molecularWeights(gas);
% Defining the inlet conditions
T1 = 290 % temperature in K
P1 = 101325 % Pressure in Pa
MassFlowRate = 100 % mass flow rate in kg/s
% Calculating all properties at inlet (station 1)
set(gas,'T',T1,'P',P1)
s1 = entropy_mass(gas) % inlet entropy
h1 = enthalpy_mass(gas) % inlet enthalpy
% Calculating properties at compressor outlet without isentropic efficiency (station 2s)
P2s = PressureRatio*P1 % in Pa
s2s = s1 % comp. outlet entropy
set(gas,'Entropy',s2s,'P',P2s)
T2s = temperature(gas)
h2s = enthalpy_mass(gas)
W_comp_s = -MassFlowRate*(h2s-h1) % calculating the work transfer rate from station 1 to station 2s in watts
% Calculating properties at compressor outlet with isentropic efficiency (station 2)
W_comp = W_comp_s/0.86 % in watts
h2 = -W_comp/(MassFlowRate)+h1
P2 = P1*PressureRatio
set(gas,'Enthalpy',h2,'P',P2)
T2 = temperature(gas)
s2 = entropy_mass(gas)
% Calculating properties at station 2a
fdil = 0.3 % defining the dillution air fraction
MFR2a = MassFlowRate*(1-fdil) % calculating the mass flow rate at 2a
h2a = -W_comp/(MFR2a)+h1
P2a = P2
set(gas,'Enthalpy',h2a,'P',P2a)
T2a = temperature(gas)
s2a = entropy_mass(gas)
% calculating properties at station 2b
MFR2b = MassFlowRate*(fdil) % calculating the mass flow rate at 2b
h2b = -W_comp/(MFR2b)+h1
P2b = P2
set(gas,'Enthalpy',h2b,'P',P2b)
T2b = temperature(gas)
s2b = entropy_mass(gas)
% Calculating all properties after the combustion (Station 3)
MFR3 = MFR2a
Q_comb = (1.46*10^6)*MFR3 % calculating the heat tranfer rate of the combustion
h3 = Q_comb/MFR2a+h2a
P3 = P2a
set(gas,'Enthalpy',h3,'P',P3)
T3 = temperature(gas)
s3 = entropy_mass(gas)
% calculating properties after the dilution zone (station 4)
MFR4 = MFR3+MFR2b % calculation of the two flow rates combining before the inlet of the dilution zone
h4 = (MFR3*h3+MFR2b*h2b)/MFR4 % calculating enthalpy after dilution zone using energy conservation
P4 = P3
set(gas,'Enthalpy',h4,'P',P4)
T4 = temperature(gas)
s4 = entropy_mass(gas)
% calculating properties after the turbine without isentropic efficiency (station 5s)
MFR5 = MFR4
P5s = P1
s5s = s4
set(gas,'Entropy',s5s,'P',P5s)
T5s = temperature(gas)
h5s = enthalpy_mass(gas)
W_turbine_s = -MFR5*(h5s-h4)
% calculating properties after the turbine with isentropic efficiency (station 5)
W_turbine = W_turbine_s*0.86
h5 = -W_turbine/MFR5+h4
P5 = P1
set(gas,'Enthalpy',h5,'P',P5)
T5 = temperature(gas)
s5 = entropy_mass(gas)
% calculating the efficiency of the open cycle gas turbine
efficiency = (W_turbine+W_comp)/Q_comb
end
Unrecognized function or variable 'IdealGasMix'.
plot(efficiency,PressureRatio,'-*');

4 commentaires

Torsten
Torsten le 10 Fév 2023
Modifié(e) : Torsten le 10 Fév 2023
You can easily find out why no plot is produced if you output the arrays "efficiency" and "PressureRatio" before the plot command.
My guess is that PressureRatio is a single scalar, namely 60, and efficiency is also a single scalar, namely efficiency(PressureRatio=60).
Do you see the mistake you made in your code ?
Walter Roberson
Walter Roberson le 10 Fév 2023
It looks to me as if a number of the statements at the beginning of the loop could be moved to before the loop. That will not affect the plot but will affect performance.
For plotting you need to record all of the efficiency values as you loop through. Unless, that is, you prefer to use animatedline()
MATTHEW WILLIAMS
MATTHEW WILLIAMS le 10 Fév 2023
how would you suggest I store the values for efficiency?
% Initialise ideal gas properties
gas = IdealGasMix('air.xml');
mw = molecularWeights(gas);
% Defining the inlet conditions
T1 = 290 % temperature in K
P1 = 101325 % Pressure in Pa
MassFlowRate = 100 % mass flow rate in kg/s
% Calculating all properties at inlet (station 1)
set(gas,'T',T1,'P',P1)
s1 = entropy_mass(gas) % inlet entropy
h1 = enthalpy_mass(gas) % inlet enthalpy
None of those lines depend upon the loop control variable. They can all be moved to before the loop.

Connectez-vous pour commenter.

 Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 10 Fév 2023
Modifié(e) : Sulaymon Eshkabilov le 10 Fév 2023
Your code produces only scalar value for the variables ash shown in your screenshot from the workspace to be plotted: efficiency = 0.8252 and PressureRatio=60
efficiency = 0.8252;
PressureRatio=60;
plot(efficiency, PressureRatio, '-*')
Here is the corrected code:
% This edited code should create the data series:
clearvars;
close all;
PressureRatio = 10:60;
efficiency = zeros(size(PressureRatio));
for ii = 1:numel(PressureRatio)
% Initialise ideal gas properties
gas = IdealGasMix('air.xml');
mw = molecularWeights(gas);
% Defining the inlet conditions
T1 = 290; % temperature in K
P1 = 101325; % Pressure in Pa
MassFlowRate = 100; % mass flow rate in kg/s
% Calculating all properties at inlet (station 1)
set(gas,'T',T1,'P',P1)
s1 = entropy_mass(gas); % inlet entropy
h1 = enthalpy_mass(gas); % inlet enthalpy
% Calculating properties at compressor outlet without isentropic efficiency (station 2s)
P2s = PressureRatio(ii)*P1; % in Pa
s2s = s1; % comp. outlet entropy
set(gas,'Entropy',s2s,'P',P2s)
T2s = temperature(gas);
h2s = enthalpy_mass(gas);
W_comp_s = -MassFlowRate*(h2s-h1); % calculating the work transfer rate from station 1 to station 2s in watts
% Calculating properties at compressor outlet with isentropic efficiency (station 2)
W_comp = W_comp_s/0.86; % in watts
h2 = -W_comp/(MassFlowRate)+h1;
P2 = P1*PressureRatio(ii);
set(gas,'Enthalpy',h2,'P',P2)
T2 = temperature(gas);
s2 = entropy_mass(gas);
% Calculating properties at station 2a
fdil = 0.3; % defining the dillution air fraction
MFR2a = MassFlowRate*(1-fdil); % calculating the mass flow rate at 2a
h2a = -W_comp/(MFR2a)+h1;
P2a = P2;
set(gas,'Enthalpy',h2a,'P',P2a(ii));
T2a = temperature(gas);
s2a = entropy_mass(gas);
% calculating properties at station 2b
MFR2b = MassFlowRate*(fdil); % calculating the mass flow rate at 2b
h2b = -W_comp/(MFR2b)+h1;
P2b = P2;
set(gas,'Enthalpy',h2b,'P',P2b);
T2b = temperature(gas);
s2b = entropy_mass(gas);
% Calculating all properties after the combustion (Station 3)
MFR3 = MFR2a;
Q_comb = (1.46*10^6)*MFR3; % calculating the heat tranfer rate of the combustion
h3 = Q_comb/MFR2a+h2a;
P3 = P2a;
set(gas,'Enthalpy',h3,'P',P3)
T3 = temperature(gas);
s3 = entropy_mass(gas);
% calculating properties after the dilution zone (station 4)
MFR4 = MFR3+MFR2b; % calculation of the two flow rates combining before the inlet of the dilution zone
h4 = (MFR3*h3+MFR2b*h2b)/MFR4; % calculating enthalpy after dilution zone using energy conservation
P4 = P3;
set(gas,'Enthalpy',h4,'P',P4);
T4 = temperature(gas);
s4 = entropy_mass(gas);
% calculating properties after the turbine without isentropic efficiency (station 5s)
MFR5 = MFR4;
P5s = P1;
s5s = s4;
set(gas,'Entropy',s5s,'P',P5s);
T5s = temperature(gas);
h5s = enthalpy_mass(gas);
W_turbine_s = -MFR5*(h5s-h4);
% calculating properties after the turbine with isentropic efficiency (station 5)
W_turbine = W_turbine_s*0.86;
h5 = -W_turbine/MFR5+h4;
P5 = P1;
set(gas,'Enthalpy',h5,'P',P5);
T5 = temperature(gas);
s5 = entropy_mass(gas);
% calculating the efficiency of the open cycle gas turbine
efficiency(ii) = (W_turbine+W_comp)/Q_comb;
end
plot(efficiency,PressureRatio,'-*');

2 commentaires

MATTHEW WILLIAMS
MATTHEW WILLIAMS le 12 Fév 2023
Thank you very much this answers my question very well
Sulaymon Eshkabilov
Sulaymon Eshkabilov le 12 Fév 2023
Most welcome! Glad to help.

Connectez-vous pour commenter.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 10 Fév 2023

0 votes

The error tells that gas = IdealGasMix('air.xml') is not importing the data. IdealGasMix() is a function to read a data from *.xml file? If so, make sure it is running and importing the data and assigning to the variuable "gas".
As of now your code has stopped at the beginning after a "for" loop initiation.
If you share your data or a function file IdealGasMix, we can provide a more constructive idea how to make your code run seamlessly.

1 commentaire

MATTHEW WILLIAMS
MATTHEW WILLIAMS le 10 Fév 2023
I am getting values that vary for effiiciency in the command window, it's just that when i plot nothing shows up on the graph

Connectez-vous pour commenter.

Catégories

En savoir plus sur Oil, Gas & Petrochemical dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by