I'm trying to build a sounding rocket to reach the 100km as my senior project next year. To do this I need an equation to approximate the atmospheric density at any given altitude in the rocket's ascent, so that I can better understand the engine performance requirements of the rocket. I got my atmospheric data from https://www.engineeringtoolbox.com/standard-atmosphere-d_604.html
Here is some python code with outputs:
## Atmospheric density curve fit from Engineering Toolbox US standard Atmosphere ## Design by whisperingShiba from scipy import optimize import numpy as np import matplotlib.pyplot as plt def fxn(x, a, b): return a*np.exp(-b*x) def polyFxn(h, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9): return ((((((((a9*h + a8)*h + a7)*h + a6)*h + a5)*h + a4)*h + a3)*h + a2)*h + a1)*h + a0 altitudes = np.array([0,5000,10000,15000,20000,25000,30000,35000,40000,45000,50000,60000,70000,80000,90000,100000,150000,200000,250000]) density1 = np.array([23.8,20.48,17.56,14.96,12.67,10.66,8.91,7.38,5.87,4.62,3.64,2.26,1.39,.86,.56,.33,.037,.0053,.00065]) altitudeLinSpace = np.linspace(0,500000,500000) #Popt returns a array containing constants a,b,c... etc for function 'fxn' popt, pcov = optimize.curve_fit(fxn, altitudes, density1, p0=(1, 1e-5)) popt2, pcov2 = optimize.curve_fit(polyFxn, altitudes, density1) print(popt) print(popt2) #Plots data plt.grid(True) plt.ylim((0,25)) plt.ylabel('Density of atmospher in slug/ft^3 * 10^-4') plt.xlabel('Altitude, feet') #Data from engineering toolbox plt.plot(altitudes, density1) #curve_fit for negative exponential plt.plot(altitudeLinSpace, fxn(altitudeLinSpace, popt, popt)) plt.plot(altitudeLinSpace, polyFxn(altitudeLinSpace, popt2,popt2,popt2,popt2,popt2,popt2,popt2,popt2,popt2,popt2)) plt.show()
Here's the output of the python script, where blue is the data, orange is the negative exponential, and green is the 9th order polynomial fit:
As can be seen in the image, the 9th order polynomial fit is really good for the first part, but deviates massively past 100000 feet. The negative exponential fit has the opposite problem, having good performance as altitude approaches infinity, but having poor performance from 50000 ft to 100000 feet.
How could I best fit this data? I want to avoid super long polynomials if possible (I only have 19 data points, and the curve is already trying too hard to 'hit' all the points). I have already put this data into excel and its even worse than python's curve fit. Any advice would be greatly appreciated.