Challenge

Project 2 - Rankine cycle Simulator

close all
clear all
clc

%% PART 1.1: RANKINE CYCLE INTRODUCTION TO USER:

% display
disp('Rankine Cycle Simulator')
disp('Process 1-2: Isentropic Expansion of Steam in the TURBINE')
disp('process 2-3: Constant Pressure Heat Rejection in CONDENSOR')
disp('Process 3-4: Isentropic Compression of Water in PUMP')
disp('Process 4-1: Constant Pressure Heat Addition in the BOILER')

%% PART 1.2: PRESSURE AND TEMPERATURE AT THE ENTRY TO TURBINE AND ENTRY PRESSURE OF CONDENSOR:

% Asking the User to enter pressure and temperature data for turbine and
% condensor.
% T1 = Turbine Entry Temperature (in Deg. Celcius).
% P1 =  Turbine Entry Pressure (in Bars).
% P2 = Condensor Entry Pressure (in Bars).

T1 = input('Please Enter the Entry Temperature of the steam in the Turbine (in Celcius): ');
P1 = input('Please Enter the Entry Pressure of the steam in the Turbine(in bar): ');
P2 = input('Please Enter the Exit Pressure of the steam in the Turbine(in bar): ');

% Checking for valid Entry Pressure(P1) or Temperature(T1).
 if T1 <= 0 || P1 <= 0
     disp('Invalid Turbine Entry Condition')
 else
%% PART 1.3: DEFINING THE STATE VARIABLE VALUES FOR DIFFERENT STATES DURING THE CYCLE:

% state point 1:
s1 = XSteam('s_pT',P1,T1);   % Entropy of Steam at Turbine entry (KJ/Kg-K).
h1 = XSteam('h_pT',P1,T1);   % Enthalpy of Steam at Turbine entry (KJ/Kg).
hf1 = XSteam('hL_p',P1);     % Enthalpy of SATURATED WATER (KJ/Kg) for Boiler Pressure (P1).
hg1 = XSteam('hV_p',P1);     % Enthalpy of SATURATED STEAM (KJ/Kg) for Boiler Pressure (P1).
sf1 = XSteam('sL_p',P1);     % Entropy of SATURATED WATER (KJ/Kg-K) for Boiler Pressure (P1).
sg1 = XSteam('sV_p',P1);     % Enthalpy of SATURATED STEAM (KJ/Kg-K) for Boiler Pressure (P1).
Ts1 = XSteam('Tsat_p',P1);   % SATURATION TEMPERATURE (in Deg. Celcius) of STEAM corresponding to Boiler Pressure (P1).

% state point 2:
s2 = s1;                        % Entropy of Steam at Turbine exit (KJ/Kg-K), both are equal since the process is ISENTROPIC in nature.
hf2 = XSteam('hL_p',P2);        % Enthalpy of SATURATED WATER (KJ/Kg) for CONDENSOR Pressure (P2).
hg2 = XSteam('hV_p',P2);        % Enthalpy of SATURATED STEAM (KJ/Kg) for CONDENSOR Pressure (P2).
sf2 = XSteam('sL_p',P2);        % Entropy of SATURATED WATER (KJ/Kg-K) for CONDENSOR Pressure (P2).
sg2 = XSteam('sV_p',P2);        % Entropy of SATURATED STEAM (KJ/Kg-K) for CONDENSOR Pressure (P2).
Ts2 = XSteam('Tsat_p',P2);      % SATURATION TEMPERATURE (in Deg. Celcius) of STEAM corresponding to CONDENSOR Pressure (P2).
T2 = XSteam('T_ps',P2,s2);
x2 = ((s2 - sf2)/(sg2 - sf2));  % DRYNESS FRACTION of STEAM at entry tO CONDENSOR.

CpS = XSteam('CpV_p',P2);

% Checking if the steam at the entry of the CONDENSOR is WET, DRY or
% SUPERHEATED.

if x2 < 1                            % WET STEAM CONDITION.
        
    h2 = hf2 + x2*(hg2 - hf2);   % Enthalpy of Steam at Entry ot CONDENSOR (from properties of pure substances).
        
    elseif x2 == 1                    % DRY SATURATED STEAM CONDITION.
        
        h2 = hg2;                     % Enthalpy of Steam at Entry ot CONDENSOR (from properties of pure substances).
        
    elseif x2 > 1                     % SUPER-HEATED STEAM CONDITION.
        
        h2 = hg2 + CpS*(T2 - Ts2);    % Enthalpy of Steam at Entry ot CONDENSOR (from properties of pure substances).
 end

