Chapter 7 : Entropy

Example 7.1 Page No : 185

In [2]:
import math 

# Variables
T1 = 37.+273;
T2 = 35.+273;
m = 1.;
cv = 4.187;

# Calculation
S = m*cv*math.log(T1/T2); 			# S = S2-S1

# Results
print "Change in the entropy of the water is %.4f KJ/K"%S

# note : answer is accurate. please check.
Change in the entropy of the water is 0.0271 KJ/K

Example 7.2 Page No : 186

In [2]:
import math 

# Part (a)
T1 = 273.;
T2 = 373.;
m = 1. ;
cv = 4.187;

# Calculation and Results
Ss = m*cv*math.log(T2/T1); 			# S = S2-S1
Q = m*cv*(T2-T1);
Sr = -(Q/T2);
S = Ss+Sr;

print "The entropy change of the universe is %.3f kJ/K"%S

# Part (b)
T3 = 323.;
Sw = m*cv*(math.log(T3/T1)+math.log(T2/T3));
Sr1 = -m*cv*(T3-T1)/T3;
Sr2 = -m*cv*(T2-T3)/T2;
Su = Sw+Sr1+Sr2;
print "The entropy change of the universe is %.3f kJ/K"%Su
The entropy change of the universe is 0.184 kJ/K
The entropy change of the universe is 0.097 kJ/K

Example 7.3 Page No : 187

In [3]:
import math 

# Variables
# Part (a)
m = 1.;
T1 = -5.+273;
T2 = 20.+273;
T0 = 0.+273;
cp = 2.093;
cv = 4.187;
lf = 333.3;

# Calculation
Q = m*cp*(T0-T1)+1*333.3+m*cv*(T2-T0);
Sa = -Q/T2;
Ss1 = m*cp*math.log(T0/T1);
Ss2 = lf/T0;
Ss3 = m*cv*math.log(T2/T0);
St = Ss1+Ss2+Ss3;
Su = St+Sa;

# Results
print "The entropy change of the universe is %.4f kJ/K"%Su

# Part (b)
S = 1.5549; 			# S = S4-S1
Wmin = T2*(S)-Q;
print "The minimum risk required is %.1f kJ"%Wmin

# rounding off error. please check.
The entropy change of the universe is 0.0965 kJ/K
The minimum risk required is 28.1 kJ

Example 7.5 Page No : 190

In [5]:
import math 

Vo = 8.4;
Vh = 14.;
n1 = Vo/22.4; 
n2 = Vh/22.4;
R = 8.31;

# Calculation
x1 = n1/(n1+n2);
x2 = n2/(n1+n2);
S = -R*(n1*math.log(x1)+n2*math.log(x2));

# Results
print "Entropy change for the process is %.2f J/K"%S
Entropy change for the process is 5.50 J/K

Example 7.8 Page No : 192

In [9]:
import math 
from hornerc import horner
import sys

# Variables
#T = poly(0,'T'); 			# T = Tf
Tf_ = [700,-2]   #700-2*T; 			# Tf_ = Tf'

# Calculation
# Bisection method to solve for the polynomial
def Temperature(a,b,f):
    N = 100.;
    eps = 1e-5;
    if((f(a)*f(b))>0):
        print ('no root possible f(a)*f(b)>0');
        sys.exit(0);

    if(abs(f(a))<eps):
        print ('solution at a');
        sys.exit(0)

    if(abs(f(b))<eps):
        print ('solution at b');
        sys.exit(0)

    while(N>0):
        c = (a+b)/2
        if(abs(f(c))<eps):
            x = c ;
            return x;

        if((f(a)*f(c))<0 ):
            b = c ;
        else:
            a = c ;
        N = N-1;
    print ('no convergence');
    sys.exit(0);


def p(T): 
	 return  2*T**3-700*T**2+9000000 
T = Temperature(100,200,p);

Tf_ = horner(Tf_,T);

print "The final temperature of the body C is",Tf_,"K"
The final temperature of the body C is 400 K

Example 7.9 Page No : 193

In [11]:
import math 
from scipy.integrate import quad 
import sys
from numpy import poly1d
from sympy import Symbol

# Variables
T1 = 200.;
T2 = 100.;
A = 0.042;

# Calculation
def f10(T): 
	 return A*T**2

Q1 =  quad(f10,T1,T2)[0]


def f11(T): 
	 return A*T**2/T

