In [5]:

```
#initialization of variables
K=100 # spring constant in kN/m
d=0.8 # dispacement of spring in m
# to get total work we integrate from 0 to 0.8 displacement
x1=0; # lower limit of integration
x2=0.8; # upper limit of integration
from scipy.integrate import quad
# we find work
def integrand(x,K):
return K*x
W12, err = quad(integrand, x1, x2, K) # integrating to get work
Q12=W12; # by first law of thermodynamics
print "The Heat transfer is ",int(Q12)," J"
```

In [10]:

```
# initialization of variables
P= 5*746 # power of fan converted in watt
t=1*60*60 # time converted to seconds
# by first law of thermodynamics Q=delU + W
# Q=0 hence -W=delU
# first we find work input
W=-P*t # work in J
delU=-W # from 1st law
print "The internal energy increase is ",float(delU)," J"
# The answer is approximated in textbook
# our answer is precise
```

In [17]:

```
# initialization of variables
P=400 # pressure in kPa
T1=200 # initial temperature in degree celsius
V1= 2 # initial volume in m^3
Q=3500 # heat added in kJ
v1=0.5342 # specific volume of steam at 200 degree celcius and 0.4 Mpa pressure from table C.3
u1=2647 # specific internal energy in kJ/kg @ pressure = 0.4 MPa
m=V1/v1 # mass in kg
# we have a relation Between u2 and v2 from 1st law of thermodynamics
v2=1.06 # specific volume at state 2 by trial and error and interpolation
V2=m*v2
u2=((3500-400*(V2-V1))/m)+2647 # specific internal energy for v2=1.06 by trial and error
# on interpolation from steam table at 0.4 MPa we get temperature
T2=644 # temperature in degree celsius
print "The temperature for u2=",round(u2)," kJ and v2 =",round(v2,3)," kg/m^3 is \n ",int(T2)," degree celsius"
# this numerical is solved by trial and error thus refer to Appendix C
```

In [20]:

```
# initialization of variables
P=400 # pressure in kPa
T1=200 # initial tmperature in degree celsius
V=2 # initial volume in m^3
Q=3500 # heat added in kJ
#solution
h1=2860 # initial enthalpy @ 200*C and 400 kPa from steam table
v=0.5342 # specific volume from steam table C.3
m=V/v;
h2=(Q/m)+h1; # final enthalpy in kJ/kg from energy equation
# NOW USING THIS ENTHLAPY AND INTERPOlATING FROM STEAM TABLE
T2=600+(92.6/224)*100
print "The Final temperature is ",int(T2)," degree Celsius"
# result is obtained from interpolation on steam table
```

In [24]:

```
# initialization of variables
T1=300 # initial temperature in degree celsius
T2=700 # final temperature in degree celsius
P=150 # pressure in kPa
m=3 # mass of steam in kg
# solution
# part (a)
from scipy.integrate import quad
# now we make function to integrate
def integrand(T):
return 2.07+(T-400)/1480
I, err = quad(integrand, T1, T2) # integrating specific heat over temperature range
delH=m*I #integrate('2.07+(T-400)/1480','T',T1,T2) # expressing as function of temperature and integrating
print" The change in Enthalpy is ",int(delH)," kJ \n"
# part(b)
CPavg=delH/(m*(T2-T1)) # avg value of specific heat at constant pressure
print " The average value of Cp is ",round(CPavg,2)," kJ/kg.*C"
```

In [29]:

```
m=1 # mass of nitrogen in kg
T1=300 # initial temperature in Kelvin
T2=1200 # final temperature in Kelvin
M=28.0 # in kg/kmol
# part(a)
# the enthalpy change is found from gas table in App.E
delh=36777-8723 # from gas table
delH=delh/M
print " The entalpy change from gas table is ",round(delH)," kJ/kg \n"
# part (b)
Cp=1.042 # from table B.2
delH=Cp*(T2-T1)
print " The entalpy change by assuming constant specific heat is ",round(delH)," kJ/kg"
```

In [34]:

