Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

1 回表示 (過去 30 日間)
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 件のコメント
Kamilu Sanusi
Kamilu Sanusi 2022 年 12 月 26 日
@Karim thank you so much for the response but I and E have already been defined to be 2 X 1 matrix i.e
I = zeros(2,1); and
E = busdata2(:,2);
E is obtained from the busdata2 matrix and I is initialized to zero, both are 2 x1 matrix
Karim
Karim 2022 年 12 月 26 日
then you need to delete the (i) after I and E:
E = rand(2,1)
E = 2×1
0.2578 0.7079
Ybuskron = rand(2,2)
Ybuskron = 2×2
0.6850 0.2567 0.5331 0.6584
I = Ybuskron * E
I = 2×1
0.3583 0.6035

サインインしてコメントする。

採用された回答

Karim
Karim 2022 年 12 月 26 日
編集済み: Karim 2022 年 12 月 26 日
@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
delta = 2×1
7.3683 1.3048
E_ang
E_ang = 2×1
-0.1346 2.6093
I
I =
-2.9732 - 8.3062i 2.7217 + 8.4822i
P
P = 2×1
-5.7617 6.1324
  2 件のコメント
Kamilu Sanusi
Kamilu Sanusi 2023 年 1 月 2 日
@Karim, Could you please send me your email please. Mine is sanusielect@yahoo.com. Thank you

サインインしてコメントする。

その他の回答 (1 件)

Paul
Paul 2022 年 12 月 26 日
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 件のコメント
Paul
Paul 2022 年 12 月 26 日
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
i = 1
E(i)
ans = 50
I(i)
ans = 5
Ybuskron*E(i)
ans =
1.0e+02 * 0.0846 - 2.8725i -0.0703 + 3.0013i -0.0703 + 3.0013i 0.0821 - 2.9021i
tyring to assign to I(i)
Unable to perform assignment because the left and right sides have a different number of elements.
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
Kamilu Sanusi 2023 年 1 月 6 日
@PaulThank you for the feedback. But, 2x2 matrix X 2X1 matrix = 2X1 matrix, this is what Im trying to use.Pls can u provide me with ur email so that i send it to u for protection reasons data please. My email is sanusielect@yahoo.com
. Thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by