Graph Not Plotting All Values??
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I am trying to output a graph from my programme which will plot TSR against CP for values of TSR ranging from 4 to 10. This is my code:
filename = 'book2.xlsx';
Input = xlsread(filename);
N = xlsread(filename,'C7:C15')
r = xlsread(filename,'D7:D15')
C = xlsread(filename,'E7:E15')
S = xlsread(filename,'F7:F15')
Non = xlsread(filename,'G7:G15')
% 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
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
F=(2/pi).*acos(exp(-(((B/2).*(1-(r_over_R)))./((r_over_R).*sin(Phi)))));
axial_induction=1./(((4.*(sin(Phi).^2))./(sigma.*Cl_design.*cos(Phi)))+1);
angular_induction=(1-(3*axial_induction))./((4.*axial_induction)-1);
for TSR=4:10,disp(TSR), % TSR from 4 to 10
while abs(Check)>=tolerance
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=(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(TSR,:)<0.96
axial_induction=1./(1+(4.*F.*(sin(relative_wind).^2))./(sigma.*Cl.*cos(relative_wind)));
else
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(:));
TSR=TSR+1;disp(TSR);
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
end
figure(1)
plot(store_Cp,store_TSR)
hold all
title('Cp vs Tip Speed Ratio')
xlabel('TSR')
ylabel('Cp')
However, when I run the programme I get the following graph. It is clear that the programme is not plotting all TSR values. Could anybody please help with this?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165504/image.jpeg)
3 Commenti
dpb
il 10 Lug 2014
...TSR value of 4 to 10.
Well, you guaranteed that by the loop index.
...instead of the desired power curve with all 6 points, ...
The sequence 4:10 includes 7 values, not 6.
Risposte (1)
Star Strider
il 10 Lug 2014
It’s difficult to follow your code, and I can’t run it. You probably need to display the incremental value of store_TSR to see what its value is in the loop.
If you want to plot Cp as a function of TSR, your plot statement should be:
plot(store_TSR,store_Cp)
I don’t know what you’re doing with this statement:
TSR=TSR+1;disp(TSR);
Since you’re using TSR as a loop counter, it will have no effect, so delete it. You can’t redefine the loop counter inside the loop.
1 Commento
dpb
il 10 Lug 2014
Well, tho, he can (and does) create/modify a local variable of the same name in the loop and he's (stubbornly) refused to take the previous advice given in that regard at
The loop index TSR variable does revert and alias the other local TSR at the beginning of the next iteration but he then mungs it up again.
I gave several demos in the other thread; unfortunately, while thanking for the advice it seems to have not had any effect.
@Kevin -- I gave several hints at otherwise simplifying your code in the previous thread. I again suggest you look at those. If the idea is to build an array from 1:someN columns; keep a secondary variable, say iCol and initialize it then increment it in the loop instead of munging on the loop index variable.
Also, if that's the idea, preallocate and fill the arrays instead of dynamically "growing" them each pass thru the loop.
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!