Project 2 - Rankine cycle Simulator
Aim : Create a Rankine Cycle Simulator using MATLAB.Code should calculate the state points of the Rankine Cycle (any type of your choice) based on user inputs. Then, plot the corresponding T-s and h-s plots for the given set of inputs.
Concept of Rankine cycle :
The Rankine cycle is a model used to predict the performance of steam turbine systems. It was also used to study the performance of reciprocating steam engines. The Rankine cycle is an idealized thermodynamic cycle of a heat engine that converts heat into mechanical work while undergoing phase change. It is an idealized cycle in which friction losses in each of the four components are neglected. The heat is supplied externally to a closed loop, which usually uses water as the working fluid. It is named after William John Macquorn Rankine, a Scottish polymath and Glasgow University professor.
The four processes in the Rankine cycle
T–s diagram of a typical Rankine cycle operating between pressures of 0.06 bar and 50 bar. Left from the bell-shaped curve is liquid, right from it is gas, and under it is saturated liquid–vapour equilibrium.
There are four processes in the Rankine cycle. The states are identified by numbers (in brown) in the T–s diagram.
Process 1–2: The working fluid is pumped from low to high pressure. As the fluid is a liquid at this stage, the pump requires little input energy.
In other words Process 1-2 is [Isentropic compression]
Process 2–3: The high-pressure liquid enters a boiler, where it is heated at constant pressure by an external heat source to become a dry saturated vapour. The input energy required can be easily calculated graphically, using an enthalpy–entropy chart (h–s chart, or Mollier diagram), or numerically, using steam tables.
In other words Process 2-3 is [Constant pressure heat addition in boiler]
Process 3–4: The dry saturated vapour expands through a turbine, generating power. This decreases the temperature and pressure of the vapour, and some condensation may occur. The output in this process can be easily calculated using the chart or tables noted above.
In other words Process 3-4 is [Isentropic expansion]
Process 4–1: The wet vapour then enters a condenser, where it is condensed at a constant pressure to become a saturated liquid.
In other words Process 4-1 is [Constant pressure heat rejection in condenser]
In an ideal Rankine cycle the pump and turbine would be isentropic, i.e., the pump and turbine would generate no entropy and hence maximize the net work output. Processes 1–2 and 3–4 would be represented by vertical lines on the T–s diagram and more closely resemble that of the Carnot cycle. The Rankine cycle shown here prevents the state of the working fluid from ending up in the superheated vapor region after the expansion in the turbine, which reduces the energy removed by the condensers.
The actual vapor power cycle differs from the ideal Rankine cycle because of irreversibilities in the inherent components caused by fluid friction and heat loss to the surroundings; fluid friction causes pressure drops in the boiler, the condenser, and the piping between the components, and as a result the steam leaves the boiler at a lower pressure; heat loss reduces the net work output, thus heat addition to the steam in the boiler is required to maintain the same level of net work output.
In general, the efficiency of a simple rankine cycle can be written as

