Project 2 - Rankine cycle Simulator
AIM: Write a Matlab code to simulate the Rankine cycle.
OBJECTIVES:
- Create a Rankine Cycle Simulator using MATLAB.
- Calculate the state points of the Rankine Cycle based on user inputs.
- Plot the corresponding T-s and h-s plots for the given set of inputs.
THEORY:
The Rankine cycle describes the performance of steam turbine systems and is an idealized thermodynamic cycle of a constant pressure heat engine that converts part of heat into mechanical work. In this cycle, the heat is supplied externally to a closed loop, which usually uses water (in a liquid and vapor phase) as the working fluid.

Rankine Cycle -processes
- 1-2 Isentropic Expansion. The vapor is expanded in the turbine, thus producing work that 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 vapor stream as the process moves further into the two-phase region. Exit vapor qualities should be greater than 90%.
- 2-3 Isobaric Heat Rejection. The vapor-liquid mixture leaving the turbineis condensed at low pressure, usually in a surface condenser using cooling water. In well-designed and maintained condensers, the pressure of the vapor 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 and is heated to the saturation temperature. Further addition of energy causes evaporation of the liquid until it is fully converted to saturated steam.
Equations:
- Work done on the pump, per kg of water, WP= h2-h1
- Energy added in the steam generator, q1= h3-h2
- Work delivered by the turbine, WT= h3-h4
- Energy rejected in the condenser, q2= h4-h1
- The thermal efficiency of the Rankine cycle is given by,

