필터 지우기
필터 지우기

How do I return to the 2nd For loop until the if statement is met before starting the 2nd iteration of the first For loop?

조회 수: 2 (최근 30일)
This may not be a very clean way to code this but, I am trying to get the 2nd For loop to repeat until the 2nd if loop condition is met then return to the 1st For loop and begin the next iteration until all 19 iterations are complete.
%% AEM 508 Term Project
% Define Known Variables
clc
clear all
close all
Pa = 18750; %Patm Pa
Ta = 216.7; %Tatm K
UFlight = 252; % m/s
T = 189000; % Thrust Needed N
To4 = 1875; % K Temp after CC
Qr = 43400000;
EtaDiffuse = .97;
EtaCompress = .85;
EtaBurn = 1;
EtaTurbine = .9;
EtaNozzle = .98;
EtaFan = .85;
EtaFN = .97;
R = 287; % Gas Constant (j/(kg.K))
B = 5; % Bypass Ratio
GDiffuse = 1.4; % Gamma Diffuser
GCompress = 1.37; % Gamma Compressor
GBurn = 1.35; % Gamma Burner
GTurbine = 1.33; % Gamma Turbine
GNozzle = 1.36; % Gamma Nozzle
GFan = 1.4; % Gamma Fan
GFN = 1.4; % Gamma Fan-Nozzle
%% Calculations
% Diffuser
M = UFlight/(sqrt(1.4*R*Ta));
To2 = Ta*(1+((GDiffuse-1)/2)*(M^2));
Po2 = Pa*(1+EtaDiffuse*((To2/Ta)-1)^(GDiffuse/(GDiffuse-1)));
Toa = To2;
% Compressor/CC/Turbine/Nozzle
CpB = R*(GBurn/(GBurn-1)); % Cp Combustion Chamber
PrcIDX = 0;
Prf = 1;
for Prc = 7:1:25;
PrcIDX = PrcIDX + 1;
PrcSave(PrcIDX) = Prc;
Po3 = Po2*Prc;
To3 = To2*(1+(1/EtaCompress)*((Prc.^((GCompress-1)/GCompress))-1));
f = (To4-To3)/(((EtaBurn*Qr)/CpB)-To4); % air-fuel ratio
Po4 = Po3*((To4/To3)^(GBurn/(GBurn-1)));
To8 = To2*(1+(1/EtaFan)*((Prf^(GFan-1)/GFan)-1));
Po8 = Po2*Prf;
To5 = To4 - (To3-To2) - B*(To8-Toa);
Po5 = Po4*((1-(1/EtaTurbine)*(1-(To5/To4)))^(GTurbine/(GTurbine-1)));
if abs(Po5 - Po8)<100
PrfSave(PrcIDX) = Prf;
Prf = 1;
continue
else
for Prf = Prf + .0001
To8 = To2*(1+(1/EtaFan)*((Prf^(GFan-1)/GFan)-1));
Po8 = Po2*Prf;
To5 = To4 - (To3-To2) - B*(To8-Toa);
Po5 = Po4*((1-(1/EtaTurbine)*(1-(To5/To4)))^(GTurbine/(GTurbine-1)));
if abs(Po5 - Po8)>100
continue
else
PrfSave(PrcIDX) = Prf;
Prf = 1;
break
end
end
end
end

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 11월 12일
It looks to me like you may want to use a while loop for your second loop instead of a for loop. Right now, it is only running once in each loop of the first for loop.
for a = 3 + 0.001
a
end
a = 3.0010
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2021년 11월 13일
I think the while conditional should be the opposite of what you have for your if statement, and the code you have in the if statement should be moved to after the while loop instead of inside it (without the if).
Also, you will want to add back in the code at the bottom of the for loop to set Prf back to 1 before the next loop starts.
Shawn Alcorn
Shawn Alcorn 2021년 11월 13일
Thank you very much for the help. I organized it the way you recommended and it worked perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axes Transformations에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by