I am having trouble creating a loop for inputs into a function

2 ビュー (過去 30 日間)
Logan DiCerb
Logan DiCerb 2022 年 7 月 11 日
I have a MATLAB code and function that finds values needed for a turbojet analysis and here is the function I created and I am calling for a project:
[ST,S,Thrust] = dualspoolturbofan(M_0,mdot_0,T_0,p_0,pi_dmax,T_t4,eff_b,pi_b,h_PR,alpha,pi_cL,pi_c,pi_f,gamma_c,cp_c,e_cL,e_cH,gamma_t,cp_t,e_tL,e_tH,e_f,eff_mH,eff_mL,pi_n,pi_fn,p0_p9,gc);
My problem statement is to then plot the outputs vs M_0 (3v1 graph), while M_0 changes from (0.0,0.9,30) (30 values between 0.0 & 0.9), and T_t4 changes from 2800,3200,3400 (just those 3 values)
So 90 total changed inputs with the 30 Mach values and 3 temperature values. I am just stuck on what loops to create to satisfy this problem statement. Thanks so much!!

回答 (1 件)

Bharat Chandra Mukkavalli
Bharat Chandra Mukkavalli 2022 年 7 月 12 日
Hi,
As I understand, you want to plot three graphs ST vs M_0, S vs M_0 and Thrust vs M_0 for different discrete values of T_t4.
You can run the following loops to achieve this:
M_0 = linspace(0, 0.9, 30);
titledlayout(3, 1);
for temp in [2800, 3200, 3400]
ST_vec = [];
S_vec = [];
Thrust_vec = [];
for m in M_0
[ST,S,Thrust] = dualspoolturbofan(m, ..., temp, ...);
ST_vec(end+1) = ST;
S_vec(end+1) = S;
Thrust_vec(end+1) = Thrust;
end
nexttile
hold on
plot(M_0, ST_vec);
plot(M_0, S_vec);
plot(M_0, Thrust_vec);
hold off
end
Hope this helps!
  4 件のコメント
Rik
Rik 2022 年 7 月 12 日
No, it does not. 'in' is not a valid Matlab syntax. You can easily check this by formatting your code as a code section, instead of an inserted example.
M_0 = linspace(0, 0.9, 30);
titledlayout(3, 1);
for temp in [2800 3200 3400]
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
ST_vec = [];
S_vec = [];
Thrust_vec = [];
for m in M_0
[ST,S,Thrust] = dualspoolturbofan(m, ..., temp, ...);
ST_vec(end+1) = ST;
S_vec(end+1) = S;
Thrust_vec(end+1) = Thrust;
end
nexttile
hold on
plot(M_0, ST_vec);
plot(M_0, S_vec);
plot(M_0, Thrust_vec);
hold off
end
Bharat Chandra Mukkavalli
Bharat Chandra Mukkavalli 2022 年 7 月 12 日
I have corrected it

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInstallation and Operational Settings についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by