- The efficiency of power cycles is defined as,
- Values of heat and work can be determined by applying the First Law of Thermodynamics to each step. The steam quality x at the turbine outlet is determined from the assumption of isentropic expansion, i.e., where Sv is the entropy of vapor and Sl is the entropy of liquid.
CODE:
clear all
close all
clc
fprintf('1-2 Const pressure Heat Addition\n2-3 Isentropic Expansion\n3-4 Const pressure Heat Rejection\n4-1 Isentropic Compression\n \n')
% Inputs
p1 = input('Enter the Pressure at the Turbine Inlet (in bar):');
T1 = input('Enter the Temperature at the Turbineinlet (in Degree Celcius):');
p2 = input('Enter the Pressure at the Condensor (in bar):');
% state point 1
h1 = XSteam('h_pt',p1,T1);
s1 = XSteam('s_pt',p1,T1);
% 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);
s2 = sg2;
h2 = hg2;
T2=XSteam('T_hs',h2,s2);
% state point 3
T3=T2;
p3= p2;
s3=XSteam('sL_T',T3);
h3=XSteam('hL_T',T3);
v3 = XSteam('vL_p',p2);
% state point 4
p4 =p1;
s4= s3;
Cp4 = XSteam('Cp_ps',p4,s4);
Cv4 = XSteam('Cv_ps',p4,s4);
gamma = Cp4/Cv4;
r = (gamma - 1)/gamma;
T4 = T3 *(p4/p3)^r;
% state point 5
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);
Wt = h1-h2; % Turbine Work
Wp = v3*(p1-p2)*100; % Pump Work
h4 = Wp + h3;
W_net = Wt-Wp; % Net Work unit in kj/kg
Qs = h1 - h4; % heat suppied
N_per = (W_net/Qs)*100; % Efficiency
steam_rate = 3600/(Wt - Wp); % Steam rate per second
back_work_ratio=Wp/Wt; % Back work ratio =(work done by pump)/(work done by turbine)
% plot T-S Diagram
subplot(1,2,1)
T_rankine = linspace(T5,T1,5000);
for i = 1:length(T_rankine)
s_rankine(i) = XSteam('s_pT',p1,T_rankine(i));
end
plot([s1 s2 s3 s4 s5 s6 s_rankine],[T1 T2 T3 T4 T5 T6 T_rankine],'linewidth',1.5);
hold on
T_curve = linspace(1,400,500);
for i=1:length(T_curve)
s_l(i) = XSteam('sL_T',T_curve(i));
s_v(i) = XSteam('sV_T',T_curve(i));
h_l(i) = XSteam('hL_T',T_curve(i));
h_v(i) = XSteam('hV_T',T_curve(i));
end
plot(s_l,T_curve);
plot(s_v,T_curve);
text(s1,T1,'1','FontSize',15)
text(s2,T2,'2','FontSize',15)
text(s3,T3,'3','FontSize',15,'HorizontalAlignment','right','VerticalAlignment','top')
text(s4,T4,'4','FontSize',15,'HorizontalAlignment','right','VerticalAlignment','bottom')
text(s5,T5,'5','FontSize',15)
text(s6,T6,'6','FontSize',15)
xlabel('Entropy in kJ/KgK');
ylabel('Temperature in Degree Celcius');
% plot H-S diagram
subplot(1,2,2)
plot([s1 s2 s3 s4 s1],[h1 h2 h3 h4 h1],'linewidth',2)
hold on
plot(s_v,h_v,'color','r')
plot(s_l,h_l,'color','r')
text(s1,h1,'1','FontSize',15)
text(s2,h2,'2','FontSize',15)
text(s3,h3,'3','FontSize',15,'HorizontalAlignment','right','VerticalAlignment','top')
text(s4,h4,'4','FontSize',15,'HorizontalAlignment','right','VerticalAlignment','bottom')
xlabel('Entropy in kJ/KgK')
ylabel('Enthalpy in kJ/kg')
fprintf('\n------------------RESULT------------------\n')
fprintf('At State point 1:\nP1 is : %4.2f Bar\nT1 is : %4.2f Degree Celcius\nH1 is : %4.2f kJ/kg\nS1 is :%4.2f kJ/kgk\n\n',p1,T1,h1,s1)
fprintf('At State point 2:\nP2 is : %4.2f Bar\nT2 is : %4.2f Degree Celcius\nH2 is : %4.2f kJ/kg\nS2 is :%4.2f kJ/kgk\n\n',p2,T2,h2,s2)
fprintf('At State point 3:\nP3 is : %4.2f Bar\nT3 is : %4.2f Degree Celcius\nH3 is : %4.2f kJ/kg\nS3 is :%4.2f kJ/kgk\n\n',p3,T3,h3,s3)
fprintf('At State point 4:\nP4 is : %4.2f Bar\nT4 is : %4.2f Degree Celcius\nH4 is : %4.2f kJ/kg\nS4 is :%4.2f kJ/kgk\n\n',p4,T4,h4,s4)
fprintf('Wt is :%4.2f kJ/kg\nWp is : %4.2f kJ/kg\nWnet is : %4.2f kJ/kg\nNtherm is : %4.2f percent\nS.S.C is :%4.2f kg/kWh\n',Wt,Wp,W_net,N_per,steam_rate)
fprintf('\nNet work output is :%4.2f kJ/kg\nback work ratio is : %4.2f \n',W_net,back_work_ratio);
EXPLANATION:
- At first, input function is used to get user inputs for the inlet temperature, pressure, and outlet pressure of the turbine.
- The inlet temperature and pressure of the turbine are used to find the enthalpy and entropy value of water(steam) at state point 1 from the Xstream library.
- The outlet pressure at the turbine is used to find the enthalpy and entropy value of water at state point 2 from the Xstream library.
- Similarly, the values of enthalpy, entropy, and Cp are obtained from the Xstream library for state points 3 and 4.
- The entropy vs temperature and entropy vs enthalpy graphs are plotted along with numbers to indicate the state points.
- Then the results of the calculation for each process are printed out as their output using fprintf function.
OUTPUT:


RESULTS: Using Matlab the Rankine cycle is simulated and the graphs for entropy vs temperature and entropy vs enthalpy are plotted for the given input values.
REFERENCES: