How to change the input of the function
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to write this code, with the input of altitude (h), to give me the temp, pressure, density. I'm not sure how to make it so that i can change the value of h. The function also seems to return the same numbers when h<11000, no matter what the input number is.
function [T, P, rho] = question1 (h)
T1 = 288.15;
L = -0.0065;
R = 287;
PSL = 101325;
g = 9.81;
rhoSL = 1.225;
if h<11000
T = T1 + L*R;
P = PSL * (T/T1)^((-g)/(L*R));
rho = rhoSL * (T/T1)^(((-g)/(L*R)) +1);
else 99
end
end
1 Commento
Davide Masiello
il 29 Mar 2022
The function returns the same values when h < 11000 because the equations in your conditional statement do not depend on h, but rather on constants.
If you could disclose your governing equations maybe a solution could be suggested.
Risposte (1)
Arif Hoq
il 29 Mar 2022
Modificato: Arif Hoq
il 29 Mar 2022
%define your variable and call your function
T1 = 288.15;
L = -0.0065;
R = 287;
PSL = 101325;
g = 9.81;
rhoSL = 1.225;
[T, P, rho]=question1 (T1,L,R,PSL,g,rhoSL)
% your function
function [T, P, rho] = question1 (T1,L,R,PSL,g,rhoSL)
h=8000; % change your h
if h<=11000
T = T1 + L*R;
P = PSL * (T/T1)^((-g)/(L*R));
rho = rhoSL * (T/T1)^(((-g)/(L*R)) +1);
else
T=0;
P=0;
rho=0;
end
end
5 Commenti
Arif Hoq
il 30 Mar 2022
Modificato: Arif Hoq
il 30 Mar 2022
See the result now. I have changed the value of h, so result also changed.
in additon, i have defined an anynomous value of conditional else . so please define your conditional else value according to your calculation.
%define your variable and call your function
T1 = 288.15;
L = -0.0065;
R = 287;
PSL = 101325;
g = 9.81;
rhoSL = 1.225;
[T, P, rho]=question1 (T1,L,R,PSL,g,rhoSL)
% your function
function [T, P, rho] = question1 (T1,L,R,PSL,g,rhoSL)
h=12000; % change your h
if h<=11000
T = T1 + L*R;
P = PSL * (T/T1)^((-g)/(L*R));
rho = rhoSL * (T/T1)^(((-g)/(L*R)) +1);
else
T=0;
P=0;
rho=0;
end
end
Sam Chak
il 30 Mar 2022
I remember my Aeronautics Professor showed me that the pressure P and density ρ of the air changes with altitude, h. Perhaps these formulas are helpful in the MATLAB code.
Then from the Ideal Gas Law, we can compute the Temperature at which pressure is calculated.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!