I am working on a code to simulate a vehicle trajectory based on forces act on it in different altitudes, I need a formula that gives density in an altitude range between 0 and 40 km to obtain lift and drag in different altitudes. Is there a formula that gives it to me even with a reasonable error?
There are the right way and the easy way.
Rigorous way would be to use the ICAO Standard Atmosphere (Doc 7488-CD in 1993) a link for document Then your code looks for temperature gradient (Table D) and uses eq.12 or 13 for pressure calculation. It depends on the temperature gradient. Then you can easily compute the density eq.14.
Easy way would be calculate density for few altitudes and fit the result with some proper function.