MATLAB: I am trying to run the program below and i am getting the error “Index exceeds matrix dimensions” for the line power = (0.5 .* pi .* density .* R^2 .* u .* Cp(ind2)); Can some one please please help me.

index exceeds matrix dimensionswind turbine power

%Program of a wind turbine to determine the variation of power
%with the wind speed variation
%Cp values
beta =0; %pitch angle
ind2 =1;
for lambda=0.1:0.01:11.8
lambdai(ind2)=(1./((1./(lambda-0.02.*beta)+(0.003./(beta^3+1)))));
Cp(ind2)=0.73.*(151./lambdai(ind2)-0.58.*beta-0.002.*beta^2.14-13.2).*(exp(-18.4./lambdai(ind2)));
ind2=ind2+1;
end
% Set values of density, rotor radius and velocity variation.
density = 1.2041;
R = 63;
v = [0.1:0.01:12];
u = v.^2;
%power as a function of wind speed
power = (0.5 .* pi .* density .* R^2 .* u .* Cp(ind2));
%Plot the graph of power against wind sped
subplot(1,2,1)
plot(u,power,'linewidth',1.5)
grid
xlabel('Wind speed (m/s)','fonstsize',14)
ylable('Power(W)','fontsize',14)

Best Answer

When that line is evaluated the value of ind2 is 1172, but there are only 1171 elements in Cp. You have a too high a value because you increment ind2 at the end of the loop.
You could move the ind2 incrementation to the start of the loop, and initialize its value to zero:
ind2 = 0;
for lambda = 0.1:0.01:11.8
ind2 = 1+ind2;
... your code
end
and then your code will not produce that error. Alternatively (and this is what I would do) you could loop over the indices (in which case do NOT increment ind2 inside the loop!):
vec = 0.1:0.01:11.8;
for ind2 = 1:numel(vec)
lambda = vec(k);
... your code
end
Note: whether the working code is correct is a different matter entirely, that I cannot answer with the information that you have give us.
Related Question