How to change the input of the function

1 visualización (últimos 30 días)
Nick Gray
Nick Gray el 29 de Mzo. de 2022
Comentada: Sam Chak el 30 de Mzo. de 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 comentario
Davide Masiello
Davide Masiello el 29 de Mzo. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Arif Hoq
Arif Hoq el 29 de Mzo. de 2022
Editada: Arif Hoq el 29 de Mzo. de 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 comentarios
Arif Hoq
Arif Hoq el 30 de Mzo. de 2022
Editada: Arif Hoq el 30 de Mzo. de 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 el 30 de Mzo. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by