If and elseif loop

조회 수: 1 (최근 30일)
Stephen Mixon
Stephen Mixon 2021년 7월 14일
답변: Cris LaPierre 2021년 7월 14일
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

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 7월 14일
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

카테고리

Help CenterFile Exchange에서 Gamma Functions에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by