Effacer les filtres
Effacer les filtres

If and elseif loop

1 vue (au cours des 30 derniers jours)
Stephen Mixon
Stephen Mixon le 14 Juil 2021
I am trying to say that if f1 is greater than f_st (which is .0667) then calculate T04f using f =.0667.
M = 4;
T_a = 205; %kelvin
P_a = 11.6; %kpa
Q_r = 45000; %Kj/kg
f_st = .0667; % Greater than or equal to used in if loop
T_o4 = 3000; %kelvin
r_d = (1 - (0.1 * ((M-1) ^ 1.5)));
r_fh = 0.97;
r_comb = .95;
n_n = .95;
n_comb = .98;
Me_comb = 0.5;
R = .287; %kJ/Kg*k
gamma1 = 1.4;
gamma2 = 1.3;
cp1= (gamma1 * R) / (gamma1 - 1);
% Equations
p0a_pa = (((1 + (gamma1 - 1) / 2) * (M ^ 2)) ^ (gamma1 / (gamma1 - 1)))
T0a_ta = ((1 + (gamma1 - 1) / 2) * (M ^ 2));
T02 = T_a;
p02_p0a = r_d
p03_p02 = r_fh
T03 = T02;
T04 = 3000; %kelvin
f1 = ((T04-T03) / (((Q_r * n_comb) / cp1) - T04))
if f1 > f_st
f = .0667;
T04f= ((T03 / (1 + f))+(((f / (1 + f)) * ((Q_r * n_comb) / cp1))))
elseif f1 <= f_st
T04f = T04
end

Réponses (1)

Cris LaPierre
Cris LaPierre le 14 Juil 2021
See Ch 13 of MATLAB Onramp to learn about if-else statements (they are not loops).
Can you clarify what is or isn't happening that you expected?
In your case, you could use an if-else statement.
if f1 > f_st
f = .0667;
T04f= ((T03 / (1 + f))+(((f / (1 + f)) * ((Q_r * n_comb) / cp1))))
else
T04f = T04
end

Catégories

En savoir plus sur Event Functions dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by