In [1]:

```
#Calculate the speed of sound in water amd steel at 20 C
# Variable
#for steel
K_steel=1.94*10**11 #Pa
rho_steel=7800. #Kg.m^3
# Calculation and Result
c_steel=(K_steel/rho_steel)**0.5/1000 # Km/s
print "the speed of sound in steel at 20 C is %f km/s"%c_steel
#for water
K_water=3.14*10**5 #lbf/in^2
rho_water=62.3 #lbm/ft^3
#1 ft =12 in
#1 lbf.s^2 = 32.2 lbm.ft
c_water=(K_water/rho_water*144*32.2)**0.5 #ft/s
print "the speed of sound in water at 20 C is %f ft/s"%c_water
```

In [2]:

```
#Calculate the speed of sound in air at 20 C
# Variable
R=10.73 #lbf.ft^3/in^2/lbmol/R
#1 ft = 12 in
#1 lbf.s^2 = 32.2 lbm.ft
R1=(R*144*32.2)**0.5 #ft/s*(lbm/lbmol/R)^0.5
k=1.4 #dimentionless
T=528. #R (Rankine temperature scale)
M=29. #lbm/lbmol
# Calculation
c=R1*(k*T/M)**0.5 #ft/s
# Result
print "the speed of sound in air at 20 C is %d ft/s"%c
```

In [3]:

```
#Calculate the temperature of the gas where is mach number is 2
# Variable
Ma=2. #dimentionless (Mach number)
k=1.4 #dimentionless
T1=528. #R (Rankine temperature scale)
# Calculation
T2=T1/((Ma**2*(k-1)/2)+1) #R (Rankine temperature scale)
# Result
print "The temperature of the gas when mach number is 2 is %d R"%T2
```

In [6]:

```
#Calculate the speed of sound in air at 20 C
# Variable
R=10.73 #lbf.ft^3/(in^2.lbmol.R)
#1 ft = 12 in
##1 lbf.s^2 = 32.2 lbm.ft
R_root=(R*144*32.2)**0.5 #ft/s*(lbm/lbmol.R)^0.5
Ma=2 #dimentionless (Mach number)
k=1.4 #dimentionless
T=298. #R (Rankine temperature scale)
M=29. #lbm/lbmol
# Calculation
c=R_root*(k*T/M)**0.5 #ft/s
v=c*Ma #ft/s
# Result
print "%f"%c
print "The speed of sound in air at 20 C is %f ft/s"%v
```

In [7]:

```
#Calculate the pressure and density at a pt where temperature ratio is 1.8 and initial pressure and density are given
# Variable
ratio_T=1.8 #dimentionless
P1=2. #bar
k=1.4 #dimentionless
# Calculation
P2=P1/ratio_T**(k/(k-1)) #bar
rho1=2.39 #Kg/m^3
rho2=rho1/ratio_T**(1/(k-1)) #Kg/m^3
# Result
print "The pressure where temperature ratio is 1.8 and initial pressure is 2 bar is %f bar"%P2
print "The density where temperature ratio is 1.8 and initial density is 2.39 Kg/m^3 is %f Kg/m^3"%rho2
```

In [8]:

```
#Calculate the cross sectional area, pressure, temperature and mach number at a pt in duct where air velocity is 1400ft/s
# Variable
P1=30. #psia
T1=660. #R (Rankine temperature scale)
m=10. #lbm/s mass flow rate
v1=1400. #ft/s
R=4.98*10**4 #(ft^2/s^2)*(lbm/lbmol.R)^0.5
k=1.4 #dimentionless
M=29. #lbm/lbmol
# Calculation and Result
T2=T1-v1**2*((k-1)/k)*M/2/R # R (Rankine temperature scale)
print "The temperature at the pt in the duct where air velocity is 1400 ft/s is %f R"%T2
c=223*(k*T2/M)**0.5 #ft/s
Ma=v1/c #dimentionless (Mach number)
print "The mach number at the pt in the duct where air velocity is 1400 ft/s is %f"%Ma
P2=P1/(T1/T2)**(k/(k-1)) #psia
print "The pressure at the pt in the duct where air velocity is 1400 ft/s is %f psia"%P2
#1 lbf.s^2 = 32.2 lbm.ft
A0=m/(P1*(M*k)**0.5*32.2/223/(T1)**0.5/((k-1)/2+1)**((k+1)/2/(k-1))) #in^2
ratio_A=((Ma**2*(k-1)/2+1)/((k-1)/2+1))**((k+1)/2/(k-1))/Ma #dimentionless
A=ratio_A*A0 #in^2
print "The cross sectional at the pt in the duct where air velocity is 1400 ft/s is %f in^2"%A
```

