I am having trouble creating a loop for inputs into a function
    7 views (last 30 days)
  
       Show older comments
    
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!!
0 Comments
Answers (1)
  Bharat Chandra Mukkavalli
      
 on 12 Jul 2022
        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          
Refer to the link here on plotting multiple plots: https://in.mathworks.com/help/matlab/creating_plots/combine-multiple-plots.html
Hope this helps!
4 Comments
  Rik
      
      
 on 12 Jul 2022
				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]
    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     
See Also
Categories
				Find more on Loops and Conditional Statements in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