% state point 3:
P3 = P2;                           % CONSTANT PRESSURE PROCESS. 
s3 = XSteam('sL_p',P3);            % Entropy of WATER(KJ/Kg-K) at EXIT from CONDENSOR and ENTRY to PUMP.     
hf3 = XSteam('hL_p',P3);           % Enthalpy of SATURATED WATER(KJ/Kg) coresponding to CONDENSOR Pressure P2.
hg3 = XSteam('hV_p',P3);           % Enthalpy of DRY SATURATED STEAM (KJ/Kg) coresponding to CONDENSOR Pressure P2.
sf3 = XSteam('sL_p',P3);           % Entropy of SATURATED WATER(KJ/Kg-K) coresponding to CONDENSOR Pressure P2.
sg3 = XSteam('sV_p',P3);           % Entropy of DRY SATURATED STEAM(KJ/Kg-K) coresponding to CONDENSOR Pressure P2.
h3 = hf3;                          % Enthalpy of WATER (KJ/Kg) at the EXIT of CONDENSOR.
T3 = XSteam('T_ps',P3,s3);         % Temperature (deg. Celcius) of WATER ar EXIT from CONDENSOR and ENTRY to PUMP.
CpW = XSteam('cpL_p',P3);          % Specific Heat of WATER at constant Pressure (KJ/Kg). 
CvW = XSteam('cvL_p',P3);          % Specific Heat of WATER at constant Volume (KJ/Kg).

gamma = (CpW/CvW);                 % Adiabatic Constant.
K = ((gamma - 1)/gamma);


% state point 4:

P4 = P1;                     % Pressure of WATER at the EXIT of PUMP or ENTRY to BOILER (in Bars).
s4 = s3;                     % Entropy of WATER at the EXIT of PUMP or ENTRY to BOILER (KJ/Kg-K).
h4 = XSteam('h_ps',P4,s4);   % Enthalpy of WATER at the EXIT of PUMP or ENTRY to BOILER (KJ/Kg).
T4 = T3*((P4/P3)^K);         % Temperature of WATER at the EXIT of PUMP or ENTRY to BOILER (in Deg. Celcius).

W_T = h1 - h2;                     % TURBINE WORK.
W_P = h4 - h3;                     % PUMP WORK.
W_Net = W_T - W_P;                 % NET WORK OUTPUT OF THE CYCLE.
Back_Work_Ratio = (W_P/W_T)*100;   % BACK WORK RATIO = ratio of pump work and turbine work.
Qs = h1 - h4;                      % HEAT SUPPLIED INTO THE CYCLE (BOILER).
Qr = h2 -h3;                       % HEAT REJECTED FROM THE CYCLE (CONDENSOR).
Nth = (W_Net/Qs)*100;              % THERMAL EFFICIENCY OF THE CYCLE.
SSC = 3600/W_Net;                  % Specific Steam Consumtion rate = steam required for 1KW of net work output.

Temp = linspace(1,400,500);        % Temperature Range.

%% PART 2: Plotting T-S and H-S diagram representing all the processes in the Cycle: 

% calculating values of enthalpy and entropy of saturated water and dry
% saturated steam at different temperatures within the temperature range.

for i = 1:length(Temp)
    
    hf(i) = XSteam('hL_T',Temp(i));  % Enthalpy of saturated water.
    hg(i) = XSteam('hV_T',Temp(i));  % Enthalpy of Dry Saturated Steam.
    sf(i) = XSteam('sL_T',Temp(i));  % Entropy of the saturated water.
    sg(i) = XSteam('sV_T',Temp(i));  % entropy of Dry saturated Steam.
end

% Plotting T-S diagram of the RANKINE CYCLE.
figure(1)
hold on
grid on

if s2 > sg2 % Checking if the steam exit condition is SUPER-HEATED or not:
    
    plot([s1 s2], [T1 T2],'color','c','linewidth',2)      % Isentrpic Expansion of steam in turbine.
    
    plot([s2 sg2], [T2 Ts2],'color','r','linewidth',2)    % constant Pressure Process in CONDENSOR in super heated state of steam.
    
    plot([sg2 sf2], [Ts2 Ts2],'color','r','linewidth',2)  % constant Pressure Process in CONDENSOR in wet state of steam.

    plot([sf2 s3], [Ts2 T4],'color','c','linewidth',2)    % Isentropic Compression of water from P2 to P1 in PUMP.
    
    plot([s4 sf1], [T4 Ts1],'color','r','linewidth',2)    % Constant Pressure Heating Process in BOILER IN SUB-COOLED region of WATER.  
    
    plot([sf1 sg1], [Ts1 Ts1],'color','r','linewidth',2)  % Constant Pressure Heating Process in BOILER in WET region of STEAM. 
    
    plot([sg1 s1],[Ts1 T1],'color','r','linewidth',2)     % Constant Pressure Heating Process in BOILER IN SUPER-HEATED region of STEAM.
    
    % Marking Important state points on the T-S Diagram.
    text(s1,T1,'1')       % STATE 1.
    text(s2,T2,'2')       % STATE 2.
    text(sg2,Ts2,'2g')    % STATE 2g.
    text(sf2,T3,'3')      % STATE 3.
    text(s3,T4,'4')       % STATE 4.
    text(sf1,Ts1,'1f')    % STATE 1f.
    text(sg1,Ts1,'1g')    % STATE 1g.
    