S =   quad(f11,T1,T2)[0]

W = Symbol('W');
Z = (-Q1-W)/T2 + S; 			# Polynomial to be solved for W

# Bisection method to solve for the Work
def Work(a,b,f):
    N = 100.;
    eps = 1e-5;
    if((f(a)*f(b))>0):
        print ('no root possible f(a)*f(b)>0');
        sys.exit(0);

    if(abs(f(a))<eps):
        print ('solution at a');
        sys.exit(0)

    if(abs(f(b))<eps):
        print ('solution at b');
        sys.exit(0)

    while(N>0):
        c = (a+b)/2
        if(abs(f(c))<eps):
            x = c ;
            return x;
        if((f(a)*f(c))<0 ):
            b = c ;
        else:
            a = c ;
        N = N-1;
    print ('no convergence');
    sys.exit(0)

def p(W): 
	 return  350-0.01*W 

W = Work(34000,36000,p);

print "The maximum work that can be recovered is",W/1000,"kJ"
The maximum work that can be recovered is 35 kJ

Example 7.10 Page No : 194

In [4]:
import math 
from scipy.integrate import quad 

# Variables
P1 = 0.5e06;
V1 = 0.2
V2 = 0.05;
n = 1.3

# Calculation
P2 = P1*(V1/V2)**n;
def H(p):
    return ((P1*V1**n)/p)**(1./n);

def f0(p): 
	 return H

H =  quad(H,P1,P2)[0]

U = H-(P2*V2-P1*V1);
W12 = -U;

# Results
print "Change in enthalpy is %.1f kJ"%(H/1000)
print "Change in internal energy is %.2f kJ"%(U/1000)
print "The change in entropy and heat transfer are",0,"and",0,"kJ"
print "The work transfer during the process is %.2f kJ"%(W12/1000)

# rounding off error.
Change in enthalpy is 223.5 kJ
Change in internal energy is 171.91 kJ
The change in entropy and heat transfer are 0 and 0 kJ
The work transfer during the process is -171.91 kJ

Example 7.11 Page No : 195

In [8]:
import math 
from scipy.integrate import quad 

# Variables
Pa = 130e03; 
Pb = 100e03;
Ta = 50+273; 
Tb = 13+273;
cp = 1.005;

# Calculation
def f1(T): 
	 return cp/T

def f2(p):
    return .287/p
Ss =  quad(f1,Ta,Tb)[0] - quad(f2,Pa,Pb)[0]
Ssy = 0;
Su = Ss+Ssy;

# Results
print "Change in the entropy of the universe is %.3f kJ/Kg k"%Su
print "As the change in entropy of the universe in the process A-B is negative so the flow must be from B-A"
Change in the entropy of the universe is -0.047 kJ/Kg k
As the change in entropy of the universe in the process A-B is negative so the flow must be from B-A

Example 7.12 Page No : 196

In [9]:
import math 

# Variables
T1 = 300.
T2 = 330.
T3 = 270.
P1 = 4.
P2 =1.
P3 =1.
cp = 1.0005
R = 0.287;

# Calculation
S21 = cp*math.log(T2/T1)-R*math.log(P2/P1); 			# S21 = S2-S1
S31 = cp*math.log(T3/T1)-R*math.log(P3/P1); 			# S31 = S3-S1
Sgen = 1*S21 + 1*S31;

# Results
print "The entropy generated during the process is %.3f kW/K"%Sgen
print "As the entropy generated is positive so such device is possible"
The entropy generated during the process is 0.786 kW/K
As the entropy generated is positive so such device is possible

Example 7.13 Page No : 197

In [11]:
import math 

# Variables
A = 5.*7;
k = 0.71;
L = 0.32;
Ti = 21.+273;
To = 6.+273;

# Calculation and Results
Q = k*A*(Ti-To)/L ;
print "The rate of heat transfer through the wall is %.2f W"%Q

Sgen_wall = Q/To - Q/Ti;
print "The rate of entropy through the wall is %.3f W/K"%Sgen_wall

Tr = 27+273.;
Ts = 2+273.;
Sgen_total = Q/Ts-Q/Tr;
print "The rate of total entropy generation with this heat transfer process is %.3f W/K"%Sgen_total
The rate of heat transfer through the wall is 1164.84 W
The rate of entropy through the wall is 0.213 W/K
The rate of total entropy generation with this heat transfer process is 0.353 W/K