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?

1 view (last 30 days)
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

Accepted Answer

Cris LaPierre
Cris LaPierre on 12 Nov 2021
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 Comments

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by