In [9]:

```
#Calculate the cross sectional area, pressure, temperature and mach number at a pt in duct where air velocity is 1400ft/s
# Variable
P1=30. #psia
T1=660. #R (Rankine temperature scale)
ratio_T=0.83333 #dimentionless
m=10. #lbm/s mass flow rate
v1=1400. #ft/s
R=4.98*10**4 #(ft^2/s^2)*(lbm/lbmol.R)^0.5
k=1.4 #dimentionless
M=29. #lbm/lbmol
# Calculation and Result
T2=T1*ratio_T #R (Rankine temperature scale)
print "The temperature at the pt in the duct where air velocity is 1400 ft/s is %f R"%T2
c=223*(k*T2/M)**0.5 #ft/s
Ma=v1/c #dimentionless (Mach number)
print "The mach number at the pt in the duct where air velocity is 1400 ft/s is %f"%Ma
ratio_t=0.7528 #dimentionless
ratio_P=0.3701 #dimentionless
ratio_A=1.0587 #dimentionless
T=T1*ratio_t #R (Rankine temperature scale)
print "T=%f"%T
P=P1*ratio_P#psia
print "P=%f"%P
```

In [5]:

```
#Calculate the cross sectional area, pressure, temperature and mach number at a pt in duct where air velocity is 1400ft/s
# Variable
P1=30. #psia
T1=660. #R (Rankine temperature scale)
m=10. #lbm/s mass flow rate
v1=4000. #ft/s
R=4.98*10**4 #(ft^2/s^2)*(lbm/lbmol.R)^0.5
k=1.4 #dimentionless
M=29. #lbm/lbmol
# Calculation and Result
T2=T1-v1**2*((k-1)/k)*M/2./R #R (Rankine temperature scale)
print "The temperature at the pt in the duct where air velocity is 1400 ft/s is %f R"%T2
T2 = -T2
c=223.*(k*T2/M)**0.5 #ft/s
Ma=v1/c #dimentionless (Mach number)
P2=P1/(T1/T2)**(k/(k-1)) #psia
#1 lbf.s^2 = 32.2 lbm.ft
A0=m/(P1*(M*k)**0.5*32.2/223/(T1)**0.5/((k-1)/2+1)**((k+1)/2/(k-1))) #in^2
ratio_A=((Ma**2*(k-1)/2+1)/((k-1)/2+1))**((k+1)/2/(k-1))/Ma #dimentionless
A=ratio_A*A0 #in^2
```

In [7]:

```
#Calculate the temperatures at different pts in a duct with different mach numbers
# Variable
#for mach number=0.5
ratio_T=0.9524 #dimentionless
T1=293.15 #K
# Calculation
T2=T1/ratio_T #K
# Result
print "The temperature at the pt in the duct where mach number is 0.5 is %f K"%T2
#for mach number 2
ratio_t=0.5556 #dimentionless
t2=293.15 #K
t1=t2*ratio_t #K
print "The temperature initially at the start of the nozzle is %f K"%t1
```

In [13]:

```
#Calculate the reservoir temperature and the pressure of air around the aircraft
# Variable
gama=1.4 #dimentionless
Ma=2. #dimentionless (Mach number)
To=273.15 #K
# Calculation
Tr=To*(Ma**2*(gama-1)/2.+1) # K
P1=50. #KPa
Pr=P1*(Tr/To)**(gama*5/2) #KPa
# Result
print "the reservoir temperature of air around the aircraft is %f K"%Tr
print "The pressure of air around the aircraft is %f KPa"%Pr
```

In [14]:

```
#Calculate temperature and the velocity of air inside the shock wave
# Variable
#Let subscript y denote air inside the shock wave and x denote the air outside the shock wave
ratio_T=1.2309 #dimentionless
Tx=528. #R (Rankine temperature scale)
My=0.7558 #dimentionless
cy=1249. #ft/s
#Calculations
Ty=ratio_T*Tx #R (Rankine temperature scale)
Vy=My*cy #ft/s
#Results
print "temperature of air inside the shock wave is %f R"%Ty
print "the velocity of air inside the shock wave is %f ft/s"%Vy
```

In [15]:

```
#Calculate the ratio of area of throat to area of a certain point
# Variable
A_throat=1. #in^2
A_exit=1.5 #in^2
ratio_A=2.2385 #dimentionless
# Calculation
ratio_A1=ratio_A*(A_throat/A_exit) #dimentionless
# Result
print "the ratio of area of throat to area of a certain point is %f"%ratio_A1
```