else    % WHEN EXIT CONDITION OF STEAM FROM TURBINE IS EITHER WET OR DRY SATURATED.
    
    plot([s1 s2], [T1 T2],'color','c','linewidth',2) % PROCESS 1-2: Isentropic Expansion of STEAM in TURBINE. 
    
    plot([s2 s3], [T2 T3],'color','r','linewidth',2) % PROCESS 2-3: Const. Pressure Heat rejection from STEAM in CONDENSOR.
    
    plot([s3 s4], [Ts2 T4],'color','c','linewidth',2) % PROCESS 3-4: Isentropic Compression of  water in PUMP.
    
    plot([s4 sf1],[T4 Ts1],'color','r','linewidth',2) % PROCESS 4-1F: Constant Pressure Heat Addition in BOILER in SUB-COOLED region of water.
    
    plot([sf1 sg1], [Ts1 Ts1],'color','r','linewidth',2) % PROCESS 1F-1G: Constant Pressure Heat addition in BOILER in WET region of STEAM. 
    
    plot([sg1 s1],[Ts1 T1],'color','r','linewidth',2)  % PROCESS 1G-1: Constant Pressure Heat addition in BOILER in SUPER-HEATED region of STEAM.
    
    
    % Marking Important state points on the T-S diagram.
    
    text(s1,T1,'1')     % STATE 1.
    text(s2,T2,'2')     % STATE 2.
    text(s3,T3,'3')     % STATE 3.
    text(s4,T4,'4')     % STATE 4.
    text(sf1,Ts1,'1f')  % STATE 1F.
    text(sg1,Ts1,'1g')  % STATE 1G.
    
end

% PLOTTING THE SATURATED LIQUID AND SATURATED VAPOUR LINE

    plot(sf,Temp,'color','b','linestyle','-.','linewidth',1.5)   % SATURATED LIQUID LINE.
    plot(sg,Temp,'color','k','linestyle','-.','linewidth',1.5)   % SATURATED VAPOUR LINE.
    title('T-S Diagram')
    xlabel('Entropy[KJ/Kg-K]')
    ylabel('Temperature[K]')
    
    % Plotting H-S Diagram of the RANKINE CYCLE.
    
    figure(2)
    hold on
    grid on
    plot([s1 s2], [h1 h2],'color','c','linewidth',2)   % PROCESS 1-2.
    
    plot([s2 s3], [h2 h3],'color','r','linewidth',2)   % PROCESS 2-3.
    
    plot([s3 s4], [h3 h4],'color','c','linewidth',2)   % PROCESS 3-4.
    
    plot([s4 s1], [h4 h1],'color','r','linewidth',2)   % PROCESS 4-1.
    
    % Plotting the saturated liquid line and saturated vapor line on H-S
    % diagram.
    
    plot(sf,hf,'color','b','linestyle','-.','linewidth',1.5) % SATURATED LIQUID LINE.
    plot(sg,hg,'color','k','linestyle','-.','linewidth',1.5) % SATURATED VAPOUR LINE.
    
    % Marking Important State points on the diagram:
    
    text(s1,h1,'1')              % STATE 1.
    text(s2,h2,'2')              % STATE 2.
    text(s3,h3,'3')              % STATE 3.
    text(s4,h4,'4')              % STATE 4.
    title('H-S Diagram')
    xlabel('Entropy[KJ/Kg-K]')
    ylabel('Enthalpy[KJ/Kg]')
    
    %% PART 3: DISPLAY OF ALL THE STATE POINT VARIABLES VALUES:
    
    % Display
    % 1.1 sTATE pOINT 1
    disp('State Point 1: ')
    fprintf('P1 is: %f Bar\n',P1)           % Pressure, P1.
    fprintf('T1 is: %f Deg. Celcius\n',T1)  % Temperature, T1.
    fprintf('h1 is: %f KJ/Kg\n',h1)         % Enthalpy, h1
    fprintf('s1 is: %f KJ/Kg-K\n',s1)       % Entropy, s1.
    
    
    % 1.2 State Point 2:
    disp('State Point 2: ')
    fprintf('P2 is: %f Bar\n',P2)            % Pressure, P2.
    fprintf('T2 is: %f Deg. Celcius\n',T2)   % Temperature, T2.
    fprintf('x2 is: %f\n',x2)                % Dryness Fraction x2.
    fprintf('h2 is: %f KJ/Kg\n',h2)          % Enthalpy, h2.
    fprintf('s2 is: %f KJ/Kg-K\n',s2)        % Entropy, s2.
    
    
    % 1.3 State Point 3:
    disp('State Point 3: ')
    fprintf('P3 is: %f Bar\n',P3)            % Pressure, P3.
    fprintf('T3 is: %f Deg. Celcius\n',T3)   % Temperature, T3.
    fprintf('h3 is: %f KJ/Kg\n',h3)          % Enthalpy, h3.
    fprintf('s3 is: %f KJ/Kg-K\n',s3)        % Entropy, s3.
    
    
    % State Point 4:
    disp('State Point 4: ')                  
    fprintf('P4 is: %f Bar\n',P4)            % Pressure, P4.
    fprintf('T4 is: %f Deg. Celcius\n',T4)   % Temperature, T4.
    fprintf('h4 is: %f KJ/Kg\n',h4)          % Enthalpy, h4.
    fprintf('s4 is: %f KJ/Kg-K\n',s4)        % Entropy, s4.
    
    fprintf('Turbine Work is: %f KJ/Kg\n',W_T)                                   % TURBINE WORK PRODUCED.
    fprintf('Pump Work is: %f KJ/Kg\n',W_P)                                      % PUMP WORK SUPPLIED.
    fprintf('The Net Work Output of the Cycle is: %f KJ/Kg\n',W_Net)             % NET WORK OUTPUT OF CYCLE.
    fprintf('The Back Work Ratio of the Cycle is: %f Percent\n',Back_Work_Ratio) % BACK WORK RATIO OF CYCLE.
    fprintf('The Thermal Efficiency of the Cycle is: %f Percent\n',Nth)          % THERMAL EFFICIENCY.
    fprintf('The Specific Steam Consumption rate SSC is: %f Kg/Kwh\n',SSC)       % SPECIFIC STEAM CONSUMPTION RATE.
