In [3]:

```
#example 1
#calculating height
m=1100 #mass of car in kg
ke=400 #kinetic energy of car in kJ
V=(2*ke*1000/m)**0.5 #velocity of car in m/s
g=9.807 #acc. due to gravity in m/s^2
H=ke*1000/(m*g) #height to which the car should be lifted so that its potential energy equals its kinetic energy
print"hence,the car should be raised to a height is",round(H,1),"m"
```

In [2]:

```
#example 1E
#calculating height
m=2400 #mass of car in lbm
ke=400 #kinetic energy of car in Btu
V=(2*ke*778.17*32.174/m)**0.5 #velocity of car in ft/s
g=32.174 #acc. due to gravity in ft/s^2
H=ke*778.17*32.174/(m*g) #height to which the car should be lifted so that its potential energy equals its kinetic energy
print"hence,the car should be raised to a height is",round(H,1),"ft"
```

In [5]:

```
#example 2
#change in internal energy
W=-5090 #work input to paddle wheel in kJ
Q=-1500 #heat transfer from tank in kJ
dU=Q-W #change in internal energy in kJ
print"hence,change in internal energy is",round(dU),"kj"
```

In [7]:

```
#example 3
#analysis of energy transfer
g=9.806 #acceleration due to gravity in m/s^2
m=10 #mass of stone in kg
H1=10.2 #initial height of stone above water in metres
H2=0 #final height in metres
dKE1=-m*g*(H2-H1) #change in kinetic energy when stone enters state 2 in J
dPE1=-1 #change in potential energy when stone enters state 2 in J
print"\n hence,when stone is ",round(dKE1),"J"
print"\n and change in potential energy is ",round(dPE1),"J"
dPE2=0 #change in potential energy when stone enters state 3 in JQ2=0 //no heat transfer when stone enters state 3 in J
W2=0 #no work done when stone enters state 3 in J
dKE2=-1 #change in kinetic energy when stone enters state 3
dU2=-dKE2 #change in internal energy when stone enters state 3 in J
print"\n hence,when stone has just come to rest in the bucket is ",round(dKE2),"J"
print"\n and dU is",round(dU2),"J"
dKE3=0 #change in kinetic energy when stone enters state 4
dPE=0 #change in potential energy when stone enters state 4 in J
W3=0 #no work done when stone enters state 4 in J
dU3=-1 #change in internal energy when stone enters state 4 in J
Q3=dU3 #heat transfer when stone enters state 4 in J
print"\n hence,when stone has entered state 4 is",round(dU3),"J"
print"\n and Q3 is ",round(Q3),"J"
```

In [12]:

```
#example 4
#Determinig the missing properties
T1=300 #given temp. in Celsius
u1=2780 #given specific internal enrgy in kJ/kg
print"From steam table, at T=300 C,ug=2563.0 kJ/kg.So,u1>ug ,it means the state is in the superheated vapor region.So, by interplotation,we find P=1648 kPa and v=0.1542 m^3/kg" #hiven pressure in kPa
u2=2000 #given specific intrernal energy in kJ/kg
print"at P=2000 kPa"
uf=906.4 #in kJ/kg
ug=2600.3 #in kJ/kg
x2=(u2-906.4)/(ug-uf)
print"Also, under the given conditions"
vf=0.001177 #in m^3/kg
vg=0.099627 #in m^3/kg
v2=vf+x2*(vg-vf)#Specific volume for water in m^3/kg
print"\n hence,specific volume for water is ",round(v2,5),"m^3/kg"
print"\n Therefore ,this state is ",round(x2,4),"N"
```

In [36]:

```
#example 5
#calculating heat transfer for the given process
Vliq=0.05 #volume of saturated liquid in m^3
vf=0.001043 #in m^3/kg
Vvap=4.95 #volume of saturated water vapour in m^3
vg=1.6940 #in m^3/kg
m1liq=Vliq/vf #mass of liquid in kg
m1liq=round(m1liq,2)
m1vap=Vvap/vg #mass of vapors in kg
m1vap=round(m1vap,2)
u1liq=417.36 #specific internal energy of liquid in kJ/kg
u1vap=2506.1 #specific internal energy of vapors in kJ/kg
U1=m1liq*u1liq + m1vap*u1vap #total internal energy in kJ
m=m1liq+m1vap #total mass in kg
V=5.0 #total volume in m^3
v2=V/m #final specific volume in m^3/kg
print"by interplotation we find that for steam, if vg=0.09831 m^3/kg then pressure is 2.03 Mpa"
u2=2600.5 #specific internal energy at final state in kJ/kg
U2=m*u2 #internal energy at final state in kJ
Q=U2-U1 #heat transfer for the process in kJ
print"\n hence,heat transfer for the process is",round(Q),"kJ"
```

In [23]:

```
#example 5E
#calculating heat transfer for the given process
Vliq=1 #volume of saturated liquid in ft^3
vf=0.01672 #in ft^3/lbm
Vvap=99 #volume of saturated water vapour in m^3
vg=26.80 #in ft^3/lbm
m1liq=Vliq/vf #mass of liquid in lbm
m1liq=round(m1liq,2)
m1vap=Vvap/vg #mass of vapors in lbm
m1vap=round(m1vap,2)
u1liq=180.1 #specific internal energy of liquid in Btu/lbm
u1vap=1077.6 #specific internal energy of vapors in Btu/lbm
U1=m1liq*u1liq + m1vap*u1vap #total internal energy in Btu
U1=round(U1)
m=m1liq+m1vap #total mass in lbm
V=100.0 #total volume in ft^3
v2=V/m #final specific volume in ft^3/lbm
print"by interplotation we find that for steam, if vg=1.575 ft^3/lbm then pressure is 294 lbf/in^2"
u2=1117.0 #specific internal energy at final state in Btu/lbm
U2=m*u2 #internal energy at final state in Btu
U2=round(U2)
Q=U2-U1 #heat transfer for the process in Btu
print"\n hence,heat transfer for the process is",round(Q),"Btu"
```

