import math
#initialization
v = 2000.0 #ft/sec
P = 14.7 #lb/in^2
g = 1.4
T = 10+460.0 #R
#calculation
c = math.sqrt(g*32.2*53.3*T)
Nm = v/c
Tratio = 1+ (g-1)/2 *Nm**2
Tt = Tratio*T
Pratio = (Tratio)**(g/(g-1))
Pt = Pratio*P
#result
print "Stagnation temperature = %d R" %Tt
print "Stagnation pressure = ", round(Pt, 1), "lb/in^2"
import math
#initialization
A = 0.3 #ft^2
P = 30.0 #lb/in^2
T = 160+460.0 #R
Mn = 0.82
g = 1.4
#calculation
w = A*144*P*math.sqrt(g*32.2) *Mn*(1+ (g-1)/2.0 *(Mn)**2)**(-3)/math.sqrt(53.3*T)
#result
print "Mass flow = ", round(w, 1), "lbm/sec"
import math
#initialization
Mn = 3.0
Mni = 0.2
w = 10.0 #lbm/sec
g = 1.4
P = 200.0 #lb/in^2
T = 400+460.0 #R
#calculation
Astar = w*math.sqrt(53.3*T) *((g+1)/2)**3 /(P*math.sqrt(g*32.2))
A1ratio = (2.0/(g+1) + (g-1)*Mni**2 /(g+1))**3 /Mni
A1 = A1ratio*Astar
A2ratio = (2.0/(g+1) + (g-1)*Mn**2 /(g+1))**3 /Mn
A2 = A2ratio*Astar
Pexit = P/(1+ Mni*Mn**2)**(g/(g-1))
#result
print "Throat Area = ", round(Astar, 2), "in^2"
print "Inlet Area = ", round(A1, 2), "in^2"
print "Exit Area = ", round(A2, 2), "in^2"
print "Exit pressure = ", round(Pexit, 2), "lb/in^2"
import math
#initialization
Pi = 750.0 #lb/in^2
g = 1.25
TA = 2.0 #in^2
r = 3.0
#calculation
Fstar = round(((g+1)*(2.0/(g+1))**5 *TA*750))
Me = 2.45
Fratio = round(((1+g*Me**2)/(Me*(math.sqrt(4.5+ (g**2 -1)*Me**2)))), 3)
F2 = Fratio*Fstar
Pratio = (1+ 0.2*Me**2)**5
Fnstar = Fratio-((g+1)/2.0)**5 *r/(Pratio*2.25)
Fn = Fnstar*Fstar
#result
print "Internal rocket thrust = %d lb" %F2 #answer in textbook is wrong
print "External thrust = %d lb" %Fn #answer in textbook is wrong
#initialization
Tt2 = 1620+460 #R
Tt1 = 60+460 #R
Mi = 0.2
P = 40 #lb/in^2
g = 1.35
#calculation
Tratio = Tt2/Tt1
#From figure
fM = 4*0.036
NM2 = 0.49
Pratio = 0.98/0.885
Pt2 = P/Pratio
#result
print "Final stagnation pressure = ", round(Pt2, 1), "lb/in^2"
print "Final mach number = ", round(fM, 3)
#initialization
M = 0.4
l = 10.0 #ft
dia = 3.0 #in
P = 50.0 #lb/in^2
ff = 0.008
T = 100+460.0 #R
#calculation
constant = 4*ff*l/dia
exitM = 2.9-constant
Nm2 = 0.5
Ptratio = 2.73/2.3
Pt2 = P/Ptratio
#result
print "Exit total pressure = ", round(Pt2, 1), "lb/in^2"