- D is a square matrix of size N_Branch(1,1) x N_Branch(1,1).
- A is a matrix of size N_Branch(1,1) x (N_Branch(1,1)-1), because you removed the first column.
- delta is a column vector of size N_bus x 1
DC Power Flow Analysis matlab script not working. My problem seems to be not getting the correct dimensions for my matrices to get them to multiply.
9 次查看(过去 30 天)
显示 更早的评论
Using MATPOWER data. trying to build a code that will work with an unlimited bus system. A IEEE 14 Bus system is going to do for now.
Here is my Code:
% DC Power Flow %
% Unlimited Bus %
% PL = D * A * delta %
% Load data from MATPOWER
mpc = loadcase('case14');
% Branch Column
N_Branch = size(mpc.branch);
% Bus column
N_bus = size(mpc.bus);
% Column 1 = From
% Column 2 = To
% Column 3 = X from the professors equation "" A (X,Y-1) where x=number of
% line and y=number of the bus
% A Matrix is a (K*n-1) incident matrix
A = zeros(N_Branch(1,1),N_Branch(1,1));
% Line Data
Line_Data = zeros(N_Branch(1,1),3);
for i = 1 : N_Branch(1,1)
% Injecting bus Number
Line_Data(i,1) = mpc.branch(i,1);
% Load bus Number
Line_Data(i,2) = mpc.branch(i,2);
% Reactance of TL
Line_Data(i,3) = mpc.branch(i,4);
end
for i = 1 : N_Branch(1,1)
% A matrix data
A(i,Line_Data(i,1)) = 1;
% A matrix data
A(i,Line_Data(i,2)) = -1;
end
%% A Matrix
A(:,1) = [];
%% Power Demand Bus
for i = 1 : N_bus
PD (i,1) = mpc.bus(i,3);
end
PD(1,:) = [];
%% B Bus, B' Matrix
Bprime = makeBdc(mpc);
% Eliminate rows and columns corresponding with the slack bus
Bprime(:,1) = [];
Bprime(1,:) = [];
%% D Matrix
% The number of rows need to match A and delta to be multiplied thourgh.
% Ds hould be multiplied by the identity matrix for the N_Branch cmd
D_identity = eye(N_Branch(1,1));
% D Matrix = (k*k) matrix w/ 0 on off-diagonal elements & Bk in diagonal elements, therefore
% changes need to be made to the syntax to work with the future equation for Power flow
for i = 1 : N_Branch(1,1)
D_diagonal(i,1) = 1/mpc.branch(i,4);
end
D = D_identity .* D_diagonal;
%% Delta = Inverse B prime matrix multiplied by the Power demand matrix.
delta = (Bprime)^(-1) * PD
%% Power Flow
% P = Bprime * delta
PL = D * A * delta
% Base MVA
Base = mpc.baseMVA;
% Bus Data
Bus_Data = mpc.bus;
% function [PF] = dcpflow(P,Line_Data)
for i = 1 : N_bus(1,1)
% Bus Number
Demand(:,1) = -mpc.bus(:,1); % Negative Value
% Bus Active Load
Demand(:,2) = -mpc.bus(:,3); % Negative Value
% Bus Number
Generation(i:1) = mpc.gen(i:1);
% Scheduled Active Power Generation
Generation(i:2) = mpc.gen(i:2);
end
% end
% Run DC Power Flow
% rundcpf;
I have commenter out a few things toward the end bc I am going to implement them later. disregard these for now.
Here is my error code:
delta =
10.7310
24.3753
20.0517
17.3170
27.4108
25.8280
25.8280
28.9350
29.4132
28.7715
29.3611
29.6657
31.5217
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of
columns in the first matrix matches the number of rows in the second
matrix. To operate on each element of the matrix individually, use TIMES
(.*) for elementwise multiplication.
Error in FinalMatlabProject142 (line 88)
PL = D * A * delta
0 个评论
回答(1 个)
Manikanta Aditya
2024-1-12
I feel you need to ensure that the dimensions of your matrix aligns for multiplication, You might need to transpose one of your matrices, or perhaps there's an issue with how the matrices and being constructed.
The error message you’re seeing is due to a mismatch in the dimensions of the matrices being multiplied. In your case, the error is occurring at the line PL = D * A * delta.
Looks like from the above line:
The multiplication D * A is valid because the number of columns in D matches the number of rows in A. However, the result of D * A is a matrix of size N_Branch(1,1) x (N_Branch(1,1)-1), and this cannot be multiplied with delta because the number of columns in D * A does not match the number of rows in delta.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dynamic System Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!