All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
In this project, I will be writing code in MATLAB to simulate a Rankine Cycle for the given parameters. A Rankine Cycle is an ideal thermodynamic heat cycle where mechanical work is extracted from the working fluid as it passes between a heat source and heat sink. This cycle or its derivatives is used in steam engines…
Dushyanth Srinivasan
updated on 04 Sep 2022
In this project, I will be writing code in MATLAB to simulate a Rankine Cycle for the given parameters.
A Rankine Cycle is an ideal thermodynamic heat cycle where mechanical work is extracted from the working fluid as it passes between a heat source and heat sink. This cycle or its derivatives is used in steam engines and steam-based power plants. This cycle consists of four processes, they are:
Process 1 - 2: Constant Pressure Heat Addition: the fluid is passed through a boiler, where heat is transferred to it. Ideally, this process occurs at constant pressure. The exiting fluid's vapour is dry or superheated. The boiler is the heat source.
Process 2 - 3: Isentropic Expansion: the fluid is passed through a turbine, where mechanical work is extracted from the fluid. Ideally, this process is isentropic.
Process 3 - 4: Constant Pressure Heat Rejection: the fluid is condensed to a saturated liquid through a condenser. Ideally, this process occurs at constant pressure.
Process 4 - 1: Isentropic Compression: the fluid is fed through a pump, where it is compressed. Ideally, this process is isentropic.
There are multiple variations to this closed loop version of the rankine cycle.
From the above assumptions,
From process 1 - 2
p1=p2p1=p2
hfg1=hfg2hfg1=hfg2
x2=1x2=1 (saturated steam)
From process 2 - 3
s2=s3s2=s3
From process 3 - 4
p3=p4p3=p4
h4=hf3h4=hf3
From process 4 - 1
s1=s4s1=s4
Where SS is the specific entropy (J/molJ/mol) at the specified stage, pp is the pressure (PaPa) at the specified stage, hh is the specific enthalpy (J/kgJ/kg) at the specified stage and xx is the dryness factor.
In this project, since it is impractical to calculate these parameters for each timestep using steam tables/mollier chart, an external library henceforth referred to as XSteam will be used.
The library can be found here: https://drive.google.com/open?id=1RK_fvrOj38CIaQvmLT1S3daqHnxKCGU
Code (with explanation)
Functions
constant_pressure_plotter : this function calculates temperature and enthalpy for different entropy values and constant pressure using the xsteam library. The output parameters are entropy, temperature and enthalpy.
filename: constant_pressure_plotter.m
function [t,h,s] = constant_pressure_plotter (s1,s2,p)
% this function calculates t and h for different entropy values and
% constant pressure values using xsteam library
s = linspace (s1,s2,100);
for i=1:length(s)
t(i) = XSteam ('T_ps',p,s(i));
h(i) = XSteam ('h_ps',p,s(i));
end
end
isentropic_plotter : this function calculates temperature and enthalpy for different pressure values and constant entropy using the xsteam library. The output parameters are entropy, temperature and enthalpy.
filename: isentropic_plotter.m
function [t,h,s] = isentropic_plotter (p1,p2,s)
% this function calculates t and h for different pressure values and
% constant entropy values using xsteam library
p = linspace (p1,p2,100);
for i=1:length(p)
t(i) = XSteam ('T_ps',p(i),s);
h(i) = XSteam ('h_ps',p(i),s);
end
s = ones(1,length(p)) .* s;
% converting s into an array to make it easier for plotting
end
Main Program
clear all
close all
clc
% Rankine Cycle
% -> 1 -> boiler -> 2 -> turbine -> 3 -> condenser -> 4 -> pump -> 1 ->
fprintf ('\t\tRANKINE CYCLE - SIMPLE\n\n')
fprintf ('Process 1 - 2: Constant Pressure Heat Addition by Boiler')
fprintf ('\nProcess 2 - 3: Isentropic Expansion in Turbine')
fprintf ('\nProcess 3 - 4: Constant Pressure Heat Rejection by Condenser')
fprintf ('\nProcess 4 - 1: Isentropic Compression in Pump\n\n')
% accepting input data from user
fprintf ('INPUT DATA\n')
p2 = input ('Enter Pressure at turbine inlet (bar): ');
t2 = input ('Enter Temperature at turbine inlet (°C): ');
p3 = input ('Enter Pressure at turbine outlet (bar): ');
% calculating state 2 parameters
% finding enthalpy and entropy at p2 and t2
h2 = XSteam('h_pT',p2,t2);
s2 = XSteam('s_pT',p2,t2);
% calculating state 3 parameters
% finding vapour and liquid enthalpy and entropy at p3
% calculating liquid-vapour enthalpy/entropy using vapour = liquid + liquid-vapour
h3_f = XSteam('hL_p',p3);
h3_fg = XSteam('hV_p',p3) - h3_f;
s3_f = XSteam('sL_p',p3);
s3_fg = XSteam('sV_p',p3) - s3_f;
% we know s3 = s2 (isentropic, and s3 = sf3 + x3 * sfg3
% s3 = sf3 + x3 * sfg3
% x3 = (s3 - sf3)/sfg3
s3 = s2;
x3 = (s3 - s3_f)/s3_fg;
% now we know x3, so we can find h3 = hf3 + x3*hfg3
h3 = h3_f + x3 * h3_fg;
% knowing p3 and h3, we can find t3
t3 = XSteam('T_ph',p3,h3);
% calculating state 4 parameters
p4 = p3; % constant pressure process
s4 = s3_f; % condensation process
h4 = h3_f; % condensation process
% knowing h4 and s4 we can find t4
t4 = XSteam('T_hs',h4,s4);
% calculating state 1 parameters
p1 = p2; % constant pressure process
s1 = s4; % isentropic process
% knowing p1 and s1, we can find h1 and t1
h1 = XSteam('h_ps',p1,s1);
t1 = XSteam('T_ps',p1,s1);
% net work ratio = work done by turbine - work done by pump
% back work ratio = work done by turbine / work done by pump
net_work_done = abs (h3-h2) - abs (h4-h1);
back_work_ratio = (h3-h2)/(h4-h1);
% generating t-s and h-s plots
[t_1_2,h_1_2,s_1_2] = constant_pressure_plotter (s1,s2,p1);
[t_2_3,h_2_3,s_2_3] = isentropic_plotter (p2,p3,s2);
[t_3_4,h_3_4,s_3_4] = constant_pressure_plotter (s3,s4,p3);
[t_4_1,h_4_1,s_4_1] = isentropic_plotter (p4,p1,s4);
% these functions generate values to be plotted
% merging those values for ease of use
t = [t_1_2 t_2_3 t_3_4 t_4_1];
s = [s_1_2 s_2_3 s_3_4 s_4_1];
h = [h_1_2 h_2_3 h_3_4 h_4_1];
% plotting t-s plot
figure (1)
plot (s,t,'LineWidth',1,'Color','b')
hold on
plot (s1,t1,s2,t2,s3,t3,s4,t4,'Color','r','Marker','o')
title ("Temperature vs Entropy for Simple Rankine Cycle")
xlabel ('Entropy (J/(kg.mol))')
ylabel ('Temperature (°C')
% plotting h-s plot
figure (2)
plot (s,h,'LineWidth',1,'Color','b')
hold on
plot (s1,h1,s2,h2,s3,h3,s4,h4,'Color','r','Marker','o')
title ("Enthalpy vs Entropy for Simple Rankine Cycle")
xlabel ('Entropy (J/(kg.mol))')
ylabel ('Enthalpy (J/kg)')
fprintf ('\nOUTPUT DATA\n')
% printing output data
% state 1
fprintf('At State Point 1:\n')
disp(['Temperature (T): ',num2str(t1),'°C'])
disp(['Pressure (P): ',num2str(p1),' bar'])
disp(['Enthapy (H/Q): ',num2str(h1),' J/kg'])
disp(['Entropy (S): ',num2str(s1),' J/(kg.mol)'])
% state 2
fprintf('\nAt State Point 2:\n')
disp(['Temperature (T): ',num2str(t2),'°C'])
disp(['Pressure (P): ',num2str(p2),' bar'])
disp(['Enthapy (H/Q): ',num2str(h2),' J/kg'])
disp(['Entropy (S): ',num2str(s2),' J/(kg.mol)'])
% state 3
fprintf('\nAt State Point 3:\n')
disp(['Temperature (T): ',num2str(t3),'°C'])
disp(['Pressure (P): ',num2str(p3),' bar'])
disp(['Enthapy (H/Q): ',num2str(h3),' J/kg'])
disp(['Entropy (S): ',num2str(s3),' J/(kg.mol)'])
% state 4
fprintf('\nAt State Point 4:\n')
disp(['Temperature (T): ',num2str(t4),'°C'])
disp(['Pressure (P): ',num2str(p4),' bar'])
disp(['Enthapy (H/Q): ',num2str(h4),' J/kg'])
disp(['Entropy (S): ',num2str(s4),' J/(kg.mol)'])
% net work done and back work ratio
fprintf('\nNet Work Done : %5.5f J/kg',net_work_done)
fprintf('\nBack Work Ratio : %5.5f\n',back_work_ratio)
Output
Command Window
Plots Generated
Temperature vs Entropy
Enthalpy vs Entropy
Straight vertical lines indicate constant entropy/isentropic processes, as expected. The temperature graph flatlines after a while, this is due to latent heat of evaporation of water.
Note: it may seem that the two points on the left side of the graph are coincident, but upon zooming in, we can see that they aren't coincident.
This shows the scale at which the turbine produces work and how little work the pump consumes.
Errors Faced during Programming
Steps Taken to fix the error
Instead of passing "s" as a parameter, "s1" was passed.
References
1. Rankine Cycle Gif from https://www.mechanicaltutorial.com/rankine-cycle-efficiency
2. Chapter 7, R. S. Khurmi and J. K. Gupta - A Textbook of Thermal Engineering-S. Chand and Company Limited (2020). ISBN: 978-81-219-2573-0.
3. https://in.mathworks.com/help/matlab/matlab_prog/combine-cell-arrays.html
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 2 - Rankine cycle Simulator
In this project, I will be writing code in MATLAB to simulate a Rankine Cycle for the given parameters. A Rankine Cycle is an ideal thermodynamic heat cycle where mechanical work is extracted from the working fluid as it passes between a heat source and heat sink. This cycle or its derivatives is used in steam engines…
04 Sep 2022 12:52 PM IST
Project 1 - Parsing NASA thermodynamic data
In this project, I will be parsing a data file prepared by NASA. The contents of the data file can be used to generated thermodynamic properties such as Specific Heat at Constant Pressure 'C_p' (J/(kg.K)), Enthalpy HorQ (J) and Entropy S (J/(kg.mol)) at various temperatures. The files will be parsed in MATLAB…
31 Aug 2022 01:07 PM IST
Week 5 - Genetic Algorithm
In this project, I will be generating a stalagmite function in MATLAB and find the global maxima of the function using Genetic Algorithm. A stalagmite function is a function which generates Stalactites, which are named after a natural phenomenon where rocks rise up from the floor of due to accumulation of droppings of…
29 Aug 2022 07:55 AM IST
Week 4.1 - Solving second order ODEs
In this project, I will be writing code in MATLAB to solve the motion of a simple pendulum. A simple pendulum motion's depends on Newton's Second Law. The equation which governs the motion of a simple pendulum is (with damping) d2θdt2+bmdθdt+gLsinθ=0 Where, θ is the angular displacement…
23 Aug 2022 08:06 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.