How to change the input of the function

1 vue (au cours des 30 derniers jours)
Nick Gray
Nick Gray le 29 Mar 2022
Commenté : Sam Chak le 30 Mar 2022
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 commentaire
Davide Masiello
Davide Masiello le 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.

Connectez-vous pour commenter.

Réponses (1)

Arif Hoq
Arif Hoq le 29 Mar 2022
Modifié(e) : Arif Hoq le 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)
T = 286.2845
P = 9.7923e+04
rho = 1.1762
% 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 commentaires
Arif Hoq
Arif Hoq le 30 Mar 2022
Modifié(e) : Arif Hoq le 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)
T = 0
P = 0
rho = 0
% 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
Sam Chak le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by