Index in position 2 exceeds array bound (must not exceed 6)

1 次查看(过去 30 天)
Hi all, May I ask how to solve this error? Thank you in advance.
function[ F ,P1 ,Pl]=eldnba(x)
warning off;
data=[0.000299 10.1 671 150 455
0.000183 10.2 574 150 455
0.001126 8.8 374 20 130
0.001126 8.8 374 20 130
0.000205 10.4 461 150 470
0.000301 10.1 630 135 460
0.000364 9.8 548 135 465
0.000338 11.2 227 60 300
0.000807 11.2 173 25 162
0.001203 10.7 175 25 160
0.003586 10.2 186 20 80
0.005513 9.9 230 20 80
0.000371 13.1 225 25 85
0.001929 12.1 309 15 55
0.004447 12.4 323 15 55];
% Loss coefficients it should be squarematrix of size nXn where n is the no
% of plants
B=[ 0.0017 0.0012 0.0007 -0.0001 -0.0005 0.0002
0.0012 0.0014 0.0009 0.0001 -0.0006 -0.0001
0.0007 0.0009 0.0031 0.0000 -0.0010 -0.0006
-0.0001 0.0001 0.0000 0.0024 -0.0006 -0.0008
-0.0005 -0.0006 -0.0010 -0.0006 0.0129 -0.0002
-0.0002 -0.0001 -0.0006 -0.0008 -0.0002 0.0150];
% Demand (MW)
Pd=2630;
x=abs(x);
n=length(data(:,1));
for i=1:n-1
if x(i)>1
x(i)=1;
else
end
P(i)=data(i+1,4)+x(i)*(data(i+1,5)-data(i+1,4));
end
B11=B(1,1);
B1n=B(1,5:n);
Bnn=B(5:n,5:n);
A=B11;
BB1=2*B1n*P';
B1=BB1-1;
C1=P*Bnn*P';
C=Pd-sum(P)+C1;
x1=roots([A B1 C]);
% x=.5*(-B1-sqrt(B1^2-4*A*C))/A
x=abs(min(x1));
if x>data(1,15)
x=data(1,15);
else
end
if x<data(1,14)
x=data(1,14);
else
end
P1=[x P];
for i=1:n
F1(i)=data(i,1)* P1(i)^2+data(i,2)*P1(i)+data(i,3);
end
Pl=P1*B*P1';
lam=abs(sum(P1)-Pd-P1*B*P1');
F=sum(F1)+1000*lam;

回答(1 个)

Image Analyst
Image Analyst 2021-12-3
编辑:Image Analyst 2021-12-3
You say
data=[0.000299 10.1 671 150 455
0.000183 10.2 574 150 455
0.001126 8.8 374 20 130
0.001126 8.8 374 20 130
0.000205 10.4 461 150 470
0.000301 10.1 630 135 460
0.000364 9.8 548 135 465
0.000338 11.2 227 60 300
0.000807 11.2 173 25 162
0.001203 10.7 175 25 160
0.003586 10.2 186 20 80
0.005513 9.9 230 20 80
0.000371 13.1 225 25 85
0.001929 12.1 309 15 55
0.004447 12.4 323 15 55];
so data has 5 columns. So then why do you refer to the 14th or 15th column here:
if x>data(1,15)
x=data(1,15);
else
end
if x<data(1,14)
x=data(1,14);
else
end
What are you expecting to be in the 14th column when it has only 5 columns?
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by