end
 
  


The code is divided into 3 parts, discussed below as follows:
PART 1.1: RANKINE CYCLE INTRODUCTION TO USER:
In this part, the processes comprising the RANKINE CYCLE are mentioned along with the respective state points marking the start and finish of the processes.
Line 8, prints a message on the screen “Rankine Cycle Simulator”.
Line 9, tells the first process of this cycle is from state point 1 to 2 and is called Isentropic Expansion of STEAM in TURBINE.
Line 10, tells the next process of this cycle is from state point 2 to 3 and is called Constant Pressure Heat Rejection in CONDENSOR.
 Line 11, tells the third process of this cycle is from state point 3 to 4 and is called Isentropic compression of water by PUMP.
Line 12, tells the last process of this cycle is from 4 to 1 and is called as Constant Pressure Heat Addition to water in BOILER.

PART 1.2: PRESSURE AND TEMPERATURE AT THE ENTRY TO TURBINE AND ENTRY PRESSURE OF CONDENSOR:

In this section, the user is asked to enter the values for:
1.	Pressure of steam at the entry of the turbine, P1 (line 22).
2.	Temperature of the steam at the turbine entry, T1 (line 23).
3.	Pressure of steam at the exit of turbine or at the entry to condenser, P2 (line 24).

Line 27, the entered values of P1 and T1 have checked whether these values are less than or equal to 0 or not.
If any one of them is less than or equal to 0, then line 28 shows a message on screen “Invalid turbine Entry Condition”. If not, then the code will proceed to further lines.

PART 1.3: DEFINING THE STATE VARIABLE VALUES FOR DIFFERENT STATES DURING THE CYCLE:

In this section, the values of all the necessary state point variables are either obtained from the given function ‘XSteam.m’ or are obtained through thermodynamic relations accompanied by each of the processes in a Rankine cycle.

XSteam function is a function that provides the values of different thermodynamics quantities of steam or water as the output. To do so the function is called into the main program using the following syntax:
Property  =  XSteam(‘pro_XY’,X,Y);
Where,
‘Property’ is some thermodynamic property that depends upon 2 thermodynamic variables, namely X and Y.
‘pro_XY’ is the syntax used to tell which property is to be found out and what must be the input variables.
This is followed by X and Y which are the values of the input thermodynamic variables.
For e.g., it is needed to find the Temperature (T1) of the steam for the given values of Pressure (say ‘P1’ stores the value of pressure) and Entropy (say ‘s1’ is the variable storing this value). So, the syntax to be used will be:
T1 = XSteam(‘T_ps’,P1,s1);
All the representation formats to find different quantities with the help of different variables are listed in the comments section of the function code itself.

Using the XSteam function the following are variables values are found for state point 1:
1.	‘s1’, specific entropy of steam at point 1, line 33.
2.	‘h1’, specific enthalpy of steam at point 1, line 34.
3.	‘hf1’, specific enthalpy of fusion of steam at pressure P1, line 35.
4.	‘hg1’, specific enthalpy of vaporization of water at pressure P1, line 36.
5.	‘sf1’, specific entropy of fusion of steam at pressure P1, line 37.
6.	‘sg1’, specific entropy of vaporization of water at pressure P1, line 38.
7.	‘Ts1’, Saturation Temperature of DRY saturated steam at pressure P1, line 39.

