In [2]:

```
#given data
t1 = 1000.; #(unit:fahrenheit) #Source temperature
t2 = 80.; #(unit:fahrenheit) #Sink temperature
#solution
#converting temperatures to absolute temperatures;
T1 = t1+460; #Source temperature #Unit:R
T2 = t2+460; #Sink temperature #Unit:R
print "Solution for a";
ans = ((T1-T2)/T1)*100; #(ans in %) #Efficiency of the engine
print "Efficiency of the engine is %.2f percentage"%(ans);
print "Solution for b";
T1 = 2000+460; #Source temperature #Unit:R
T2 = t2+460; #Sink temperature #Unit:R
ans = ((T1-T2)/T1)*100; #(ans in %) #Efficiency of the engine
print "When the upper tempretrature is increased upto certain ,Efficiency of the engine is %.2f percentage "%(ans);
print "Solution for c";
T1 = t1+460; #Source temperature #Unit:R
T2 = 160+460; #Sink temperature #Unit:R
ans = ((T1-T2)/T1)*100; #(ans in %) #Efficiency of the engine
print "When the lower tempretrature is increased upto certain ,Efficiency of the engine is %.2f percentage "%(ans);
```

In [4]:

```
#given data
Qin = 100.; #heat added to the cycle
print "In problem 4.1"
#given data
t1 = 1000.; #(unit:fahrenheit) #Source temperature
t2 = 80.; #(unit:fahrenheit) #Sink temperature
#solution
#converting temperatures to absolute temperatures;
T1 = t1+460; #Source temperature #Unit:R
T2 = t2+460; #Sink temperature #Unit:R
print "Solution for a";
print "Efficiency of the engine is %.2f percentage"%(((T1-T2)/T1)*100);
print "Now in problem 4.2"
W = 0.63*Qin; #W = W/J; #Efficiency in problem 4.1
W = Qin*(W/Qin); #amount of work
Qr = Qin-W; #Qin-Qr = W/J #Qr = heat rejected by the cycle
print "The heat removed from the reservoir %.2f units"%(Qr);
```

In [5]:

```
#given data
t1 = 70.; #(unit:fahrenheit) #Source temperature
t2 = 15.; #(unit:fahrenheit) #Sink temperature
Qin = 125000.; #(unit = Btu/hr) #Qin = heat added to the cycle
# Calculations and Results
#converting temperatures to absolute temperatures;
T1 = t1+460; #Source temperature #Unit:R
T2 = t2+460; #Sink temperature #Unit:R
Qr = Qin*(T2/T1); #Qr = heat rejected by the cycle
print "Qr is %.2f in Btu/hr"%(Qr);
work = Qin-Qr; #reversed cycle requires atleast input #work #btu/hr
print "Work is %.2f in Btu/hr"%(work);
# 1 hp = 33000 ft*LBf/min
# 1 Btu = 778 ft*LBf #1 hr = 60 min
print "Minimum horsepower input required is %.2f hp"%((work*778/60*33000));
```

In [6]:

```
W = (50.*33000)/778; #output #W = W/J
# 1 hp = 33000 ft*LBf/min
# 1 Btu = 778 ft*LBf
print "Output is %.2f in Btu/min"%(W);
t1 = 1000.; #Source temperature #(unit:fahrenheit)
t2 = 100.; #Sink temperature #(unit:fahrenheit)
#converting temperatures to absolute temperatures;
T1 = t1+460; #Source temperature #Unit:R
T2 = t2+460; #Sink temperature #Unit:R
n = (1-(T2/T1))*100; #efficiency
print "Efficiency is %.2f percentage"%(n); #in %)
#n = (W/J)/Qin
Qin = W/(n/100); #(unit Btu/hr) #Qin = heat added to the cycle
print "Heat added to the cycle is %.2f in Btu/min"%(Qin);
Qr = Qin*(1-(n/100)); #(unit Btu/hr) #Qr = heat rejected by the cycle
print "Heat rejected by the cycle is %.2f in Btu/min "%(Qr);
```

In [7]:

```
t1 = 700.; #Source temperature #Unit:Celcius
t2 = 20.; #Sink temperature #Unit:Celcius
#converting in F
T1 = t1+273; #Source temperature #Unit:R
T2 = t2+273; #Sink temperature #Unit:R
n = (T1-T2)/T1*100; #Efficiency
print "Efficiency is %.2f percentage"%(n); #in %)
output = 65; #in hp #Given
work = output*0.746; #(unit kJ/s) # 1 hp = 746 W
print "Work is %.2f kJ/s"%(work);
Qin = work/(n/100); #(unit kJ/s) #Qin = heat added to the cycle
print "Heat added to the cycle is %.2f kJ/s "%(Qin);
Qr = Qin*(1-(n/100)); #(unit kJ/s) #Qr = heat rejected by the cycle
print "Heat rejected by the cycle is %.2f kJ/s "%(Qr);
```

In [8]:

```
import math
# given data
t1 = 700.; #(unit:fahrenheit) #Source temperature
t2 = 200.; #(unit:fahrenheit) #Sink temperature
#converting temperatures to absolute temperatures;
T1 = t1+460; #Source temperature #Unit:R
T2 = t2+460; #Sink temperature #Unit:R
#n1 = (T1-Ti)/T1 and n2 = (Ti-T2)/Ti #n1 & n2 are efficiency
#(T1-Ti)/T1 = (Ti-T2)/Ti;
Ti = math.sqrt(T1*T2); #Exhaust temperature #Unit:R
print "Exhaust temperature of first engine is %.2f in R"%(Ti);
#converting absolute temperature to normal F temperature
#Ti(fahrenheit) = Ti(R)-460;
print "Exhaust temperature of first engine is %.2f fahrenheit"%(Ti-460);
```

In [9]:

```
#For reversible isothermal process,
q = 843.7; #Heat #Unit:Btu #at 200 psia
t = 381.86; #(unit:fahrenheit) #temperature
# #converting temperatures to absolute temperatures;
T = t+460; #temperature #unit:R
deltaS = (q/T); #Change in entropy #Unit:Btu/lbm*R
# Results
print "Change in entropy is %.2f Btu/lbm*R"%(deltaS); #1 LBm of saturated water
```

In [11]:

```
#For reversible isothermal process,
#In problem 4.8,
q = 843.7; #Heat #Unit:Btu #at 200 psia
t = 381.86; #(unit:fahrenheit)
#converting temperatures to absolute temperatures;
T = t+460; #Unit:R"
deltaS = (q/T); #Change in entropy #Btu/lbm
print "Change in entropy is %.2f Btu/lbm*R"%(deltaS); #1 LBm of saturated water
#In problem 4.9
t1 = 381.86; #(unit:fahrenheit) #Source temperature
t2 = 50.; #(unit:fahrenheit) #Sink temperature
#converting temperatures to absolute temperatures;
T1 = t1+460; #Source temperature #Unit:R
T2 = t2+460; #Sink temperature #Unit:R
qin = q; #heat added to the cycle
n = (1-(T2/T1))*100; #Efficiency
print "Efficiency is %.2f percentage"%(n);
wbyJ = qin*n*0.01; #work output
print "Work output is %.2f Btu/lbm"%(wbyJ);
Qr = qin-wbyJ; #heat rejected
print "Heat rejected is %.2f Btu/lbm"%(Qr);
print "As an alternative solution and refering to figure 4.12"
qin = T1*deltaS; #heat added #btu/lbm
Qr = T2*deltaS; #Heat rejected #btu/lbm
print "Heat rejected is %.2f Btu/lbm"%(Qr);
wbyJ = qin-Qr; #Work output #Btu/lbm
print "Work output is %.2f Btu/lbm"%(wbyJ);
n = (wbyJ/qin)*100; #Efficiency
print "Efficiency is %.2f percentage"%(n);
```

In [12]:

```
# Given value
hfg = 1959.7; #Unit:kJ/kg #Evaporative enthalpy
T = 195.07+273; #Converted into Kelvin #Temperature
# Calculations
deltaS = hfg/T; #Change in entropy #kJ/kg*K
# Results
print "Change in entropy at 1.4MPa for the vaporization of 1 kg is %.2f kJ/kg*K"%(deltaS); #Values compares very closely to the Steam Tables value
```

In [13]:

```
#Let is assume that a Carnot engine cycle operates between two temperatures in each case.
t = 1000.; #(unit:fahrenheit)
#converting temperatures to absolute temperatures;
T1 = t+460;
#T1*deltaS = Qin;
Qin = 100.; #Unit:Btu #heat added to the cycle
deltaS = Qin/T1; #Change in entropy #Btu/R
T2 = 50.+460; #converting 50 F temperature to absolute temperature;
Qr = T2*deltaS; #Heat rejected #Unit:Btu
print "%.2f Btu energy is unavailable with respect to a receiver at 50 fahrenheit "%(Qr);
T2 = 0+460; #converting 0 F temperature to absolute temperature;
Qr = T2*deltaS; #Heat rejected #unit:Btu
print "%.2f Btu energy is unavailable with respect to a receiver at 0 fahrenheit "%(Qr);
```

In [14]:

```
Qin = 1000; #Unit:Joule #heat entered to the system
t = 500; #(unit:Celcius) #temperature
#converting temperature
T1 = t+273; #Unit:Kelvin
deltaS = Qin/T1; #Change in entropy #Unit:J/K
print "Solution for a"
T2 = 20+273; #converted 20 Celcius temperature to Kelvin;
Qr = T2*deltaS; #Heat rejected at 20 celcius #Joule
print "%.2f Joule energy is unavailable with respect to a receiver at 20 Celcius"%(Qr);
print "Solution for b"
T2 = 0+273; #converted 0 Celcius temperature to Kelvin
Qr = T2*deltaS; #heat rejected at 0 celcius #Joule
print "%.2f Joule energy is unavailable with respect to a receiver at 0 Celcius"%(Qr);
```

In [15]:

```
#deltas = Cp*ln(T2/T1)
#Multiplying both the sides of equation by the mass m,
#DeltaS = m*Cp*ln(T2/T1)
m = 6.; #mass #Unit:lbm
Cp = 0.361; #Btu/lbm*R #Specific heat constant
DeltaS = -0.7062; #Unit:Btu/R #change in entropy
t = 1440.; #(unit:fahrenheit)
#converting temperatures to absolute temperatures;
T1 = t+460; #Unit:R
#Rearranging the equation,
T2 = T1*math.exp(DeltaS/(m*Cp)); #final temperature #Unit:R
# Results
print "Final temperature is %.2f R"%(T2);
print "or %.2f fahrenheit"%(T2-460);
```

In [16]:

```
#1 lbm of water at 500F is mixed with 1 lbm of water at 100F
m1 = 1.; #Unit:lbm #mass
m2 = 1.; #Unit:lbm #mass
c1 = 1.; #Specific heat constant
c2 = 1.; #Specific heat constant
t1 = 500.; #(unit:fahrenheit)
t2 = 100.; #(unit:fahrenheit)
cmix = 1.; #Specific heat constant of mixture
#now, m1*c1*t1 +m2*c2*t2 = (m1+m2)*cmix*t
#So,
t = ((m1*c1*t1)+(m2*c2*t2))/((m1+m2)*cmix) #resulting temperature of the mixture
print "The resulting temperature of the mixture is %.2f fahrenheit"%(t);
#For this problem,the hot steam is cooled
deltas = cmix*math.log((t+460)/(t1+460)); #temperatures converted to absolute temperatures; #deltas = change in entropy #Unit:Btu/(lbm*R)
#The cold steam is heated
deltaS = cmix*math.log((t+460)/(t2+460)); #temperatures converted to absolute temperatures; #deltaS = change in entropy #Unit:Btu/(lbm*R)
print "The net change in entropy is %.2f Btu/lbm*R)"%(deltaS+deltas);
```

In [17]:

```
#In problem 4.15,
#1 lbm of water at 500F is mixed with 1 lbm of water at 100F
m1 = 1; #Unit:lbm #mass
m2 = 1; #Unit:lbm #mass
c1 = 1; #Specific heat constant
c2 = 1; #Specific heat constant
t1 = 500; #(unit:fahrenheit)
t2 = 100; #(unit:fahrenheit)
cmix = 1; #Specific heat constant of mixture
#now, m1*c1*t1 +m2*c2*t2 = (m1+m2)*cmix*t #So,
t = ((m1*c1*t1)+(m2*c2*t2))/((m1+m2)*cmix) #resulting temperature of the mixture
print "In problem 4.14, The resulting temperature of the mixture is %.2f fahrenheit"%(t);
#Now,in problem 4.15,taking 0F as a reference temperature,
#For hot fluid,
deltas = cmix*math.log((t1+460)/(0+460)); #temperatures converted to absolute temperatures; #deltas = change in entropy #Unit:Btu/(lbm*R)
#For cold fluid,
s = cmix*math.log((t2+460)/(0+460)); #temperatures converted to absolute temperatures; #s = change in entropy #Unit:Btu/(lbm*R)
#At final mixture temperature of t F,the entropy of each system above 0F is,for the hot fluid
s1 = cmix*math.log((t+460)/(0+460)); #temperatures converted to absolute temperatures; #s1 = change in entropy #Unit:Btu/(lbm*R)
#and for the cold fluid,
s2 = cmix*math.log((t+460)/(0+460)); #temperatures converted to absolute temperatures; #s2 = change in entropy #Unit:Btu/(lbm*R)
print "The change in the entropy for hot fluid is %.2f Btu/lbm*R)"%(s1-deltas);
print "The change in the entropy for cold fluid is %.2f Btu/lbm*R)"%(s2-s);
print "The total change in entropy if %.2f Btu/lbm*R"%(s1-deltas+s2-s);
```