```
# initialization of variables
x=0.7 # quality of steam
P1=200 # initial pressure in kPa
P2=800 # final pressure in kPa
V=2 # volume in m^3
# The values are taken from TABLE C.2
vf1=0.0010 # specific volume of saturated liquid at 200 kPa
vg1=0.8857 # specific volume of saturated gas at 200 kPa
uf1=504.5 # specific internal energy of saturated liquid @ state 1
ug1=2529.5 # speciific internal energy of saturated gas @ state 1
v1=vf1+x*(vg1-vf1); # specific volume of vapour
m=V/v1
u1=uf1+x*(ug1-uf1) # specific internal energy of vapour @ state 1
v2=v1 # constant volume process
u2=((0.6761-0.6203)*(3661-3853)/(0.6761-0.6181))+3853 # from steam table @ 800kPa by interpolating
Q=m*(u2-u1) # heat transfer
print "The heat transfer is ",round(Q,3)," kJ"
# The answer in the textbook is approximated
```

In [37]:

```
# initialization of variables
V=0.02 # volume in m^3
P=400 # pressure in kPa
T1=50+273 # initial temperature in kelvin
T2=700+273 # final temperature in kelvin
Q=50 # heat added in kJ
R=287 # constant for air
Cp=1 # constant for specific heat of air
# using the ideal gas equation
m=P*1000*V/(R*T1) # mass of air in kg
W=Q-(m*Cp*(T2-T1)) # work done from first law
# result
print "The Paddle work is ",round(W,2)," kJ"
```

In [41]:

```
# initialization of variables
V1=2 # initial volume in m^3
V2=0.2 # final volume in m^3
T1=20+273 # temperature in kelvin
P=200 # pressure in kPa
R=0.287 # constant for air
gama=1.4 # polytropic index for air
Cv=0.717 # specific heat at constant volume for air
#solution
#using the ideal gas equation
m=(P*V1)/(R*T1) # mass in kg
# process is adiabatic thus
T2=T1*((V1/V2)**(gama-1)) # final temperature
W=-m*Cv*(T2-T1) # work from first law
print "The Work is ",int(W)," kJ"
# solution is approximated in textbook
```

In [45]:

```
import math
# initialization of variables
P1=2000.0 # initial pressure in kPa
T1=600.0 # initial temperature in degree celsius
p2=600.0 # final pressure in kPa
T2=200.0 # final temperature in degree celsius
d1=0.06 # diameter of inlet pipe in metre
d2=0.120 # diameter of outlet pipe in metre
V1=20.0 # velocity at inlet in m/s
# solution
# from superheat table C.3 values are noted
v1=0.1996 # specific volume of superheated steam @ 600*C and 2000 kPa
v2=0.3520 # specific volume of superheated steam @ 200*C and 2000 kPa
rho1=1/v1 # initial density
rho2=1/v2 # final density
A1=(math.pi*d1**2)/4 # inlet area
A2=(math.pi*d2**2)/4 # exit area
V2=(rho1*A1*V1)/(rho2*A2) # from continuity equation
print " The Exit velocity is ",round(V2,2)," m/s \n"
mdot=rho1*A1*V1 # mass flow rate
print" The mass flow rate is ",round(mdot,3)," kg/s"
```

In [50]:

```
# initialization of variables
P1=8000 # initial pressure in kPa
T1=300 # temperature in degree celsius
P2=2000 # final pressure in kPa
# solution
h1=2785 # specific enthalpy of steam in kJ/kg @ 8000 kPa and 300 degree celsius from steam table
h2=h1 # throttling process thus enthalpy is constant
T2=212.4 # from steam table as we know enthalpy and pressure
hf2=909 # specific enthalpy of saturated liquid @ 2000 kPa and 300 degree celsius
hg2=2799.5 # specific enthalpy of saturated gas @ 2000 kPa and 300 degree celsius
x2=(h2-hf2)/(hg2-hf2) # quality of steam
vg2=0.0992 # specific volume of saturated gas @ 2000 kPa and 212.4*c
vf2=0.0012 # specific volume of saturated liquid @ 2000 kPa and 212.4*c
v2=vf2+x2*(vg2-vf2) # from properties of pure substance
print "The Final Temperature and Specific volume is ",round(T2,1),"*C and ",round(v2,3)," m^3/kg"
```

In [78]:

