I am having trouble creating a loop for inputs into a function
    조회 수: 7 (최근 30일)
  
       이전 댓글 표시
    
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
답변 (1개)
  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          
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
  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]
    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     
참고 항목
카테고리
				Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!