Matlab图只绘制For Loop中的一个值?

时间:2014-07-10 13:44:27

标签: matlab matrix graph matrix-multiplication

我目前正在设计一个程序,它将输出x轴上4到10范围内的值的图表。然而,当我绘制图形时,它只绘制点而不是For循环所需的6个点。有人可以帮忙解决这个问题吗?

我附上了我的代码和图表:

    ![% Inputs
R=0.4;                                          % Radius of Rotor
B=3;                                            % Number of blades
V=2;                                            % Fluid velocity
Rho=998;                                        % Fluid Density
N=9;                                            % Number of Blade Elements
Cp_estimate=0.5;                                % Estimate power coefficient
Alpha_design=4;                                 % Design alpha
Cl_design=1.04;                                 % Design lift coefficient



% Variables
TSR=4;                                          % Initial tip speed ratio
Cp=0;                                           % Initial power coefficient
i=1;                                            % Counter
alpha_new=0;                                    % Initial value for alpha new
axial_induction=0;                              % Initial axial induction factor
tolerance=0.01;                                 % Tolerance Value
Check=1;                                        % Initial check value
axial_induction_old=0;                          % Initial value for old axial induction factor




for TSR=4:10,disp(TSR),                                                                     % TSR from 4 to 10

   while abs(Check)>=tolerance

r_local=\[(R./N)*1; (R./N)*2; (R./N)*3; (R./N)*4; (R./N)*5; (R./N)*6; (R./N)*7; (R./N)*8; (R./N)*9\];
r_over_R=r_local / R;
TSR_local=r_over_R .* TSR;

Phi=(2/3)*atan(1./TSR_local);
C=((8.*pi.*r_local) ./ (B.*Cl_design)).*(1-cos(Phi));
sigma=(B*C) ./ (pi.*r_local.*2);


Cl=\[1.3; 1.1; 1; 0.9; 0.86; 0.83; 0.8; 0.75; 0.5\];                                          % Lift Coefficients
Cd=\[0.027; 0.024; 0.02; 0.019; 0.018; 0.016; 0.013; 0.012; 0.01\];                           % Drag Coefficients




axial_induction= 1 ./ (((4.*(sin(Phi).^2)) ./ (sigma.*Cl_design.*cos(Phi)))+1);
angular_induction= (1-(3*axial_induction)) ./ ((4.*axial_induction)-1);




axial_induction_old = axial_induction;        
TSR_local = TSR*(r_local./R);                                                                 % Local Tip Speed Ratio
Phi = (2/3)*atan(1./TSR_local);                                                               % Angle of Relative Fluid




relative_wind= atan((1-axial_induction) ./ ((1+axial_induction).*TSR));

F=(2/pi).*acos(exp(-(((B/2).*(1-(r_over_R))) ./ ((r_over_R).*sin(relative_wind)))));          % Tip Loss Factor

C_T=(sigma.*((1-axial_induction).^2) .* ((Cl.*cos(relative_wind))+(Cd.*sin(relative_wind)))) ./ ((sin(relative_wind)).^2);


if C_T(:,i)<0.96
    axial_induction=1 ./ (1+(4.*F.*(sin(relative_wind).^2)) ./ (sigma.*Cl.*cos(relative_wind)));  
elseif C_T(:,i)>0.96
    axial_induction=1 ./ (((4.*F.*cos(relative_wind)) ./ (sigma.*Cl))-1); 
end

D=(8./(TSR.*N)).*(F.*(sin(Phi).^2).*(cos(Phi)-((TSR_local).*(sin(Phi)))).*(sin(Phi)+((TSR_local).*(cos(Phi)))).*(1-(Cd./Cl).*atan(Phi)).*(TSR_local.^2));
Cp=sum(D);


Diff=axial_induction-axial_induction_old;
Check=max(Diff(:));



   end

store_Phi(:,TSR)=Phi;
store_TSR_local(:,TSR)=TSR_local;
store_axial_induction(:,TSR)=axial_induction;
store_angular_induction(:,TSR)=angular_induction;
store_relative_wind(:,TSR)=relative_wind;
store_Check(:,TSR)=Check;
store_Diff(:,TSR)=Diff;
store_Cp(:,TSR)=Cp;
store_TSR(:,TSR)=TSR;

end




figure(1)
plot(store_TSR,store_Cp)
hold all
title('Cp vs Tip Speed Ratio')
xlabel('TSR')
ylabel('Cp')][1]

2 个答案:

答案 0 :(得分:0)

好吧,我尝试在Octave中运行你的代码,在纠正代码中的一些拼写错误之后,这就是我得到的:

enter image description here

这不是你所期望的吗?

仅供参考,我发现的拼写错误如下:

  • ![% Inputs替换为% Inputs
  • r_local=\[(R./N)*1; (R./N)*2; (R./N)*3; (R./N)*4; (R./N)*5; (R./N)*6; (R./N)*7; (R./N)*8; (R./N)*9\];替换为r_local=[(R./N)*1; (R./N)*2; (R./N)*3; (R./N)*4; (R./N)*5; (R./N)*6; (R./N)*7; (R./N)*8; (R./N)*9];
  • Cl=\[1.3; 1.1; 1; 0.9; 0.86; 0.83; 0.8; 0.75; 0.5\];替换为Cl=[1.3; 1.1; 1; 0.9; 0.86; 0.83; 0.8; 0.75; 0.5];
  • Cd=\[0.027; 0.024; 0.02; 0.019; 0.018; 0.016; 0.013; 0.012; 0.01\];替换为Cd=[0.027; 0.024; 0.02; 0.019; 0.018; 0.016; 0.013; 0.012; 0.01];

答案 1 :(得分:0)

第一次迭代完成后(Check)保留TSR=4中的变量Check=0,因此它用于TSR=5,因此满足了while语句。一个简单(虽然不优雅)的解决方案是在for语句之后立即定义Check

for TSR=4:10,disp(TSR),                      
    Check=1;
    while abs(Check)>=tolerance
        r_local=R/N*(1:9)'; % does the same as your code
        %rest of code
    end
    %rest of code    
end`

除了am304的评论:

在代码的某些部分中不需要使用./(逐元素划分)。 RN都是标量,并且不会在循环中更改,因此{for}循环外部也可以定义r_local(并在上面的代码中缩短)。尝试仅在实际需要时使用./.*