In [1]:

```
#example 6
#calculating work and heat transfer for the process
V1=0.1 #volume of cylinder in m^3
m=0.5 #mass of steam in kg
v1=V1/m #specific volume of steam in m^3/kg
vf=0.001084 #m^3/kg
vfg=0.4614 #m^3/kg
x1=(v1-vf)/vfg #quality
hf=604.74 #kJ/kg
hfg=2133.8#kJ/kg
h2=3066.8 #final specific heat enthalpy in kJ/kg
h1=hf+x1*hfg #initial specific enthalpy in kJ/kg
Q=m*(h2-h1) #heat transfer for this process in kJ
P=400 #pressure inside cylinder in kPa
v2=0.6548 #specific enthalpy in m^3/kg
W=m*P*(v2-v1) #work done for the process in kJ
print"\n hence, work done for the process is",round(W),"kJ"
print"\n and heat transfer is ",round(Q,1),"kJ"
```

In [18]:

```
# example 7
#calculating work and heat transfer for the process
V1=0.010 #volume of cylinder in m^3
V2=0.040 # m^3
P1=573 #kPa
v1=0.03606 #specific volume of steam in m^3/kg
u1=389.2 #kJ/kg
m=V1/v1#mass of steam in kg
v2=v1*(V2/V1)
P2=163 #kPa
u2=395.8 # kJ/kg
W=8 # kJ
Q2=m*(u2-u1)+W
u3=383.4#kJ/kg
W2=m*(u1-u3)#kJ
print"\n and heat transfer is ",round(Q2,2),"kJ"
print"\n hence, work done for the process is",round(W2,1),"kJ"
```

In [4]:

```
#example 8
#calculating change in enthalpy
import math
h1=273.2 #specific heat enthalpy for oxygen at 300 K
h2=1540.2 #specific heat enthalpy for oxygen at 1500 K
T1=300 #initial temperature in K
T2=1500 #final temparature in K
dh1=h2-h1 #this change in specific heat enthalpy is calculated using ideal gas tables
dh3=0.922*(T2-T1) #it is claculated if we assume specific heat enthalpy to be constant and uses its value at 300K
dh4=1.0767*(T2-T1) #it is claculated if we assume specific heat enthalpy to be constant and uses its value at 900K i.e mean of initial and final temperature
print"\n Hence,change in specific heat enthalpy if ideal gas tables are used is ",round(dh1,1),"kJ/kg"
print"\n if specific heat is assumed to be constant and using its value at T1 is",round(dh3,1),"kJ/kg"
print"\n if specific heat is assumed to be constant at its value at (T1+T2)/2 is",round(dh4,1),"kJ/kg"
```

In [43]:

```
#example 9
#determining amount of heat transfer
P=150 #pressure of nitrogen in cylinder in kPa
V=0.1 #initial volume of cylinder in m^3
T1=25 #initial temperature of nitrogen in celsius
T2=150 #final tempareture of nitrogen in celsius
R=0.2968 #in kJ/kg-K
m=P*V/(R*(T1+273)) #mass of nitrogen in kg
Cv=0.745 #constant volume specific heat for nitrogen in kJ/kg-K
W=-20 #work done on nitrogen gas in kJ
Q=m*Cv*(T2-T1)+W #heat transfer during the process in kJ
print"\n hence,the heat transfer for the above process is",round(Q,1),"kJ"
```

In [31]:

```
#example 9E
#determining amount of heat transfer
P=20 #pressure of nitrogen in cylinder in lbf/in^2
V=2 #initial volume of cylinder in ft^3
T1=80 #initial temperature of nitrogen in F
T2=300 #final tempareture of nitrogen in F
R=55.15 #in ft*lbf/lbm-R
m=P*V*144/(R*(540)) #mass of nitrogen in lbm
Cv=0.177 #constant volume specific heat for nitrogen in Btu/lbm-R
W=-9.15 #work done on nitrogen gas in Btu
Q=m*Cv*(T2-T1)+W #heat transfer during the process in Btu
print"\n hence,the heat transfer for the above process is",round(Q,2),"Btu"
```

In [45]:

```
#example 10
#calculating rate of increase of internal energy
W=-12.8*20 #power consumed in J/s
Q=-10 #heat transfer rate from battery in J/s
r=Q-W #rate of increase of internal energy
print"\n hence,the rate of increase of internal energy is",round(r),"J/s"
```

In [49]:

```
#example 11
#rate of change of temperature
Q=1500.0 #power produced by burning wood in J/s
mair=1 #mass of air in kg
mwood=5 #mass of soft pine wood in kg
miron=25 #mass of cast iron in kg
Cvair=0.717 #constant volume specific heat for air in kJ/kg
Cwood=1.38 #constant volume specific heat for wood in kJ/kg
Ciron=0.42 #constant volume specific heat for iron in kJ/kg
dT=75-20 #increase in temperature in Celsius
T=(Q/1000)/(mair*Cvair+mwood*Cwood+miron*Ciron) #rate of change of temperature in K/s
dt=(dT/T)/60 #in minutes
print" hence,the rate of change of temperature is",round(T,4),"k/s"
print" and time taken to reach a temperature of T is",round(dt),"min"
```