Project 2 - Rankine cycle Simulator
%rankine cycle
close all
clear all
clc
fprintf('rankine cycle \n');
fprintf('1-2 isentropic expanshion \n');
fprintf('2-3 constant pressure heat rejection \n');
fprintf('3-4 isentropic compression \n');
fprintf('4-1 constant pressure heat absorption \n');
%user input
P1=input('pressure at inlet of turbine(in bars): \n');
T1=input('temperature at inlet of turbine(in k): \n');
P2=input('pressure at outlet of turbine (in bars): \n');
%state 1
H1=XSteam('h_pT',P1,T1);
S1=XSteam('s_pT',P1,T1);
Hf1=XSteam('hL_p',P1);
Hg1=XSteam('hV_p',P1);
Ts1=XSteam('Tsat_p',P1);
Sf1=XSteam('sL_p',P1);
Sg1=XSteam('sV_p',P1);
%state 2
S2=S1
Hf2=XSteam('hL_p',P2);
Hg2=XSteam('hV_p',P2);
Ts2=XSteam('Tsat_p',P2);
Sf2=XSteam('sL_p',P2);
Sg2=XSteam('sV_p',P2);
Hfg2=Hg2-Hf2;
Sfg2=Sg2-Sf2;
x=(S2-Sf2)/Sfg2;
H2=Hf2+(x*Hfg2);
T2=XSteam('T_ph',P2,H2);
% state 3
H3 = Hf2;
S3 = Sf2;
T3 = T2;
P3 = P2;
% state 4
P4 = P1;
S4 = S3;
H4 = XSteam('h_ps',P4,S4);
T4 = XSteam('T_ps',P4,S4);
t=linspace(0,374,500);
%plotting t-s
hold on
for i=1:length(t)
plot(XSteam('sL_T',t(i)),t(i),'.','color','b')
plot(XSteam('sV_T',t(i)),t(i),'.','color','b')
end
% Plot Cycle
plot([S1 S2],[T1 T2],'linewidth',2,'color','r')
if x>1
T3 = Ts2;
plot([S2 Sg2 S3 S4],[T2 Ts2 T3 T4],'linewidth',2,'color','r')
T2 = Ts2;
else
plot([S2 S3 S4],[T2 T3 T4],'linewidth',2,'color','r')
end
l = linspace(T1,T2,1000);
for i = 1 : length(l)
plot(XSteam('s_pT',P1,l(i)),l(i),'.','color','r')
end
plot([Sf1 Sg1],[Ts1 Ts1],'linewidth',2,'color','r')
xlabel('Entropy[KJ/Kg-K]')
ylabel('Temprature[K]')
title('T-S Diagram')
% Plot H-S Diagram
figure(2)
hold on
% Plot Saturation Curve
for i = 1 : length(t)
plot(XSteam('sL_T',t(i)),XSteam('hL_T',t(i)),'.','color','b')
plot(XSteam('sV_T',t(i)),XSteam('hV_T',t(i)),'.','color','b')
end
% Plot Cycle
plot([S1 S2 S3 S4 S1],[H1 H2 H3 H4 H1],'linewidth',2,'color','r')
xlabel('Entropy[KJ/Kg-K]')
ylabel('Enthalpy[KJ/Kg]')
title('H-S Diagram')
Wt = H1-H2;
Wp = H4-H3;
Qin = H1-H4;
Qout = H2-H3;
Wnet = Wt-Wp;
Ntherm = (Wnet/Qin)*100;
SSC = 3600/Wnet;
BWR = Wp/Wt;
% Print Results
fprintf('\n Results \n')
fprintf('At State Point 1: \n')
fprintf('P1 is : %.2f barn',P1)
fprintf('T1 is : %.2f Deg Celcius \n',T1)
fprintf('H1 is : %.2f KJ/Kg \n',H1)
fprintf('S1 is : %.2f KJ/Kg-K \n',S1)
fprintf('\n At State Point 2:n')
fprintf('P2 is : %.2f barn',P2)
fprintf('T2 is : %.2f Deg Celciusn',T2)
fprintf('H2 is : %.2f KJ/Kgn',H2)
fprintf('S2 is : %.2f KJ/Kg-Kn',S2)
fprintf('\n At State Point 3: \n')
fprintf('P3 is : %.2f bar \n',P3)
fprintf('T3 is : %.2f Deg Celcius \n',T3)
fprintf('H3 is : %.2f KJ/Kg \n',H3)
fprintf('S3 is : %.2f KJ/Kg-K \n',S3)
fprintf('\n At State Point 4: \n')
fprintf('P4 is : %.2f bar \n',P4)
fprintf('T4 is : %.2f Deg Celcius\n',T4)
fprintf('H4 is : %.2f KJ/Kg\n',H4)
fprintf('S4 is : %.2f KJ/Kg-K\n',S4)
fprintf('\n Wt is : %.2f KJ/Kg\n',Wt)
fprintf('Wp is : %.2f KJ/Kg\n',Wp)
fprintf('Wnet is : %.2f KJ/Kg\n',Wnet)
fprintf('Thermal Efficiency is : %.2f percent\n',Ntherm)
fprintf('S.S.C. is : %.2f Kg/KWh\n',SSC)
fprintf('Back Work Ratio is : %.3f \n',BWR)
plots:-
temperatute vs entropy graph
enthalpy vs entropy graph
command window screenshot
explanation of code:-
1) first starting code with clear all,close all,clc which helps us to clear all values of work space nd closing all previous plots
2) assigning values for p1,t1,p2 by using input function
3)making code for remaning terms such as H1,S1 etc...... from XSteam.m file
4)temperature spacing is done using 'linspace' command
5)plot T vs S
6)plot H vs S
7)calculate work done, effeciency,ratio etc...
8) finally print results using 'fprintf'