Matlab code is following :
clear all
close all
clc
fprintf ('%80s \n\n','RANKINE CYCLE SIMULATOR')
fprintf ('1-2 is Isentropic Expansion in Turbine \n')
fprintf ('2-3 is Const Pressure Heat Rejection by the Condenser \n')
fprintf ('3-4 is Isentropic Compression in the Pump \n')
fprintf ('4-1 is Const Pressure Heat Addition by the Boiler \n\n')
% user inputs
P1 = input('Enter the Pressure at the Turbine Inlet (in bar) :');
T1 = input('Enter the Temperature at the Turbine Inlet (in Degree Celcius) :');
P2 = input('Enter the Pressure at Condenser (in bar) :');
%Results execution
fprintf ('\n %70s','RESULTS')
% for State Point 1
S1 = XSteam ('s_pT',P1,T1);
H1 = XSteam ('h_pT',P1,T1);
% for State Point 2
S2 = S1;
sf2 = XSteam ('sL_p',P2);
sg2 = XSteam ('sV_p',P2);
hf2 = XSteam ('hL_p',P2);
hg2 = XSteam ('hV_p',P2);
T2 = XSteam ('Tsat_p',P2);
x2 = ((S2-sf2)/(sg2-sf2));
H2 = hf2+(x2*(hg2-hf2));
% for State Point 3
P3 = P2;
T3 = XSteam ('Tsat_p',P3);
S3 = XSteam ('sL_p',P3);
H3 = XSteam ('hL_p',P3);
% Gamma calculation
cp = XSteam('cpL_p',P3);
cv = XSteam('cvL_p',P3);
gamma = (cp/cv);
% for State Point 4
P4 = P1;
S4 = S3;
H4 = XSteam('h_ps',P4,S4);
T4 = T3*((P4/P3)^((gamma-1)/gamma));
%work done calculation
%turbine work(output)
Wt = H1 - H2;
%pump work(input)
Wp = H4 - H3;
%net work
W_net = Wt-Wp;
%heat input and output
q_in = H1 - H4;
q_out = H2 - H3;
%efficiency = nwt work/heat input
n = W_net/q_in;
n_percent = n*100;
SSC = 3600/W_net;
%Back work ratio
BWR = q_in/q_out;
% At State Points 5 and 6
T5 = XSteam('Tsat_p',P1);
T6 = T5;
S5 = XSteam('sL_p',P1);
S6 = XSteam('sV_p',P1);
H5 = XSteam('hL_p',P1);
H6 = XSteam('hV_p',P1);
% Plotting the Graphs
% T-S Graph
figure(1)
T_Zone1 = linspace(T5,T1,500);
for i = 1:length(T_Zone1)
S(i) = XSteam('s_pt',P1,T_Zone1(i));
end
hold on
plot([S1 S2 S3 S4 S5 S6 S],[T1 T2 T3 T4 T5 T6 T_Zone1],'linewidth',3,'color','k')
axis ([0 10 0 430])
text (S1,T1,'1','FontSize',10)
text (S2,T2,'2','FontSize',10)
text (S3,T3,'3','FontSize',10,'verticalalignment','top')
text (S4,T4,'4','FontSize',10,'verticalalignment','bottom','horizontalalignment','right')
text (S5,T5,'5','FontSize',10,'verticalalignment','top')
text (S6,T6,'6','FontSize',10,'verticalalignment','top','horizontalalignment','right')
T_Zone2 = linspace(0,T1,500);
for j = 1:length(T_Zone2)
sl(j) = XSteam('sL_T',T_Zone2(j));
sv(j) = XSteam('sV_T',T_Zone2(j));
hl(j) = XSteam('hL_T',T_Zone2(j));
hv(j) = XSteam('hV_T',T_Zone2(j));
end
plot (sl,T_Zone2,'linewidth',1.5,'color','r')
plot (sv,T_Zone2,'linewidth',1.5,'color','r')
xlabel('Entropy (S)')
ylabel('Temperature (T)')
title ('Entropy vs. Temperature (T-S Dia)')
%Enthalpy vs.entropy plot( H-S Graph)
figure(2)
hold on
plot([S1 S2 S3 S4 S1],[H1 H2 H3 H4 H1],'linewidth',3,'color','k')
axis ([0 10 -100 3500])
text (S1,H1,'1','FontSize',10)
text (S2,H2,'2','FontSize',10)
text (S3,H3,'3','FontSize',10,'verticalalignment','top','horizontalalignment','left')
text (S4,H4,'4','FontSize',10,'verticalalignment','bottom','horizontalalignment','right')
plot(sv,hv,'linewidth',1.5,'color','r')
plot(sl,hl,'linewidth',1.5,'color','r')
xlabel('Entropy (S)')
ylabel('Enthalpy (H)')
title ('Enthalpy vs. Entropy (H-S Dia)')
% Results as per challenge Description
fprintf ('At State Point 1 : \n')
fprintf ('P1 is : %f Bar \n',P1)
fprintf ('T1 is : %f Deg Celcius \n',T1)
fprintf ('H1 is : %f kJ/kg \n',H1)
fprintf ('S1 is : %f kJ/kgK \n',S1)
fprintf ('At State Point 2 : \n')
fprintf ('P2 is : %f Bar \n',P2)
fprintf ('T2 is : %f Deg Celcius \n',T2)
fprintf ('H2 is : %f kJ/kg \n',H2)
fprintf ('S2 is : %f kJ/kgK \n',S2)
fprintf ('X2 is : %f \n',x2)
fprintf ('At State Point 3 : \n')
fprintf ('P3 is : %f Bar \n',P3)
fprintf ('T3 is : %f Deg Celcius \n',T3)
fprintf ('H3 is : %f kJ/kg \n',H3)
fprintf ('S3 is : %f kJ/kgK \n',S3)
fprintf ('At State Point 4 : \n')
fprintf ('P4 is : %f Bar \n',P4)
fprintf ('T4 is : %f Deg Celcius \n',T4)
fprintf ('H4 is : %f kJ/kg \n',H4)
fprintf ('S4 is : %f kJ/kgK \n\n',S4)
fprintf ('Wt : %f kJ/kg \n',Wt)
fprintf ('Wp : %f kJ/kg \n',Wp)
fprintf ('Wnet : %f kJ/kg \n',W_net)
fprintf ('Ntherm : %f percent \n',n_percent)
fprintf ('SSC : %f kg/kWh\n',SSC)
fprintf ('BWR : %f \n',BWR)
Code Explanation :
Using fprintf command for displaying the required data on command window.
As described in challenge the input value of Turbine Inlet temperature ,
Turbine Inlet Pressure ,Turbine Outlet Pressure (Condenser Inlet Pressure) as T1 ,P1 and P2 respectively.
And using the XStream required parameters are founded.and then using them into basic formulas other parameters founded.like net work done , efficiency, Back work ratio.
For plotting, between point 5 and 1 temp.zone is assumed and their entropy is founded.
As described in challenge the plot is made using text command and state point number is also displayed.for better understanding.
Then,finally T-S and H-S diagram is plotted.
And at last the results are shown by using fprintf command , Results includes State parameters values.
PLOTS:
Output Window:
Errors while Programing :
many typo errors were their like wrong parameter is executed from the steam table and also find error in joining the point 5 and 1.
which were rectified by go through the code carefully and some idea from the other reference .
References: