Index exceed array bound error showing....
Afficher commentaires plus anciens
clear all;
clc;
display(' MATLAB CODE FOR FORMATION OF BUS ADMITTANCE MATRIX ');
m=input('Enter the no of buses=');
for i=1:m
for j=1:m
fprintf('Enter the admittance value between %d & %d is=',i,j);
y(i,j)=input('=');
end
end
Y(m,m)=0;
for i=1:m
for j=1:m
if i==j
for k=1:m
Y(i,j)=Y(i,j)+y(i,k);
end
else
Y(i,j)=-y(i,j);
end
end
end
disp('Bus Admittance Matrix is::');
Y_bus=Y
inp2=input('\nEnter Voltage in 1st column, p in 2nd, q in 3rd: ');
vo=inp2(:,1);
p=inp2(:,2);
q=inp2(:,3);
vn(1)=vo(1);
for i=2:m
s1=0;
for j=1:i-1
s1=s1+Y(i,j)*vn(j);
end
s2=0;
for j=i+1:m
s2=s2+Y(i,j)*vo(j);
end
vn(i)=(((p(i)-1j*q(i))/vo(i))-s1-s2)/Y(i,i);
end
for i=1:m
fprintf('\nVoltage %d new =',i);
disp(vn(i));
[theta,r] = cart2pol(real(vn(i)), imag(vn(i)));
theta= theta.*(180/pi);
for i=1:m
fprintf('\nMod V%d:%f',i,r(i));
fprintf('\tdelta%d:%f',i,theta(i));
end
end
OUTPUT
MATLAB CODE FOR FORMATION OF BUS ADMITTANCE MATRIX
Enter the no of buses=4
Enter the admittance value between 1 & 1 is==0
Enter the admittance value between 1 & 2 is==2-8i
Enter the admittance value between 1 & 3 is==1-4i
Enter the admittance value between 1 & 4 is==0
Enter the admittance value between 2 & 1 is==2-8i
Enter the admittance value between 2 & 2 is==0
Enter the admittance value between 2 & 3 is==0.666-2.664i
Enter the admittance value between 2 & 4 is==1-4i
Enter the admittance value between 3 & 1 is==1-4i
Enter the admittance value between 3 & 2 is==0.666-2.664i
Enter the admittance value between 3 & 3 is==0
Enter the admittance value between 3 & 4 is==2-8i
Enter the admittance value between 4 & 1 is==0
Enter the admittance value between 4 & 2 is==1-4i
Enter the admittance value between 4 & 3 is==2-8i
Enter the admittance value between 4 & 4 is==0
Bus Admittance Matrix is::
Y_bus =
Columns 1 through 2
3.0000 -12.0000i -2.0000 + 8.0000i
-2.0000 + 8.0000i 3.6660 -14.6640i
-1.0000 + 4.0000i -0.6660 + 2.6640i
0.0000 + 0.0000i -1.0000 + 4.0000i
Columns 3 through 4
-1.0000 + 4.0000i 0.0000 + 0.0000i
-0.6660 + 2.6640i -1.0000 + 4.0000i
3.6660 -14.6640i -2.0000 + 8.0000i
-2.0000 + 8.0000i 3.0000 -12.0000i
Enter Voltage in 1st column, p in 2nd, q in 3rd: [
1.06+0i 0 0
1.0+0i -0.5 -0.2
1.0+0i -0.4 -0.3
1.0+0i -0.3 -0.1]
Voltage 1 new = 1.0600
Mod V1:1.060000 delta1:0.000000Index exceeds array bounds.
Error in MYY (line 66)
fprintf('\nMod V%d:%f',i,r(i));
>>
Réponses (2)
You are trying to extract more number of elements than present in the array. You need to have a look on the maxiimum index of your for loop.
$ EXample:
A = rand(1,10) ; % matrix of size 1*10
fprintf('%f\n',A(1)) % no error
fprintf('%f\n',A(10)) % no error
fprintf('%f\n',A(11)) % eroror, 11th element is not present
Image Analyst
le 25 Août 2021
Whatever m is, r does not have that many elements. Before the for loop, put this and see what it says in the command window:
m % Don't use semicolons
whos r
whos theta
Like maybe it will say m is 100 but r only has one element. So when (the badly-named) i gets to 2 and it tries to print r(2), it can't do that because there is no 2 and thus throws the error saying so.
By the way, you can fix the indentation in MATLAB editor by typing control-a, then control-i. Do that before copying it. Then paste it into Answers, highlight/select the code, and click the code icon on the tool ribbon so that it will be formatted as code and have the copy link so people can conveniently copy the whole thing into the clipboard with one click.
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!