```
import math
# initialization of variables
P1=4000 # inlet pressure in kPa
T1=500 # inlet temperature in degree celsius
V1=200 # inlet steam velocity in m/s
d1=0.05 # inlet diameter in 'm'
P2=80 # exit pressure in kPa
d2=0.250 # exit diameter in 'm'
# solution
v1=0.08643 # specific volume from steam table @ 4000 kPa and 500*C
v2=2.087 # specific volume from steam table @ 80 kPa and 500*C
rho1=1/v1 # density at inlet
rho2=1/v2 # density at outlet
A1=(math.pi*d1**2)/4 # inlet area
A2=(math.pi*d2**2)/4
mdot=rho1*A1*V1 # mass flow rate
mdot=round(mdot,3) # rounding to 3 significant digits
#now using table C.3
h1=3445 # initial specific enthalpy @ 4000 kPa and 500 *C
h2=2666 # final specific enthalpy @ 80 kPa and 500 *C
WT=-mdot*(h2-h1) # maximum power from first law
print " The power output is ",round(WT)," kJ/s \n "
V2=(A1*V1*rho1)/(A2*rho2)
V2=round(V2) # rounding of digits
delKE=mdot*((V2**2)-(V1**2))/2 # the change in kinetic energy
print " The change in K.E is ",round(delKE)," J/s"
```

In [80]:

```
import math
# initialization of variables
Wdot=10 # pump power in hp
g=9.81 # acceleration due to gravity
rho=1000 # density of water in kg/m^3
d1=0.06 # inlet dimeter in 'm'
d2=0.10 # oulet diamter in 'm'
V1=10 # velocity of water at inlet in m/s
#solution
A1=math.pi*(d1**2)/4 # area of inlet
A2=math.pi*(d2**2)/4 # area of outlet
V2=A1*V1/A2 # oulet velocity from continuity equation
mdot=rho*A1*V1 # mass flow rate
delP=((((Wdot*746)/mdot)-((V2**2)-V1**2)/(2*g))*rho)/1000 # change in pressure in kPa
print "The rise in pressure is ",round(delP)," kPa"
# The answer is approximated in textbook , our answer is precise
```

In [87]:

```
import math
# initialization of variables
P1=7000.0 # inlet pressure in Pa
T1=420.0 # inlet temperature in degree celsius
V1=400.0 # inlet velocity in m/s
d1=0.200 # inlet diameter in 'm'
V2=700.0 # exit velocity in m/s
k=1.4 # polytopic index for air
Cp=1000 # specific heat at constant pressure for air in j/kg.K
R=287 # specific gas constant for air
#solution
#part (a)
T2=(((V1**2)-V2**2)/(2*Cp))+T1 # outlet temperature in degree celsius
print " The exit temperature is ",round(T2)," *C \n"
#part (b)
rho1=P1/(R*(T1+273)) # density at entrance
A1=(math.pi*d1**2)/4
mdot=rho1*A1*V1 #
print " The mass flow rate is ",round(mdot,3)," kg/s \n"
# part (c)
rho2=rho1*(((T2+273)/(T1+273))**(1/(k-1))) # density at exit
# now we find the exit diameter
d2=math.sqrt((rho1*V1*(d1)**2)/(rho2*V2))
print " The outlet diameter is ",round(d2,3)," m"
```

In [90]:

```
# initialization of variables
mdots=100 # mass flow rate of sodium in kg/s
Ts1=450 # inlet temperature of sodium in degree celsius
Ts2=350 # exit temperature of sodium in degree celsius
Cp=1.25 # specific heat of sodium in KJ/kg.*C
Tw1=20 # inlet temperature of water in degree celsius
Pw=5000 # inlet pressure of water in kPa
# solution
hw1=88.65 # enthalpy from table C.4
hw2=2794 # enthalpy from table C.3
mdotw=(mdots*Cp*(Ts1-Ts2))/(hw2-hw1) # mass flow rate of water
print " The mass flow rate of water is ",round(mdotw,2)," kg/s \n"
Qdot=mdotw*(hw2-hw1) # heat transfer in kW using energy equation
# result
print " The rate of heat transfer is ",round(Qdot)," kW"
```