Standard Atmosphere table: how can i use the initial values of one section, which are the last ouputs of the last one?

17 views (last 30 days)
Emma Carns
Emma Carns on 22 Feb 2018
I am writing a code to calculate the pressure, density, temperature, geopotential altitude and geometric altitude. The troposphere is from 0-11 km, isothermal from 12-24, and stratosphere from 25-47. initially i wrote my code to use the last value calculated, but my teacher told me I need to be using the initial value for each step as the T1 and so on. So how can I use the numbers calculated for step 12, the pressure, density, temperature, etc, and use that for the initial in all of the rest until step 24, then the same for 25-47?
clear,clc; %clear the workspace.
T = []; %create empty arrays for T, temperature.
p = []; %create empty arrays for p, pressure.
d = []; %create empty arrays for d, d is being used instead of rho for density.
h = linspace(0,47,48); %using a linspace function so there are 48 steps from 0 to 48.
a = -6.5*10^-3; %what the a for the troposphere is.
a1 = -3*10^-3; %what the a for the stratosphere is.
g = 9.80065; %what the gravity constant is.
R = 287; %what the R constant is.
re= 6371.0008 %what the radius of the earth is.
T(1) = 288.16; %intial value of Temperature at sea level.
p(1) = 1.01325*10^5; %initial value of pressure at sea level.
d(1) = 1.225; %initial value of density at sea level.
for i = 2:48 %begin my for statement, for i from 2:48.
if(i<12) %begin if statement for troposphere, from 0:11.
T(i) = T(1) + a*(h(i)-h(i-1)); %using i to use the last total used, not the intitial value. this is the equation for Temperature.
p(i) = ((T(i)/T(1))^(-g/(a*R)))*(p(1));%again using i, this is the equation for pressure.
d(i) = ((T(i)/T(1))^((-g/(a*R))-1))*(d(1)); %again using i, this is the equation for density.
elseif(i<26) %elseif statement for if i<26 and greater than 11, isothermal.
T(i) = T(12); %temperature is constant in the isothermal layer.
p(i) =(exp((-g/(R*T(i)))*(h(i)-h(i-1))))*p(12); %pressure equation using i.
d(i) =(exp((-g/(R*T(i)))*(h(i)-h(i-1))))*d(12); %density equation using 1.
else %stratosphere, else statement, which is everything else from 26-47, do not need parameters because they are already set.
T(i) = T(25) + (a1 *(h(i)-h(i-1))); % temperature equation, using i's again to use the last value, not the initial from the set.
p(i) = ((T(i)/T(25))^(-g/(a1*R)))*p(25); %pressure equation, using i's.
d(i) = ((T(i)/T(25))^((-g/(a1*R))-1))*d(25); %density equation, using i's.
end% end the if statement.
hG(i) = (h(i)*re)/(re - h(i)); %hG has the same equation for all of the altitudes so we leave that out of the if statement, will be used for all.
end%end the for statement.
GeopotentialAltitude = h.'%name the variable and use values from h.
GeometricAltitude= hG.' %name the variable and use values from hG.
Temperature = T.'%name the variable and use values from T.
Pressure = p.'%name the variable and use values from p.
Density = d.' %name the variable and use values from d.
T1 = table(GeopotentialAltitude, GeometricAltitude, Temperature, Pressure, Density); %create a table T1, and use the variables just stated in this order for the columns.
T1.Properties.VariableUnits = {'km' 'km' 'K' 'kg/m^3' 'N/m^2'}% adding variable units, although I can't seem to figure out how to get these to show up.
h=h' %what i have will have all of them as 1*48 matrices, so we need to transpose it to be 48*1.

Answers (2)

Guillaume on 22 Feb 2018
I don't really understand your question. From step 12 to 25 your code already use T(12), p(12) and d(12) in the right hand side of your calculations. So if that's what you call T1 then you're already doing it.
The big problem I see, is that at step 12, you do:
T(12) = T(12);
p(12) = something * p(12);
d(12) = something * d(12);
And since T(12), p(12) and d(12) are all 0 to start with, you'll end up with 0 for all them. Shouldnt't you be using T(11), p(11) and d(11) instead, i.e. the last value calculated in the previous branch?
Unrelated, but instead of
T = []; %create empty arrays for T, temperature.
p = []; %create empty arrays for p, pressure.
d = []; %create empty arrays for d, d is being used instead of rho for density.
You should use
T = zeros(48, 1);
p = zeros(48, 1);
d = zeros(48, 1);
since you already know their final size. Avoid growing arrays in loop. As a bonus, they're created as column vectors, so you don't have to transpose them later on. Similarly, I'd create h as
h = linspace(0,47,48).';
so your hG ends up as a column vector.

how can do the program for properties of Air Atmospheric Presssure table using Matlab & matlab functions.
if any one knows mail me

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!