# variables
v1 = 100.; # fps
p1 = 50.; # psia
T1 = 300.; # degreeF
v2 = 500.; # fps
Cp = 186.5;
gam = 1.4;
# calculations
T2 = T1 - (v2**2 - v1**2)/(2*36.2*Cp);
p2 = p1*(1 - (v2**2 - v1**2)/(2*36.2*53.3*(T1+460)*(gam/(gam-1))))**(1/0.286);
# results
print 'T2 = %d degreeF'%(round(T2,-1));
print 'p2 = %.1f psia'%(p2);
#there is an error in the answer given in textbook
import math
# variables
p1 = 300.; # psia
T1 = 900.; # degreeF
p2 = 200.; # psia
T2 = 780.; # degreeF
H2 = 1414.; #Btu/lb
H1 = 1471.; # Btu/lb
# calculations
V2 = math.sqrt(2*31.1*778*(H1-H2));
# results
print 'T2 = %d degreeF and V2 = %d fps'%(T2,V2);
import math
# variables
v = 586.; # fps
p = 13.; # psia
T = 0.; # degreeF
gam = 1.4;
# calculations
rho_0 = p*144/(32.2*53.3*(460+T));
a_0 = math.sqrt(gam*32.2*53.3*(T+460));
M_0 = v/a_0;
p_8_approx = p+(0.5/144)*rho_0*v**2 *(1+0.25*M_0**2);
p_8_exact = p*(1+M_0**2 *(gam-1)/2)**(gam/(gam-1));
T_8 = v**2 /(2*32.2*186.5) +460;
rho_8 = p_8_exact*144/(T_8*32.2*53.3);
# results
print 'At stagnetion point, p = %.2f psia, T = %.1f degreeR and density = %.5f slug/cuft'%(p_8_exact,T_8,rho_8);
import math
# variables
g = 32.2
k = 1.40
R = 53.3
A2 = 0.005454
p1 = 114.7 * 144
T1 = 560
# calculations
y1 = p1 /(R * T1)
p2 = 0.528 * 114.7
G1 = math.sqrt(g*k/R * (2/(k+1))**((k+1)/(k-1))) * A2*p1/math.sqrt(T1)
p2 = 94.7 # psia
p2byp1 = 0.825
G = A2*math.sqrt( (2*g*k)/(k-1) * p1*y1 * ((p2byp1)**(2/k) - (p2byp1)**((k+1)/k)))
# result
print "part a"
print "G = %.2f lb/sec"%G1
print "\npart b"
print "G = %.2f lb/sec"%G
import math
# variables
d = 1.; # in
p = 100.; # psi
T = 10.; # degreeF
p_i = 80.; #psi
p_b = 14.7; #psi
p1 = 16520.; # psfa
gam1 = 0.553; # lb/cuft
k = 0.874;
# calculations
G = (0.5*k*0.25*math.pi*(d/12)**2 /(1-(2./3)**4)) *math.sqrt(2*32.2*(p-p_i)*144/gam1);
# results
print 'flow rate = %.2f lb/sec'%(G);
import math
# variables
d = 1.; # in
p_r = 100.; #psi
T_r = 100.; # degreeF
p_b = 14.7; # psi
p3 = 14.7; #psi
G = 2.03; # lb/sec
gam1 = 0.553;
gam = 1.4;
# calculations
V3 = math.sqrt(2*32.2*(gam/(gam-1))*(p_r+p_b)*144/gam1 *(1-(p3/(p_r+p_b))**((gam-1)/gam)));
T3 = (T_r+460) - V3**2 /(2*32.2*186.5);
a3 = math.sqrt(gam*32.2*53.3*T3);
M3 = V3/a3;
A3 = G/(gam1*V3);
d3 = (A3/(0.25*math.pi))**(1./2);
p3_dash = 103.3; # psia
p_B = p3*(1+ (2*gam/(gam+1))*(M3**2 -1));
# results
print 'V3 = %d fps, a3 = %d fps, M3 = %.2f '%(V3,a3,M3);
print 'p3_dash = %.1f psia, p_B = %.1f psia'%(p3_dash,p_B);
#there are rounding-off errors in the answer given in textbook
import math
# variables
V_0 = 586.; # fps
t_0 = 0; # degreeF
P_0 = 13.; # psia
a_0 = 1052.; # fps
M_0 = 0.557;
V_A = 800.; #fps
V_B = 900.; #fps
gam = 1.4;
# calculations
T_A = 488.5- V_A**2 /(2*32.2*186.5);
T_B = 488.5- V_B**2 /(2*32.2*186.5);
p_A = 16.18*(T_A/488.5)**(gam/(gam-1));
p_B = 16.18*(T_B/488.5)**(gam/(gam-1));
a_A = math.sqrt(gam*32.2*53.3*T_A);
a_B = math.sqrt(gam*32.2*53.3*T_B);
M_A = V_A/a_A;
M_B = V_B/a_B;
# results
print 'At point A, p = %.2f psia, T = %.1f degreeR, a = %d fps, M = %.3f'%(p_A,T_A,a_A,M_A);
print 'At point B, p = %.2f psia, T = %.1f degreeR, a = %d fps, M = %.1f'%(p_B,T_B,a_B,M_B);
#answer differs due to rounding-off errors in textbook