temp=input('Enter the Turbine inlet Temperature in degree celcius:\n');
press=input('Enter the Turbine inlet Pressure in bars:\n');
press_out=input('Enter the Turbine outlet Pressure in bars:\n');
p1=press;
p2=press_out;
t1=temp;
p4=p1;
p3=p2;
% p1=30;
% p2=0.05;
% p3=p2;
% p4=p1;
% t1=400;
%state point1
h1=XSteam('h_pt',30,400);
s1=XSteam('s_pT',30,400);
v1=XSteam('v_pT',30,400);
hf2=XSteam('hL_p',0.05);
hfg2=XSteam('hV_p',0.05);
sf2=XSteam('sL_p',0.05);
sfg2=XSteam('sV_p',0.05);
% To calculate dryness fraction
% s1=sf2+X2*sfg2
% s1-sf2=X2*sfg2
X2=(s1-sf2)/sfg2;
%state point 2
h2=hf2+X2*hfg2;
%state pont 3
h3=hf2;
s2=s1;
s3=sf2;
v3=XSteam('vL_p',0.05);
% v3*(p1-p2)=h4-h3
% state point 4
h4=v3*(p1-p2)+h3;
s4=s3;
v4=XSteam('vL_p',30);
WT=h1-h2;
WC=h3-h4;
qin=h1-h4;
qout=h2-h3;
wnet=WT-WC;
eff=wnet/qin;
Back_work_ratio=h3-h4/h1-h2;
v2=XSteam('vV_p',0.05);
%plotting
figure(1)
plot(s1,h1,'*','color','r')
hold on
plot(s2,h2,'*','color','g')
hold on
plot([s1 s2],[h1 h2],'linewidth',4,'color','c')
plot(s3,h3,'*','color','y')
plot([s2 s3],[h2 h3],'linewidth',4,'color','c')
hold on
plot(s4,h4,'*','color','b')
plot([s1 s4],[h1 h4],'linewidth',4,'color','c')
xlabel('Entropy')
ylabel('Enthalpy')
title('Entropy vs Enthaply')
t=linspace(1,500,100);
for i=1:length(t);
enthalpy(i)=XSteam('hL_T',t(i));
enthalpy_vap(i)=XSteam('hV_T',t(i));
end
for j=1:length(t);
entropy(j)=XSteam('sL_T',t(j));
entropy_vap(j)=XSteam('sV_T',t(j));
end
plot(entropy,enthalpy,'linewidth',4,'color','r')
hold on
plot(entropy_vap,enthalpy_vap,'linewidth',4,'color','r')
% Temperature calculations
gamma=1.4;
% state point 1
t2=t1*(p2/p1)^((gamma-1)/gamma);
v3=v2;
t3=t2*v3/v2;
t4=t3*(p4/v3)^((gamma-1)/gamma);
sa=XSteam('sL_p',30);
ta=XSteam('T_ps',30,sa);
sb=XSteam('sV_p',30);
tb=XSteam('T_ps',30,sb);
figure(2)
plot(s1,t1,'*','color','r')
hold on
plot(s2,t2,'*','color','b')
hold on
plot([s1 s2],[t1 t2],'linewidth',4,'color','c')
plot(s3,t3,'*','color','c')
hold on
plot([s2 s3],[t2 t3],'linewidth',4,'color','c')
plot(s4,t4,'*','color','k')
hold on
plot(sa,ta,'*','color','g')
hold on
plot(sb,tb,'*','color','g')
plot([s3 s4],[t3 t4],'linewidth',4,'color','c')
hold on
plot([s4 sa],[t4 ta],'linewidth',3,'color','c')
hold on
plot([sa sb],[ta tb],'linewidth',3,'color','c')
hold on
plot([sb s1],[tb t1],'linewidth',3,'color','c')
xlabel('Entropy')
ylabel('Temperature')
title('T-S diagram')
T=linspace(50,500,100);
for i=1:length(T);
s_liquid(i)=XSteam('sL_T',T(i));
s_vapour(i)=XSteam('sV_T',T(i));
end
plot(s_liquid,T,'linewidth',4,'color','r')
hold on
plot(s_vapour,T,'linewidth',4,'color','r')
% printing output
fprintf('RANKINE CYCLE SIMULATOR\n')
fprintf('At state point 1:\n')
fprintf('p1: is %d \n',p1)
fprintf('T1: is %d\n',t1)
fprintf('H1: is %d\n',h1)
fprintf('S1: is %d\n' ,s1)
fprintf('At state point 2:\n')
fprintf('p1: is %d \n',p2)
fprintf('T1: is %d\n',t2)
fprintf('H1: is %d\n',h2)
fprintf('S1: is %d\n' ,s2)
fprintf('At state point 3:\n')
fprintf('p1: is %d \n',p3)
fprintf('T1: is %d\n',t3)
fprintf('H1: is %d\n',h3)
fprintf('S1: is %d\n' ,s3)
fprintf('At state point 4:\n')
fprintf('p1: is %d \n',p4)
fprintf('T1: is %d\n',t4)
fprintf('H1: is %d\n',h4)
fprintf('S1: is %d\n' ,s4)
fprintf('The efficiency of this cycle is: %f\n',eff)
fprintf('The net work done by this cycle is :%d\n',wnet)
fprintf('The Back work ratio of this cycle is:%d\n',Back_work_ratio)