In [3]:

```
# initialization of variables
Th=200+273.0 # higher temperture in kelvin
Tl=20+273.0 # lower temperture in kelvin
Wdot=15 # output of engine in kW
ef=1-(Tl/Th) # carnot efficiency
Qhdot=Wdot/ef # heat supplied by reservoir
print " The heat suppled by higher temperature reservoir is",round(Qhdot,2),"kW \n "
# using forst law
Qldot=Qhdot-Wdot # heat rejected to reservoir
print " The heat suppled by lower temperature reservoir is",round(Qldot,2),"kW"
```

In [7]:

```
# initialization of variables
TL1=-5+273.0 # lower temperature in kelvin for first situation
TH=20+273.0 # higher temperature in kelvin
TL2=-25+273.0 #lower temperature in kelvin for second situation
#solution
COP1=TL1/(TH-TL1) # carnot refrigerator COP for first situation
# Let Heat be 100 kJ
QL=100.0 # assumption
W1=QL/COP1 # work done for situation 1
# for situation 2
COP2=TL2/(TH-TL2) # COP carnot for second situation
W2=QL/COP2 # work done
Per=(W2-W1)*100/W1 # percentage increase in work done
#result
print" The perccentage increase in work is ",round(Per,1),"%"
```

In [15]:

```
import math
# initialization of variables
T1=20+273 # initial temperature in kelvin
P=200 # pressure in kPa
V=2 # volume in m^3
R=0.287 # gas constant for air
W=720 # work done on air in kJ
Cv=0.717 # specific heat at constant volume for air
#solution
m=(P*V)/(R*T1) # mass of air
T2=T1+(W/(m*Cv))# final temperature in kelvin
delS=m*Cv*math.log(T2/T1) # ENROPY CHANGE FOR CONSTANT VOLUME PROCESS
print " The Entropy increase is",round(delS,3),"kJ/K "
```

In [18]:

```
# initialization of variables
T1=350+273 # initial temperature in kelvin
P1=1200.0 # initial pressure in kPa
P2=140 # final pressure in kPa
k=1.4 # polytopic index for air
Cv=0.717 # specific heat at constant volume for air
#solution
T2=T1*((P2/P1)**((k-1)/k)) # reversible adiabatic process relation
w=-Cv*(T2-T1) # work done by gases in reversible adiabatic process
print" The work done by gases is",round(w),"kJ/kg"
```

In [22]:

```
import math
# initialization of variables
T1=20+273.0 # initial temperature in kelvin
P1=200.0 # pressure in kPa
V=2 #volume in m^3
R=0.287 # gas constant for air
W=-720 # negative as work is done on air in kJ
#solution
m=(P1*V)/(R*T1)# mass of air
u1=209.1 #specific internal energy of air at 293K and 200 kPa from table E.1
s1=1.678 # by interpolation from table E.1
# change in internal energy= work done
u2=-(W/m)+u1 # final internal energy
T2=501.2# final temperature interpolated from table E.1 corresponding to value of u2
s2=2.222 # value of s from table E.3 by interpolating from corresponding to value of u2
P2=P1*(T2/T1) # final pressure in kPa
delS=m*(s2-s1-R*math.log(P2/P1))# entropy change
# result
print " The Entropy increase is",round(delS,3),"kJ/K "
```

In [33]:

```
# initialization of variables
T1=350+273.0 # initial temperature in kelvin
P1=1200.0 # initial pressure in kPa
P2=140.0 # final pressure in kPa
k=1.4 # polytopic index for air
#solution
# The values are taken from table E.1
Pr660=23.13# relative pressure @ 660K
Pr620=18.36# relative pressure @ 620K
Pr1=((Pr660-Pr620)*3/40)+Pr620 # relative pressure by interpolation
Pr2=Pr1*(P2/P1) # relative pressure at state 2
Pr340=2.149 # relative pressure @ 340K
Pr380=3.176 # relative pressure @ 380K
T2=((Pr2-Pr340)/(Pr380-Pr340))*40+340 # interpolating final temperature from table E.1
# now interpolating u1 AND u2 from table E.1
u620=451.0# specific internal energy @ 620k
u660=481.0# specific internal energy @ 660k
u1=(u660-u620)*(3/40.0)+u620 # initial internal energy
u380=271.7 #specific internal energy @ 380k
u340=242.8 #specific internal energy @ 340k
u2=((Pr2-Pr340)/(Pr380-Pr340))*(u380-u340)+u340 # final internal energy
w=u2-u1 # work= change in internal energy
print " The work done by gas is",int(w),"kJ/kg"
# The answer is slightly different as values are approximated in textbook
```

In [37]:

```
# initialization of variables
T1=300+273.0 # initial temperature in kelvin
P1=600 # initial pressure in kPa
P2=40 # final pressure in kPa
#solution
#please refer to steam table for values
v1=0.4344 # specific volume from steam table @ 573k and 600 kPa
v2=v1 # rigid container
u1=2801.0 # specific internal energy from steam table @ 573k and 600 kPa
s1=7.372 # specific entropy @ 600 kPa and 573 K
vg2=0.4625 # specific volume of saturated vapour @ 40 kPa and 573 K
vf2=0.0011 # specific volume of saturated liquid @ 40 kPa and 573 K
sf2=1.777 # specific entropy of saturated liquid @ 40 kPa and 573 K
sg2=5.1197 # specific entropy of saturated vapour @ 40 kPa and 573 K
x=(v2-vf2)/(vg2-vf2)# quality of steam using pure substance relation
s2=sf2+x*sg2 # overall specific enthalpy at quality 'x'
delS=s2-s1 # entropy change
print" The entropy change is",round(delS,3),"kJ/kg.K \n "
#heat transfer
uf2=604.3 #specific internal energy of saturated liquid @ 40 kPa and 573 K
ug2=1949.3 #specific internal energy of saturated vapour @ 40 kPa and 573 K
u2=uf2+x*ug2 #specific internal energy @ quality x
q=u2-u1 # heat transfer in kJ/kg from first law as W=0
print " The heat transfer is",int(q),"kJ/kg"
# result
# the answers are approximated in textbook but here they are precise thus minute difference is there
```

