In [1]:

```
#Given
k = 100; # Unit:lbf/in. #k = spring constant
l = 2; #Unit:inch #l = length of compression of string
# Calculations
work = (1./2)*k*l**2; #force-print lacement relation #Unit:in*lbf
# Results
print "Workdone is %.2f inch*lbf"%(work);
```

In [2]:

```
#Given
k = 20*1000; # Unit:N/m #k = 20kN #k = spring constant
l = 0.075; #Unit:meter #l = 75 mm #l = length of compression of string
# Calculations
work = (1./2)*k*l**2; #force-print lacement relation #Unit:N*m
# Results
print "Workdone is %.2f Jule"%(work);
```

In [3]:

```
#Given
Z = 600; #Unit:ft #Z = The dismath.tance,the body is raised from its initial position when the force is applied
gc = 32.174; #Unit: (lbm*ft)/(lbf*s**2) #gc is constant of proportionality
g = gc; #Unit:ft/s**2 #g = The local gravity
m = 1.; #Unit:lbm #m = mass
# Calculations
PE = (m*g*Z)/gc; #potential energy #Unit:ft*lbf
# Results
print "%.2f ft*lbf work is done lifting the water to elevation "%(PE)
```

In [4]:

```
# Given value
m = 1; #Unit:kg #m = mass
g = 9.81 #Unit:m/s**2 #g = The local gravity
Z = 50 #Unit:m # #Z = The dismath.tance,the body is raised from its initial position when the force is applied #In this case Z = delivered water from well to pump
# Calculations
PE = m*g*Z; #PE = Potential Energy #Unit:Joule
# Results
print "Change in potential energy per kg of water is %.2f J "%(PE); #J = Joule = N*m = kg*m**2/s**2
```

In [5]:

```
# Given value
Rho = 62.4; #Unit:lbm/ft**3 #Rho = The density of water
A = 10000; #Flow = 10000; gal/min
V = (231./1728); # 12 inch = 1 ft #So,1 ft**3 = 1728 in**3 # One Gallon is a volumetric measure equal to 231 in**3
#A*V #Unit:ft**3/min
#In example, 2.4:
# From example 2.4
Z = 600; #Unit:ft #Z = The dismath.tance,the body is raised from its initial position when the force is applied
gc = 32.174; #Unit: (lbm*ft)/(lbf*s**2) #gc is constant of proportionality
g = gc; #Unit:ft/s**2 #g = The local gravity
m = 1; #Unit:lbm #m = mass
# Calculations and Results
PE = (m*g*Z)/gc; #potential energy #Unit:ft*lbf
print "%.2f ft*lbf work is done lifting the water to elevation "%(PE);
#So,
# In example 2.5
M = Rho*A*V; #M = the mass flow
Power = M*PE; #Unit:ft*lbf/lbm
print "Generated Power is %.2f ft*lbf/lbm "%(Power);
# 1 horsepower = 33,000 ft*lbf/min
print "Power = %.2f hp"%(Power/33000);
```

In [6]:

```
print "In problem 2.5";
m = 1; #Unit:kg #m = mass
g = 9.81 #Unit:m/s**2 #g = The local gravity
Z = 50 #Unit:m # #Z = The dismath.tance,the body is raised from its initial position when the force is applied #In this case Z = delivered water from well to pump
# Calculations and Results
PE = m*g*Z; #PE = Potential Energy #Unit:Joule
print "Change in potential energy per kg of water is %.2f J "%(PE); #J = Joule = N*m = kg*m**2/s**2
#Given data in problem 2.7 is
M = 1000; #Unit;kg/min #M = Water density
Power = PE*M*(1./60); #1 min = 60 seconds #power #unit:Joule/s = W
print "Power is %.2f Watt"%(Power); #Watt = N*m/s = Joule/s = Watt
#1 Hp = 746 Watt
print "Power is %.2f Horsepower"%(Power/745);
```

In [7]:

```
m = 10.; #Unit:lb #m = Mass
V1 = 88.; #Unit: #ft/s V1 = Velocity before it is slowed down
V2 = 10.; #Unit;ft/s #V2 = Velocity after it is slowed down
gc = 32.174; #Unit: (lbm*ft)/(lbf*s**2) #gc is constant of proportionality
# Calculations and Results
KE1 = m*V1**2/(2*gc); #The kinetic energy of the body before it is slowed down #Unit:ft*lbf
print "The kinetic energy of the body before it is slowed down is %.2f ft*lbf"%(KE1);
KE2 = m*V2**2/(2*gc); #The kinetic energy of the body before it is slowed down #Unit:ft*lbf
print "The kinetic energy of the body before it is slowed down is %.2f ft*lbf"%(KE2);
KE = KE1-KE2; #KE = Change in kinetic energy #Unit:ft*lbf
print "Change in kinetic energy is %.2f ft*lbf"%(KE);
```

In [8]:

