Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Afficher commentaires plus anciens
Dear MATLAB users,
I am trying to run this program to determine delta (delta(1) and delta(2)) which is the main unknown parameter but at line 45, I am experiencing "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side".
Is the placement of line 46 equation the right place to put it in the program?
Is it also neccessary to initialize P to zeros?
Any suggestions on the errors in this program or how to improve it would be so much appreciated. My email is sanusielect@yahoo.com
Thank you
% Main program
Pm1 = (6.593706744511551/Tbase)*1; % 6.593706744511551/Tbase;
Pm2 = (2.337250265694494/Tbase)*1; % 2.337250265694494/Tbase;
Ta1= 0.1*(100*pi)^2/1000;
Ta2= 0.6*(100*pi)^2/1000;
Em = 325;
Dpu = 9;
% Bus data parameters
% 1 2 3 4 5 6 7 8 9 10 11
% Bus E delta Poi Qoi PGi QGi PLi QLi Pm Ta
busdata2 =[1 1 0 0 0 0 0 0 0 Pm1 Ta1;
2 1 0 0 0 0 0 0 0 Pm2 Ta2;];
acc1 = 1.385;
acc2 = 1.412;
acc3 = 1.439;
bus2 = busdata2(:,1) % Bus number.
E = busdata2(:,2)
delta = busdata2(:,3) % Initial Bus Voltage Angles.
PO = busdata2(:,4);
QO = busdata2(:,5);
PG = busdata2(:,6); % PGi, Real Power injected into the buses.
QG = busdata2(:,7); % QGi, Reactive Power injected into the buses.
PL = busdata2(:,8); % PLi, Real Power Drawn from the buses.
QL = busdata2(:,9); % QLi, Reactive Power Drawn from the buses.
Pm = busdata2(:,10);
Ta = busdata2(:,11);
n_bus = max(bus2) % To get no. of buses
P = PG + PO - PL; % Pi = PGi - PLi, Real Power at the buses.
Q = QG + QO - QL; % Qi = QGi - QLi, Reactive Power at the buses.
Eprev = E;
% Initialization of varaiables
I = zeros(2,1)
S = zeros(2,1);
delta_prev = delta;
iteration = 0; % Iteration Starting
E11 = zeros(2000,2);
delta_tolerance = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ybuskron = [0.1691 - 5.7449i -0.1407 + 6.0026i;-0.1407 + 6.0026i 0.1642 - 5.8042i]; % 2 by 2 matrix
while (delta_tolerance > 1e-7 || E_angle_tol > 1e-7)
for i = 1:n_bus
E(i)=(cos(delta(i))+1j*sin(delta(i)))
45 I(i) = Ybuskron*E(i);
S(i) = E(i)*conj(I(i));
P(i) = real(S);
end
46 delta(i) = ((Pm(i) - P(i))/Dpu);
E_mag(i) = abs(Eprev(i)) + acc1*(abs(E(i))-abs(Eprev(i)));
E_ang(i) = angle(Eprev(i)) + acc2*(angle(E(i))-angle(Eprev(i)));
delta(i) = delta_prev(i) + acc3*(delta(i) - delta_prev(i));
E(i) = E_mag(i)*exp(1i*E_ang(i));
E11(iteration+1,1:2)= abs(E);
% E_tolerance = max(abs((E)-(Eprev)));
E_angle_tol = max(abs((angle(E))- angle(Eprev)));
delta_tol = max(abs(delta - delta_prev));
Eprev = E; % Vprev is required for next iteration
iteration = iteration + 1; % Increment iteration count
end
delta;
E_ang;
I;
P;
3 commentaires
Karim
le 26 Déc 2022
Note that Ybuskron is a 2x2 matrix, E(i) is a scalar. The result of this operation is a 2x2 matrix. You are trying to save this into I(i) which can only store a single scalar. This is why you get the error about the dimensions. So either you need to change the computation at that line or change I to be a matrix of 2x2
I(i) = Ybuskron*E(i)
Kamilu Sanusi
le 26 Déc 2022
then you need to delete the (i) after I and E:
E = rand(2,1)
Ybuskron = rand(2,2)
I = Ybuskron * E
Réponse acceptée
Plus de réponses (1)
Paul
le 26 Déc 2022
0 votes
At line 45 the variable Ybuskron is a 2 x 2 matrix and E(i) is a 1 x 1 scalar. So their product is a 2 x 2 matrix, which is trying to be assigned to I(i) which is a scalar 1 x 1. Can't assign a 2 x 2 result to a 1 x 1. I'm not sure what the code is attempting to do so don't have any suggestions on how to modify that line to make the code work properly.
3 commentaires
Kamilu Sanusi
le 26 Déc 2022
Yes, I and E are defined that way and at the start of the loop are both 2 x 1. Nevertheless, inside the loop that starts with
for i = 1:n_bus
the value of i is a scalar and you are trying to assign a 2 x 2 result to single element of I. To illustrate, let's intialize I and E to 2 x 1 with entries something other than zero
I = [5;10];
E = [50;100];
Here is Ybuskron
Ybuskron = [0.1691 - 5.7449i -0.1407 + 6.0026i;-0.1407 + 6.0026i 0.1642 - 5.8042i]; % 2 by 2 matrix;
Here is the relevant part of the loop, displaying the relevant values, using an arbitrary value for n_bus
n_bus = 2;
for i = 1:n_bus
i
disp('E(i)'),E(i)
disp('I(i)'),I(i)
disp('Ybuskron*E(i)'),Ybuskron*E(i)
disp('tyring to assign to I(i)')
I(i) = Ybuskron*E(i)
end
Can't assign a 2 x 2 matrix to a single element E(1).
Would need more information about the algorithm the code is tyring to implement in order for anyone to suggest corrections.
Kamilu Sanusi
le 6 Jan 2023
Catégories
En savoir plus sur Logical 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!