Rankine cycle Simulator using MATLAB
Project: Rankine Cycle simulator using MATLAB
AIM: To write a code to create a 'Rankine Cycle' simulator using MATLAB using 'XSteam' function.
OBJECTIVE:
(1) Create a Rankine Cycle Simulator using MATLAB.
(2) Write code to calculate the state points of the Rankine Cycle.
(3) Plot the corresponding T-s and h-s plots for the given set of inputs.
BRIEF:
The Rankine cycle is the fundamental operating cycle of all power plants where an operating fluid is continuously evaporated and condensed. The selection of operating fluid depends mainly on the available temperature range. Figure (i) shows the idealized Rankine cycle. The pressure-velocity (p-h) and temperature-entropy (T-s) diagrams of this cycle are given in figure (ii).

figure(i). Schematic Layout of Idealized Rankine cycle
The Rankine cycle operates in the following steps:
-
1-2 Isentropic Expansion: The vapour is expanded in the turbine, thus producing work which may be converted to electricity. In practice, the expansion is limited by the temperature of the cooling medium and by the erosion of the turbine blades by liquid entrainment in the vapour stream as the process moves further into the two-phase region. Exit vapour qualities should be greater than 90%.
-
2-3 Isobaric Heat Rejection: The vapour-liquid mixture leaving the turbine (2) is condensed at low pressure, usually in a surface condenser using cooling water. In well designed and maintained condensers, the pressure of the vapour is well below atmospheric pressure, approaching the saturation pressure of the operating fluid at the cooling water temperature.
-
3-4 Isentropic Compression: The pressure of the condensate is raised in the feed pump. Because of the low specific volume of liquids, the pump work is relatively small and often neglected in thermodynamic calculations.
- 4.1 Isobaric Heat Transfer: High-pressure liquid enters the boiler from the feed pump (3) and is heated to the saturation temperature (1). Further addition of energy causes evaporation of the liquid until it is fully converted to saturated steam (1).