```
# Given value
m = 1500.; #Unit:kg #m = mass
V1 = 50.; #Km/hour V1 = Velocity before it is slowed down
#V1 = (50*1000 m/hour)**2/(3600 s/hour)**2
# Calculations
KE1 = (m*(V1*1000)**2/3600**2)/2; #KE1 = Initial kinetic energy #Unit:Joule
#After slowing down
V2 = 30; #Unit:KM/hour #V2 = Velocity after it is slowed down
#V2 = (30*1000 m/hour)**2/(3600 s/hour)**2
KE2 = (m*(V2*1000)**2/3600**2)/2; #KE2 = After slowing down, the kinetic energy #Unit:Joule
KE = KE1-KE2; #KE = Change in kinetic energy #Unit:Joule
# Results
print "Change in kinetic energy is %.2f kJ"%(KE/1000);
```

In [10]:

```
import math
m = 10 #Unit:kg #m = mass
Z = 10 #Unit:m #Z = The dismath.tance,the body is raised from its initial position when the force is applied
g = 9.81 #Unit:m/s**2 #g = The local gravity
#There are no losses in the system
#So,initial potential energy plus initial kinetic energy equal to sum of final potential energy plus final kinetic energy
#So, PE1+KE1 = PE2+KE2
#From the figure,KE1 = 0; PE2 = 0;
#So,PE1 = KE2;
# Calculations and Results
PE1 = m*g*Z; #PE = Potential Energy #Unit:Joule
#KE2 = (m*v**2)/2
v = (PE1*2)/m;
V = math.sqrt(v); #Unit:m/s #velocity
print "Velocity = %.2f m/s"%(V);
KE2 = PE1; #kinetic energy #Unit:Joule
print "Kinetic energy is %.2f N*m"%(PE1);
```

In [11]:

```
p1 = 100.; #pressure at the enmath.tance #Unit:psia,lbf/in**2
Rho1 = 62.4; #Unit:lbm/ft**3 #Rho = The density
v1 = 144.*(1/Rho1) #Specific Volume at entrance or reciprocal of fluid density # 144 in**2 = 1 ft**2
#1 Btu = 778 ft*lbf
J = 778.; #Unit:ft*lbf/Btu #conversion factor
# Calculations and Results
FW1 = (p1*v1)/J; #Flow work #Btu/lbm
print "Flow work = %.2f Btu/lbm"%(FW1);
print "At the exit of device"
p2 = 50.; #pressure at the exit #Unit:psia,lbf/in**2
Rho2 = 30.; #Unit:lbm/ft**3 #Rho = The density
v2 = 144.*(1./Rho2) #Specific Volume at exit or reciprocal of fluid density # 144 in**2 = 1 ft**2
#1 Btu = 778 ft*lbf
J = 778.; #Unit:ft*lbf/Btu #conversion factor
FW2 = (p2*v2)/J; #Flow work #Btu/lbm
print "Flow work = %.2f Btu/lbm"%(FW2);
```

In [12]:

```
print "At the entrance of device"
p1 = 200*1000; #200kPa*1000 Pa/kPa #pressure at the entrance #Unit:N/m**2
Rho1 = 1000; #kg/m**3 #Fluid density at entrance
v1 = 1./Rho1; #Specific Volume at entrance or reciprocal of fluid density
FW1 = p1*v1; #Flow work at entrance #Unit:N*m/kg
print "Flow work = %.2fN*m/kg"%(FW1);
print "At the exit of device"
p2 = 100*1000; #200kPa*1000 Pa/kPa #pressure at the exit #Unit:N/m**2
Rho2 = 250; #kg/m**3 #Fluid density at exit
v2 = 1./Rho2; #Specific Volume at entrance or reciprocal of fluid density
FW2 = p2*v2; #Flow work at exit #Unit:N*m/kg
print "Flow work = %.2f N*m/kg"%(FW2);
```

In [13]:

```
#It is necessary that pressure be expressed as psfa when the volume is in cubic feet
#100 psia = 100*144 psfa
p1 = 100*144; #Unit:psfa #initial pressure
v1 = 2; #Unit:ft**3/lb #Initial Specific Volume
v2 = 1.; #Unit:ft**3/lb #Final Specific Volume
# Calculations
w = p1*v1*math.log(v2/v1); #work done on fluid #Unit:ft*lbf/lbm
# Results
print "Work done on fluid = %.2f ft*lbf/lb"%(w);
#1 Btu = 778 ft*lbf
print "Work done on the fluid per pound of fluid is %.2f Btu/lbm"%(w/778);
```

In [15]:

```
import math
# Given value
#p1*v1 = p2*v2
p1 = 200.*1000; #p1 = Initial Pressure #Unit:Pa
p2 = 800*1000; #p2 = Final Pressure #Unit:Pa
v1 = 0.1; #v1 = Initial Special Volume #Unit:m**3/kg
# Calculations
v2 = (p1/p2)*v1; #v1 = final Special Volume #Unit:m**3/kg
w = p1*v1*math.log(v2/v1); #workdone #Unit:kJ/kg
# Results
print "Work done per kilogram of gas is %.2f kJ/kg into the system)"%(w/1000);
```