Line 42, the entropy of steam at the exit of the turbine (s2) is equal to that at the entry to the turbine (s1) because the process is considered to be an Isentropic Expansion process.

From lines 43 to 48, the values of variables of state point 2 are obtained through the XSteam function, these are as follows:
1.	‘hf2’, specific enthalpy of fusion of water at pressure P2, line 43.
2.	‘hg2’, specific enthalpy of vaporization of water at pressure P2, line 44.
3.	‘sf2’, specific entropy of fusion of steam at pressure P2, line 45.
4.	‘sg2’, specific entropy of vaporization of water at pressure P2, line 46.
5.	‘Ts2’, Saturation Temperature of DRY saturated steam at pressure P2, line 47.
6.	‘T2’, Temperature of steam at the exit to the turbine (or entry to condensor) depending upon pressure (P2) and entropy (s2), line 48.

Line 49. ‘x2’ is the dryness fraction parameter, this represents the fraction of steam that is present in a quantity of a mixture of steam and water. 
The value of the dryness fraction also tells whether the steam at the exit from the turbine is in WET, DRY SATURATED, or SUPER-HEATED state.

 Line 56, check the state of the steam at the exit of the turbine. If ‘x2’ is less than 1, the steam is in the WET region. The wet region is a mixture of steam and water.
For steam in the wet region the enthalpy is given by, the relation from properties of pure substances, 
h2 = hf2 + x2*(hg2 – hf2), as mentioned in line 58.

If the value of x2 is equal to 1 (line 60), the steam is dry saturated and in this case enthalpy of steam is equal to the enthalpy of vaporization of water corresponding to the pressure P2 (line 62).

If the x2 is greater than 1, the steam is in a superheated state, and in this case, the enthalpy is calculated as mentioned in line 66:
h2 = hg2 + CpS*(T2 – Ts2);


line 70, pressure at 3 is equal to that at 2. Since the process is a constant pressure process.
In general, the exit condition from the condensor is considered to be on the saturated liquid line, so here it is assumed that the exit condition from the condensor is on the saturated liquid line for the pressure P3 (or P2).
Line 71-75, XSteam function is used to find the values of:
1.	‘s3’ entropy of water at the exit from condensor, it is equal to sf3. 
2.	‘hf3’ enthalpy of fusion of steam at pressure P3.
3.	‘hg3’ enthalpy of vaporization of steam at pressure P3.
4.	‘sf3’ entropy of fusion of water at pressure P3. 
5.	‘sg3’ entropy of vaporization of water at pressure P3.
Line 76, enthalpy at the exit of condensor (h3) is equal to the enthalpy of fusion of steam (hf3) at pressure P3.
Line 77, the temperature at the exit of the condensor (T3) is calculated through the XSteam function.
Line 78, ‘CpW’ is the specific heat of water at constant pressure.
Line 79, ‘CvW’ is the specific heat of water at constant volume.
Line 81, ‘gamma’ is adiabatic gas constant.
Line 82, ‘K’ is the power coefficient, used to find the temperature T4.
K = (gamma – 1)/gamma
Line 87, pressure at state 4 (P4) is equal to the pressure at state 3 (P3) since the process is a constant pressure process.
Line 88, entropy at state 4 (s4) is equal to the entropy at state 3 (s3), since process 3-4 is an Isentropic process so entropy is constant.
Line 89, ‘h4’ is the enthalpy at state 4 and is calculated through the XSteam function using P4 and s4 as the input variables.
Line 90, the temperature at state 4 is calculated using the adiabatic process relation;
(T4/T3)  = (P4/P3)^K
Line 92, ‘W_T’ is the work produced by the turbine, it is equal to the difference between the enthalpy of steam at state 1 (h1) and state 2 (h2).
Line 93, ‘W_P’ is the work consumed by the pump, it is equal to the difference between the enthalpy of steam at state 4 (h4) and state 3 (h3).
Line 94, the net work obtained from the cycle is defined as ‘W_Net’. It is the difference between turbine work and pump work.
Line 95, the Back Work Ratio is the ratio of the pump work and the turbine work for the given cycle. It is defined here by the variable ‘Back_Work_Ratio’.
Line 96, ‘Qs’ is the heat supplied to the cycle, equal to the difference of h1 and h4.
Line 97, ‘Qr’ is the heat rejected from the cycle, equal to the difference of h4 and h3.
Line 98, ‘Nth’ is the thermal efficiency of the Rankine cycle for the given temperature limits. It is the ratio of the Net work (W_Net) developed and the Heat Supplied to the system (Qs).
Line 99, ‘SSC’ is defined as the Specific Steam Consumption, it is the amount of Steam utilized in order to generate a 1kW Net Work output from the cycle.

Line 101, ‘Temp’ is a row vector with temperature values from 1 to 400 as its elements. There are in total 500 elements in this row vector which are linearly varying from 1 to 400.

PART 2: Plotting T-S and H-S diagram representing all the processes in the Cycle:

In this section, the T-S and H-S diagram for the given Rankine cycle are plotted.

Line 108, a for loop is initiated, with its loop counter I varying from 1 to the length of ‘Temp’ vector i.e., 500.
Line 110, ‘hf(i)’ is the enthalpy of fusion corresponding to the temperature value of the ith element of ‘Temp’. For the entire loop the row vector ‘hf’ is obtained containing these values for the entire temperature range, and when plotted against the temperature range will generate the SATURATED LIQUID LINE on the T-S diagram.

Similarly, in line 111, the ‘hg(i)’ is the enthalpy of vaporization, for the entire loop row vector ‘hg’ is obtained which plotted against the ‘temp’ will give the SATURATED VAPOUR LINE on the T-S diagram.

Line 112, ‘sf(i)’ is the entropy of fusion corresponding to the temperature value of the ith element of ‘Temp’. For the entire loop ‘sf’ is obtained containing these values for the entire temperature range, and when plotted against the temperature range will generate the SATURATED LIQUID LINE on the H-S diagram.

Similarly, in line 113, the ‘sg(i)’ is the enthalpy of vaporization, for the entire loop row vector ‘sg’ is obtained which plotted against the ‘temp’ will give the SATURATED VAPOUR LINE on the H-S diagram.

Line 117, a new figure window (figure 1) is opened.
Line 118, hold on feature is turned on, to prevent overwriting of the plots creates and allowing superimposition of the plots.
Line 119, gridlines are turned on.
When the steam expands in the turbine there are two possibilities that may arise:
1.	The steam may leave the turbine in a superheated state, or
2.	Steam may leave the turbine in a wet or dry saturated state.
For both these conditions, the T-S diagram of the cycle is different and to plot the condition of the steam correctly it is necessary to check the condition of the steam leaving the turbine.
Line 121, checks if the exit steam is in a SUPERHEATED state or not. If the entropy of the steam at state 2 (s2) is greater than the entropy of vaporization (sg2) corresponding to the pressure P2, then steam is in a super-heated state. If it is less than or equal to sg2 then it is not in a super-heated state.  
If the steam is in a super-heated state, then:
Line 123, will plot Process 1-2: Isentropic Expansion of Steam in Turbine. The X-coordinate (‘s’) vary from s1 to s2, Y-coordinate (‘Temp’) varies from T1 to T2. The color is set to cyan by ‘color’, ‘c’ and the line width is fixed to 2 by ‘linewidth’, 2.
Line 125, will plot the Process 2-2g: Constant Pressure Heat Rejection in Condensor. It is a sub-part of process 2-3, which occurs in the super-heated region. The X-coordinate (‘s’) vary from s2 to sg2, Y-coordinate (‘Temp’) varies from T2 to Ts2. The color is set to cred by ‘color’, ‘r’ and the line width is fixed to 2 by ‘linewidth’, 2.
Line 127, will plot the Process 2g-2f: Constant Pressure Heat Rejection in Condensor. It is a sub-part of process 2-3, which occurs in the wet region. The X-coordinate (‘s’) vary from sg2 to sf2, Y-coordinate (‘Temp’) remains the same (Ts2). The color is set to cred by ‘color’, ‘r’ and the line width is fixed to 2 by ‘linewidth’, 2.
Line 129, will plot Process 3-4: Isentropic Compression of Water by Pump. The X-coordinate (‘s’) vary from sf2 to s3, Y-coordinate (‘Temp’) varies from T3 to T4. The color is set to cyan by ‘color’, ‘c’ and the line width is fixed to 2 by ‘linewidth’, 2.
Line 131, will plot the Process 4-1f: Constant Pressure Heat Addition in Boiler. It is a sub-part of the entire process 4-1, which occurs in the sub-cooled region. The X-coordinate (‘s’) vary from s4 to sf1, Y-coordinate (‘Temp’) varies from T4 to Ts1. The color is set to red by ‘color’, ‘r’, and the line width is fixed to 2 by ‘linewidth’, 2.
Line 133, will plot the Process 1f-1g: Constant Pressure Heat Rejection in Boiler. It is a sub-part of the entire process 4-1, which occurs in the wet region. The X-coordinate (‘s’) vary from sf1 to sg1, Y-coordinate (‘Temp’) remains the same (Ts1). The color is set to red by ‘color’, ‘r’, and the line width is fixed to 2 by ‘linewidth’, 2.
Line 135, will plot the Process 1f-1: Constant Pressure Heat Addition in Boiler. It is a sub-part of the entire process 4-1, which occurs in a super-heated region. The X-coordinate (‘s’) varies from sg1 to s1, Y-coordinate (‘Temp’) varies from Ts1 to T1. The color is set to red by ‘color’, ‘r’, and the line width is fixed to 2 by ‘linewidth’, 2.
Line 138-144 the important state points during the Rankine cycle are marked on the plot with the help of the ‘text’ command. This command takes in the X and Y- coordinates values of a point as input. And the text that must be shown at that coordinate point. 
If the steam leaving the turbine is not in the super-heated region, then the T-S diagram is plotted through the following lines:
Line 148, will plot Process 1-2: Isentropic Expansion of Steam in Turbine. The X-coordinate (‘s’) vary from s1 to s2, Y-coordinate (‘Temp’) varies from T1 to T2. The color is set to cyan by ‘color’, ‘c’ and the line width is fixed to 2 by ‘linewidth’, 2.
Line 150, will plot Process 2-3: Constant Pressure Heat Rejection in Condensor. The X-coordinate (‘s’) vary from s2 to s3, Y-coordinate (‘Temp’) varies from T2 to T3. The color is set to cred by ‘color’, ‘r’ and the line width is fixed to 2 by ‘linewidth’, 2.
Line 152, will plot Process 3-4: Isentropic Compression of Water by Pump. The X-coordinate (‘s’) vary from s3 to s4, Y-coordinate (‘Temp’) varies from T3 to T4. The color is set to cyan by ‘color’, ‘c’ and the line width is fixed to 2 by ‘linewidth’, 2.
Line 154, will plot the Process 4-1f: Constant Pressure Heat Addition in Boiler. It is a sub-part of the entire process 4-1, which occurs in the sub-cooled region. The X-coordinate (‘s’) vary from s4 to sf1, Y-coordinate (‘Temp’) varies from T4 to Ts1. The color is set to red by ‘color’, ‘r’, and the line width is fixed to 2 by ‘linewidth’, 2.
Line 156, will plot the Process 1f-1g: Constant Pressure Heat Rejection in Boiler. It is a sub-part of the entire process 4-1, which occurs in the wet region. The X-coordinate (‘s’) vary from sf1 to sg1, Y-coordinate (‘Temp’) remains the same (Ts1). The color is set to red by ‘color’, ‘r’, and the line width is fixed to 2 by ‘linewidth’, 2.
Line 158, will plot the Process 1f-1: Constant Pressure Heat Addition in Boiler. It is a sub-part of the entire process 4-1, which occurs in a super-heated region. The X-coordinate (‘s’) varies from sg1 to s1, Y-coordinate (‘Temp’) varies from Ts1 to T1. The color is set to red by ‘color’, ‘r’ and the line width is fixed to 2 by ‘linewidth’, 2.

Line 163-168 the important state points during the Rankine cycle are marked on the plot with the help of the ‘text’ command. In this case, the point ‘2g’ (as in for 1st case in line 140) is not seen since the steam is not in a super-heated region therefore this point is not seen.
Line 163, ‘1’ is marked on the plot representing state point 1.
Line 164, ‘2’ is marked on the plot representing state point 2.
Line 165, ‘3’ is marked on the plot representing the state point 3.
Line 166, ‘4’ is marked on the plot representing state point 4.
Line 167, ‘1f’ is marked on the plot representing the state point 1f.
Line 168, ‘1g’ is marked on the plot representing the state point 1g.

Line 174, the plot between the row vector ‘sf’ as X-axis variable and temperature ‘Temp’ as Y-Axis variable is drawn. This plot is the SATURATED LIQUID LINE and is represented on the plot with the help of a blue dashed curve slopping upwards on the left.
Line 175, similarly the row vector ‘sg’ as X-axis variable and temperature is plotted against the temperature ‘Temp’ as Y-Axis variables is drawn and the curve obtained id the SATURATED VAPOUR LINE, represented by black dashed curve sloping downwards on the right.
Line 176, ‘title’ command gives the title of the plot as ‘T-S Diagram’.
Line 177 and 178 the commands ‘xlabel’ and ‘ylabel’ give the names of the X and the Y axes as ‘Entropy [KJ/Kg-K]’ and ‘Temperature [Deg. Celcius]’ respectively.
Line 182, a new figure window (figure 2) is opened.
Line 183 hold on feature is turned on.
Line184, the grid lines are also turned on.
Now the H-S Diagram of the given Rankine cycle will be plotted. Unlike the T-S diagram, there are sub-division of the process occurring in the condensor or in the boiler and are easily plotted in this diagram.
Line 185, plots Process 1-2: Isentropic Expansion of the Steam in Turbine. The X-coordinate, Entropy ‘s’ varies from s1 to s2 and the Y-coordinate, Enthalpy ‘h’ varies from h1 to h2. The color is set to cyan by ‘color’, ‘c’, and the line width is set to 2 by ‘linwidth’, 2.
Line 187, plots the Process 2-3: Constant Pressure Heat Rejection in Condensor. The X-coordinate, Entropy ‘s’ varies from s2 to s3 and the Y-coordinate, Enthalpy ‘h’ varies from h2 to h3. The color is set to cyan by ‘color’, ‘r’, and the line width is set to 2 by ‘linwidth’, 2.
Line 189, plots Process 3-4: Isentropic Compression in Pump. The X-coordinate, Entropy ‘s’ varies from s3 to s4 and the Y-coordinate, Enthalpy ‘h’ varies from h3 to h4. The color is set to cyan by ‘color’, ‘c’, and the line width is set to 2 by ‘linwidth’, 2.
Line 191, plots the Process 2-3: Constant Pressure Heat Addition in Boiler. The X-coordinate, Entropy ‘s’ varies from s4 to s1 and the Y-coordinate, Enthalpy ‘h’ varies from h4 to h1. The color is set to cyan by ‘color’, ‘r’, and the line width is set to 2 by ‘linwidth’, 2.