figure(ii). p-v, T-s & h-s diagrams of Rankine cycle
Syntax used:
(1) fprintf - Write data to a text file.
(2) linspace - It is used to generate a linearly spaced vector.
(3) plot - 2-D line plotting.
(4) text - Add text descriptions to data points.
CODE LOGIC:
(1) First we assigned the variables to the given input to solve the Rankine cycle.
(2) Extracted and stored them into a variable for the value for the enthalpy, entropy & volume value w.r.t. to given pressure and temperature using the function 'XSteam'.
(3) Calculated the enthalpy at each point using the values extracted from the function and also find the respective temperature at each point.
(4) Use a for loop to checking the value of dryness factor `x` at stage 2, where it is in the liquid state or vapour state.
(5) After all the enthalpy values are calculated, we can derive the equation to solve for work done and heat calculation in the cycle.
(6) Now calculate the performance of the Rankine cycle using the values of enthalpy.
(7) Create the graph for `T-s` and `h-s` using the values calculated and extracted from the function. To plot the saturated entropy curve for liquid and vapour line, we created a for loop w.r.t. temperature and extracted the values for entropy for liquid state and the vapour state.
(8) Use the 'fprintf' command to display the results & values at each point the command window.
CODE:
To get the values of the steam table, use a function code 'XSteam'.
%%Program for RANKINE cycle Simulator
clear all %clear the workspace
close all %close all the opened window
clc %clear the command
%%Printing the value in command
fprintf (' RANKINE CYCLE SIMULATORnn')
fprintf ('1-2 = Isentropic Expansion in the Turbinen')
fprintf ('2-3 = Const Pressure heat rejection by the condensorn')
fprintf ('3-4 = Isentropic compression in the Pumpn')
fprintf ('4-1 =Const Pressure heat addition by the Boilernn' )
p1 = input('Enter the Pressure the Turbine Inlet (in bar)=')
T1 = input('Enter the Temperature at the Turbine Inlet (in degree celcius)=')
p2 = input('Enter the Pressure at the Condensor(in bar)=')
disp (' RESULTS')
%%Input variable
p4 = p1;
p3 = p2;
Tsup = T1;
%%Extract values from Steam table using the function 'XSteam'
hg_1 = XSteam('h_pT',p1,T1);
Cp_1 = XSteam('CpV_p',p1);
Tsat = XSteam('Tsat_p',p2);
sf2 = XSteam('sL_p',p2);
sg2 = XSteam('sV_p',p2);
hf2 = XSteam('hL_p',p2);
hg2 = XSteam('hV_p',p2);
s1 = XSteam('s_pT',p1,T1);
hf3 = XSteam('hL_p',p3);
v3 = XSteam('vL_p',p3);
s3 = XSteam('sL_p',p3);
sg4 = XSteam('sL_p',p4);
sf4 = XSteam('sL_p',p4);
%%Enthalpy calculation at Stage 1
h1 = hg_1;
%%Printing the values in command window
fprintf ('At Stage point 1:n')
fprintf ('P1 = %f barn',p1)
fprintf ('T1 = %f degree celciusn',T1)
fprintf ('H1 = %f KJ/kgn',h1)
fprintf ('S1 = %f KJ/kgknn',s1)
%%Enthalpy calculation at Stage 2
s2 = s1; %Entropy is same from 1-2
%s1 = sf2 + (x_2*sfg_2);
sfg_2 = sg2-sf2;
x2 = ((s1-sf2)/(sfg_2)); %Calculation of dryness fraction at point 2
h2 = hf2 + (x2*(hg2-hf2));
if x2<1
T2 = Tsat;
%s2 = sg2+low_cpv(log(T2/Tsat))
else T2 = (Tsat+273)*exp((s2-sg2)/Cp_1);
T2 = T2-273;
end
%%Printing the values in command window
fprintf ('At Stage point 2:n')
fprintf ('P2 = %f barn',p2)
fprintf ('T2 = %f degree celciusn',T2)
fprintf ('H2 = %f KJ/kgn',h2)
fprintf ('S2 = %f KJ/kgknn',s2)
%%Temperature at outlet turbine
T3 = T2;
%%Entalpy calculation at Stage 3
h3 = hf3;
%%Printing the values in command window
fprintf ('At Stage point 3:n')
fprintf ('P3 = %f barn',p3)
fprintf ('T3 = %f degree celciusn',T3)
fprintf ('H3 = %f KJ/kgn',h3)
fprintf ('S3 = %f KJ/kgknn',s3)
%%Enthalpy calculation at Stage 4
h4 = v3*(p4-p3)*100 + h3;
%%Temperature & entropy for plot the graph for line 4-1
s4 = s3;
T4 = XSteam('T_ps',p4,s4);
T5 = XSteam('Tsat_p',p1);
T6 = T5;
s5 = XSteam('sL_T',T5);
s6 = XSteam('sV_T',T6);
%%Printing the values in command window
fprintf ('At Stage point 4:n')
fprintf ('P4 = %f barn',p4)
fprintf ('T4 = %f degree celciusn',T4)
fprintf ('H4 = %f KJ/kgn',h4)
fprintf ('S4 = %f KJ/kgknn',s4)
%%Heat calculation
Qin = h1-h4;
Qout = h2-h3;
%%Printing the values in command window
fprintf ('Heat & work done in the Rankine cylcen')
fprintf ('Qin :%f Jn',Qin)
fprintf ('Qout :%f Jn',Qout)
%%Work done & efficiency for the Rankine cycle
W_t = h1-h2;
W_p = h4-h3;
Wnet = W_t - W_p;
%%Printing the values in command window
fprintf ('Work done by Turbine :%f Jn',W_t)
fprintf ('Work done by Pump :%f Jn',W_p)
fprintf ('Net Work done :%fnn',Wnet)
%%Performance of the Rankine cycle
eff = Wnet/Qin;
SSC = 3600/Wnet;
work_ratio = Wnet/W_t;
%%Printing the values in command window
fprintf ('Performance of RANKINE CYCLEn')
fprintf ('Efiiciency :%fn',(eff*100))
fprintf ('Specific Steam Consumption :%fn',SSC)
fprintf ('Back work ratio :%fn',work_ratio)
%%Temperature range for the saturated entropy for liquid & vapour line
temp = linspace(0,600,500);
for i = 1:length(temp)
h_l(i) = XSteam('hL_T',temp(i));
h_v(i) = XSteam('hV_T',temp(i));
s_l(i) = XSteam('sL_T',temp(i));
s_v(i) = XSteam('sV_T',temp(i));
end
%%Plotting graph for Rankine Cycle
figure(1) %T-S curve
hold on
plot(s1 ,T1,'.')
text (s1, T1, '1')
plot(s2 ,T2,'.')
text (s2, T2, '2')
plot(s3 ,T3,'.')
text (s3, T3, '3')
plot(s4 ,T4,'.')
text (s4, T4, '4')
plot(s5 ,T5,'.')
text (s5, T5, '4s')
plot(s6 ,T6,'.')
text (s6, T6, '1s')
plot(s_l,temp,'linestyle','--','linewidth',1.5)
plot(s_v,temp,'linestyle','--','linewidth',1.5)
plot([s1 s2 s3 s4 s5 s6 s1],[T1 T2 T3 T4 T5 T6 T1],'color','r','linewidth',1)
xlabel('Entropy (KJ/kgk)')
ylabel ('Temperature (k)')
axis ([0 10 0 500])
title ('Temperature vs Entropy for Rankine Cycle')
grid on
figure (2) %h-s curve
hold on
plot(s1, h1,'.')
text (s1, h1, '1')
plot(s2, h2,'.')
text (s2, h2, '2')
plot(s3, h3,'.')
text (s3, h3, '3')
plot(s4, h4,'.')
text (s4, h4, '4')
plot(s_l,h_l,'linestyle','--','linewidth',1.5)
plot(s_v,h_v,'linestyle','--','linewidth',1.)
plot([s1 s2 s3 s4 s1],[h1 h2 h3 h4 h1],'color','b','linewidth',1)
xlabel ('Entropy (KJ/kgk)')
ylabel ('Enthalpy (KJ/kg)')
title ('Enthalpy vs Entropy for Rankine Cycle')
grid on
%%End of Program
GRAPHS:
(1) Graph for Temperature vs Entropy:

figure (iii). T-s curve for Rankine cycle
(2) Graph for Enthalpy vs Entropy:

figure (v). h-s curve for Rankine cycle
RESULTS:


CONCLUSION: Successfully executed the code to plot the graph for `T-s` and `h-s` curve and calculated the performance of the Rankine cycle using the function 'XSteam'.
REFERENCE:
(1) Thermal Engineering by R.S. Khurmi.
(2) http://thermopedia.com/content/1072/
(3) https://www.youtube.com/watch?v=zyWX4xAmvdI&feature=youtu.be