Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kamilu Sanusi
am 26 Dez. 2022
Kommentiert: Kamilu Sanusi
am 6 Jan. 2023
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 Kommentare
Karim
am 26 Dez. 2022
then you need to delete the (i) after I and E:
E = rand(2,1)
Ybuskron = rand(2,2)
I = Ybuskron * E
Akzeptierte Antwort
Karim
am 26 Dez. 2022
Bearbeitet: Karim
am 26 Dez. 2022
@Kamilu Sanusi, based on your comments I tried to update the code. The code runs without errors, but you will have to verify wheter or not the outcome is correct. The main change is that in order to perform the matrix multiplication, you needed to delete the indexing (i)
Hence change lines like
I(i) = Ybuskron*E(i)
into
I = Ybuskron*E
Below, I tried to make the necesary changes. Hope it helps.
% this values was not provided, thus i made it a random value
Tbase = rand;
% 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
% i added a max iteration counter to run online, since Tbase is a random
% value anyway
while iteration < 2000 && (delta_tolerance > 1e-7 || E_angle_tol > 1e-7)
% incerment the iteration count
iteration = iteration + 1;
E = cos(delta) + 1j*sin(delta);
I = Ybuskron*E;
S = E.*conj(I);
P = real(S);
delta = (Pm - P) / Dpu;
E_mag = abs(Eprev) + acc1 * (abs(E) - abs(Eprev) );
E_ang = angle(Eprev) + acc2 * (angle(E)- angle(Eprev));
delta = delta_prev + acc3 * (delta - delta_prev );
E = E_mag.*exp(1i*E_ang);
E11(iteration,:) = abs(E);
E_angle_tol = max(abs(angle(E) - angle(Eprev)));
delta_tol = max(abs( delta - delta_prev ));
Eprev = E;
end
delta
E_ang
I
P
2 Kommentare
Weitere Antworten (1)
Paul
am 26 Dez. 2022
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 Kommentare
Paul
am 26 Dez. 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.
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!