In [49]:

```
import math
# initialization of variables
v1=0.5 # assumed as air is filled in half of the tank
v2=1.0 # final volume when partition is removed
R=0.287 # gas contant for air
#solution
q=0 # heat transfer is zero
w=0 # work done is zero
# temperatue is constant as no change in internal energy by first law
dels=R*math.log(v2/v1)# change in entropy when temperature is constant
print "The change in specific entropy is",round(dels,3),"kJ/kg.K"
```

In [53]:

```
# initialization of variables
T1=400+273.0 # initial temperature in kelvin
P=600 # pressure in kPa
Tsurr=25+273.0 # surrounding temperature in K
m=2 # mass of steam in kg
#solution
#please refer to steam table for values
s1=7.708 # specific entropy of steam @ 400 degree celsius and 0.6 MPa
s2=1.9316# specific enropy of condensed water @ 25 degree celsius and 0.6 MPa
delSsys=m*(s2-s1) # entropy change in system i.e of steam
h1=3270 # specific enthalpy of steam @ 400 degree celsius and 0.6 MPa
h2=670.6#specific enropy of condensed water @ 25 degree celsius and 0.6 MPa
Q=m*(h1-h2)# heat transfer at constant pressure
delSsurr=Q/Tsurr # entropy change in surroundings
sigma=delSsys+delSsurr # net entropy change
print "The net entropy production is",round(sigma,1),"kJ/K"
```

In [56]:

```
# initialization of variables
T1=600+273 # initial temperature in kelvin
P1=2 # initial pressure in MPa
P2=10 # final pressure in kPa
mdot=2 # mass flow rate in kg/s
#solution
#please refer to steam table for values
h1=3690 # specific enthalpy in kJ/kg @ 2MPa and 600 degree celsius
s1=7.702 #specific entropy in kJ/kg.K @ 2MPa and 600 degree celsius
s2=s1 # Reversible adiabatic process thus entropy is constant
sf2=0.6491 #specific entropy of saturated liquid from steam table @ 10 kPa
sg2=8.151 #specific entropy of saturated vapour from steam table @ 10 kPa
x2=(s2-sf2)/(sg2-sf2) # quality of steam at turbine exit
h2f=191.8 #specific enthalpy of saturated liquid from steam table @ 10 kPa
h2g=2584.8 #specific enthalpy of saturated vapour from steam table @ 10 kPa
h2=h2f+x2*(h2g-h2f) # specific enthalpy @ quality 'x'
WdotT=mdot*(h1-h2)# from work done in adiabatic process
# result
print " The maximum power output is",int(WdotT),"kJ/s"
```

In [59]:

```
# initialization of variables
T1=600+273 # initial temperature in kelvin
P1=2 # initial pressure in MPa
P2=10 # final pressure in kPa
mdot=2 # mass flow rate in kg/s
EffT=0.8 # efficiency of turbine
WdotT=2496 # theoritical power of turbine in kW
#solution
Wdota=EffT*WdotT # actual power output of turbine
h1=3690 # specific enthalpy @ 2MPa and 600 degree celsius
h2=h1-(Wdota/mdot) # final enthalpy from first law of thermodynamics
T2=((h2-2688)/(2783-2688))*(150-100)+100 # by interpolating from steam table @ P2= 10 kPa, h2=2770
s2=8.46 # final specific entropy by interpolation from steam table
print "The temperature by interpolation is",round(T2)," degree celsius \n"
print "The final entropy by interpolation is",round(s2,2),"kJ/kg.K"
# The temperature and entropy are found by interpolation from steam table and cannot be shown here.
```

In [60]:

```
# initialization of variables
T2=250.0 # temperature of steam in degree celsius
mdot2=0.5 # mass flow rate of steam in kg/s
T1=45 # temperature of water in degree celsius
mdot1=4 # mass flow rate of water in kg/s
P=600.0 # pressure in kPa
mdot3=mdot1+mdot2 # by mass balance
h2=2957 # specific enthalpy in kJ/kg of steam @ 600 Kpa from steam table
h1=188.4 # specific enthalpy in kJ/kg of water @ 600 Kpa from steam table
h3=(mdot1*h1+mdot2*h2)/mdot3 # specific enthalpy in kJ/kg at exit
# by interpolation from saturated steam table
T3=(h3-461.3)*10/(503.7-461.3)+110 # temperature of mixture
sf3=1.508 # entropy of saturated liquid in kJ/kg.K at 600Kpa and T3 temperature from steam table
s3=sf3 # by interpolating sf
s2=7.182 # entropy of superheated steam in kJ/kg.K @ 600Kpa from steam table
s1=0.639 # entropy of entering water in kJ/kg.K at T= 45 degree celsius
sigmaprod=mdot3*s3-mdot2*s2-mdot1*s1
# result
print "The rate of entropy production is",round(sigmaprod,3),"kW/K "
```