MATLAB if statement help VERY SIMPLE confused
Afficher commentaires plus anciens
I have a number 'h' that I input into this function 'finddata'. inside the function i have several if and elseif statements. But my problem is when i run anything greater than h = 25000, say h = 47000, by breakpoint debugging,the function does the right things and skips the if statement for h <= 11000, but then starts at the 11000 < h < 25000 interval and spits that out as my answer. Thats not right! it needs to go to the respective if statement. Am i coding this wrong?
function [ T,P,rho ] = finddata(h)
%UNTITLED2 Summary of this function goes here
% To find the Temperature, Pressure, and Density given altitude
% conversion into SI
% h = alt* ;
g = 9.81;
R = 287;
if h <= 11000
a1 = -6.5e-3;
Tref1 = 288.16;
href1 = 0;
Pref1 = 101325;
rho_ref1 = 1.2250;
T = Tref1+a1*(h-href1);
P = Pref1 * (T/Tref1)^(-g/a1/R);
rho = rho_ref1*(T/Tref1)^(-g/a1/R-1);
if else 11000 < h <= 25000
Tref2 = 223.15;
href2 = 11000;
Pref2 = 2.2616e+04;
rho_ref2 = 0.3636;
T = Tref2;
P = Pref2*exp(((-g)/(R*T))*(h-href2));
rho = rho_ref2*exp(((-g)/(R*T))*(h-href2)-1);
elseif 25000 < h <= 47000
a3 = 3e-3;
Tref3 = 223.15;
href3 = 25000;
Pref3 = 2.6490e+03;
rho_ref3 = 0.0157;
T = (Tref3) + (a3)*(h-href3);
P = Pref3 * (T/Tref3)^(-g/a3/R);
rho = rho_ref3*(T/Tref3)^(-g/a3/R-1);
elseif 47000 < h <= 53000
Tref4 = 223.15;
href4 = 11000;
Pref4 = 2.2616e+04;
rho_ref4 = 0.3636;
T = Tref4;
P = Pref4*exp(((-g)/(R*T))*(h-href4));
rho = rho_ref4*exp(((-g)/(R*T))*(h-href4)-1);
elseif 53000 < h <= 79000
a5 = -4.5e-3;
Tref5 = 331.16;
href5 = 47000;
Pref5 = 251.9333;
rho_ref5 = 0.0027;
T = Tref5+a5*(h-href5);
P = Pref5 * (T/Tref5)^(-g/a5/R);
rho = rho_ref5*(T/Tref5)^(-g/a5/R-1);
elseif 79000 < h <= 90000
Tref6 = 223.15;
href6 = 11000;
Pref6 = 2.2616e+04;
rho_ref6 = 0.3636;
T = Tref6;
P = Pref6*exp(((-g)/(R*T))*(h-href6));
rho = rho_ref6*exp(((-g)/(R*T))*(h-href6)-1);
elseif 90000 < h <= 105000
a7 = 4e-3;
Tref7 = 427.1600;
href7 = 79000;
Pref7 = 13.8573;
rho_ref7 = 1.1639e-04;
T = Tref7+a7*(h-href7);
P = Pref7 * (T/Tref7)^(-g/a7/R);
rho = rho_ref7*(T/Tref7)^(-g/a7/R-1);
end
end
function is as follows in script:
[T,P,rho] = finddata(h)
thank you!!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Desktop dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!