I am trying to run a loop in python to get an array of P values. I have an array of t and h values. I need to calculate the difference of h2-h1 for each iteration. For example, for the first iteration, I need to calculate 200-10, and the second 350-200, etc.
I want to calculate P for each iteration, using the previous iteration's P value as Po. Here's my code:
import matplotlib.pyplot as plt
import numpy as np
h = np.array([10,200,350,500,700,850,1000,1500,2000,2500,3000]) #height (m)
t = np.array([20,17,15,13,15,17,19,14,10,7,4]) #Temp (C)
t = t+273.15 #Temp (K)
ws = np.array([3,12,15,16,17,18,19,19.6,20,20.2,21]) #Wind Speed (m/s)
q = np.array([16,15,14,13,3,2,2,1.8,1.7,1.5,1.4]) #specific humidity (g/kg)
#define variables for calculation
Po= 101325 #pa
m = 0.029 #kg/mol
g = 9.8 #m/s
R = 287.058 #J/kg/K #specific gas constant for dry air
#calculate virtual potential temperature using Hypsometric equation
### must calculate change in pressure with height
def pressure():
pressure = []
for eachvalue in t:
P = Po/np.exp((g/(R*t))*(np.diff[h]))
pressure.append(P)
return pressure