Line 196, the plot between the row vector ‘sf’ as X-axis variable and row vector of enthalpy of fusion ‘hf’ as Y-Axis variable is drawn. This plot is the SATURATED LIQUID LINE and is represented on the plot with the help of a blue dashed curve. The line width is kept at 1.5 using ‘linwidth’, 1.5.
Line 197, similarly the row vector ‘sg’ as X-axis variable and row vector of enthalpy of fusion ‘hf’ as Y-Axis variables is drawn and the curve obtained is the SATURATED VAPOUR LINE, represented by the black dashed curve. The line width is kept at 1.5 using ‘linwidth’, 1.5.
Line 201, state point 1 is marked on the plot representing the beginning of the process 1-2.
Line 202, state point 2 is marked on the plot representing the beginning of process 2-3.
Line 203, state point 3 is marked on the plot representing the beginning of the process 3-4.
Line 204, state point 4 is marked on the plot representing the beginning of the process 4-1.
Line 205, ‘title’ command is used to set the title of the plot as ‘H-S Diagram’.
Line 206 and 207 the commands ‘xlabel’ and ‘ylabel’ give the names of the X and the Y axes as ‘Entropy [KJ/Kg-K]’ and ‘Enthalpy [KJ/Kg]’ respectively.


PART 3: DISPLAY OF ALL THE STATE POINT VARIABLES VALUES:

In this section, all the output values of the state variables are printed on the screen for each of the states respectively.
Line 213-217, the values of state variables at state 1 are displayed as follows:
Line 213, displays the current state point using ‘disp’ command.
Line 214, ‘fprintf’ command displays the message on-screen “P1 is XXX Bars”. In place of XXX, there is the numerical value. %f tells the value of the variable ‘P1’ is a floating-point number i.e., a number with digits after a decimal place also.
Similarly, in lines 215-217, fprintf command prints the value of T1 (the temperature at state 1), h1 (Enthalpy at state 1), and s1 (entropy at state 1) respectively.
Line 221, displays the current state point variables are for state point 2.
Line 222-226, fprintf prints the values of the pressure at point 2 (P2), the temperature at point 2 (T2), enthalpy at point 2 (h2), and entropy at point 2 (s2) respectively.
Line 229, displays the current state point variables are for state point 3.
Line 230-233, fprintf prints the values of the pressure at point 3 (P3), the temperature at point 3 (T3), enthalpy at point 3 (h3), and entropy at point 3 (s3) respectively.
Line 238, displays the current state point variables are for state point 4.
Line 238-242, fprintf prints the values of the pressure at point 4 (P4), the temperature at point 4 (T4), enthalpy at point 4 (h4), and entropy at point 4 (s4) respectively.
Line 244, prints the work developed by the turbine on screen.
Line 245, prints the work consumed by the pump on the screen.
Line 246, the net work output from the cycle is printed on the screen through this line.
Line 247, the back work ratio value for the cycle is printed on the screen.
Line 248, the thermal efficiency of the cycle is printed through this line.
Line 249, the value of specific steam consumption SSC is printed on the screen by this line.


The outputs from this code are:
1.	T-S Diagram plot against the Temperature (Temp) and the Entropy of the steam (s) throughout the cycle.
2.	H-S diagram plot against the Enthalpy (h) of the steam for the entire cycle against the Entropy (s) of the steam.
3.	Display 4 thermodynamic quantities values namely; Pressure, Temperature, Enthalpy, and Entropy of the steam for each state from state 1 to state 4 on the screen.
4.	Display of the cycle performance parameters, namely; turbine work, pump work, net work output, back work ratio, thermal efficiency, and specific fuel consumption on the screen. 

All the screenshots and the plots are attached below.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.