Borrar filtros
Borrar filtros

Index exceeds matrix dimensions.

2 visualizaciones (últimos 30 días)
arian hoseini
arian hoseini el 10 de En. de 2022
Comentada: Walter Roberson el 10 de En. de 2022
function [L]=LineData
% ---------------------------------data input------------------------------
%{
Transmission line parameters:
1st & 2nd column for line "From-To"
From | To | R | X | Bsh
%}
L =[1 2 0.1 0.2 0.02
1 4 0.05 0.2 0.02
1 5 0.08 0.3 0.03
2 3 0.05 0.25 0.03
2 4 0.05 0.1 0.01
2 5 0.1 0.3 0.02
2 6 0.07 0.2 0.025
3 5 0.12 0.26 0.025
3 6 0.02 0.1 0.01
4 5 0.2 0.4 0.04
5 6 0.1 0.3 0.03]
end
function [B]=BusData
% ---------------------------------data input------------------------------
%bus number| Bus type | voltage schedule | Pgen | Pload | Qload
syms Swing
syms Gen
syms Load
syms Pg
syms Pl
syms Ql
B =[1 Swing 1.05 Pg Pl Ql
2 Gen 1.05 0.5 0 0
3 Gen 1.07 0.6 0 0
4 Load 0 0 0.7 0.7
5 Load 0 0 0.7 0.7
6 Load 0 0 0.7 0.7]
end
%%different file
L=LineData;
%Load BusData input Here:
B=BusData;
%Transmission line parameters:
ln = L(:,1);
rn = L(:,2);
R = L(:,3);
X = L(:,4);
%Bc = L(:,5);
%Bus parameters:
bn = B(:,1);
bt = B(:,2);
vs = B(:,3);
Pgen = B(:,4);
Pload = B(:,5);
Qload = B(:,6);
%Number of Buses:
Nb = max(max(ln), max(rn));
mat= [
1.4286 5.0000 0 5.0000 3.3333 0
5.0000 0.9524 4.0000 10.0000 3.3333 5.0000
0 4.0000 1.6393 0 3.8462 10.0000
5.0000 10.0000 0 1.4286 2.5000 0
3.3333 3.3333 3.8462 2.5000 0.6410 3.3333
0 5.0000 10.0000 0 3.3333 1.6667]
Bs=inv(mat)
syms Swing
syms Gen
syms Load
syms Pg
n = find(ismember(bt, Swing));
Bs(n,:) = []
Bs(:,n) = []
v = find(ismember(bt, Gen));
f = find(ismember(bt, Load));
P = zeros(Nb,1)
P= -Pload + Pgen
P(n,:)=[]
Q=Bs*P
sum(P)==Pg
for i = ln , j = rn
Pt(i,j)=(Q(i)-Q(j))/X(i,j); %Transmission power
end
first can i make this code simple and short?
second why am i getting this error?did i miss something?
and Q depends on Busdata so if first or second or...bt=swing Q of that row is zero
  1 comentario
arian hoseini
arian hoseini el 10 de En. de 2022
Index exceeds matrix dimensions.
Error in sym/subsref (line 814)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in DCPowerFlow (line 64)
Pt(i,j)=(Q(i)-Q(j))/X(i,j); %Transmission power

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de En. de 2022
Editada: Walter Roberson el 10 de En. de 2022
You have
for i = ln , j = rn
Pt(i,j)=(Q(i)-Q(j))/X(i,j); %Transmission power
end
That is not a double-nested loop. That is instead equivalent to
for i = ln
j = rn
Pt(i,j)=(Q(i)-Q(j))/X(i,j); %Transmission power
end
which iterates over i but within each iteration of i it overwrites all of j with the vector rn .
format long g
L=LineData;
L
L = 11×5
1 2 0.1 0.2 0.02 1 4 0.05 0.2 0.02 1 5 0.08 0.3 0.03 2 3 0.05 0.25 0.03 2 4 0.05 0.1 0.01 2 5 0.1 0.3 0.02 2 6 0.07 0.2 0.025 3 5 0.12 0.26 0.025 3 6 0.02 0.1 0.01 4 5 0.2 0.4 0.04
%Load BusData input Here:
B=BusData;
%Transmission line parameters:
ln = L(:,1);
rn = L(:,2);
R = L(:,3);
X = L(:,4);
%Bc = L(:,5);
%Bus parameters:
bn = B(:,1);
bt = B(:,2);
vs = B(:,3);
Pgen = B(:,4);
Pload = B(:,5);
Qload = B(:,6);
%Number of Buses:
Nb = max(max(ln), max(rn));
mat= [
1.4286 5.0000 0 5.0000 3.3333 0
5.0000 0.9524 4.0000 10.0000 3.3333 5.0000
0 4.0000 1.6393 0 3.8462 10.0000
5.0000 10.0000 0 1.4286 2.5000 0
3.3333 3.3333 3.8462 2.5000 0.6410 3.3333
0 5.0000 10.0000 0 3.3333 1.6667];
Bs=inv(mat);
syms Swing
syms Gen
syms Load
syms Pg
n = find(ismember(bt, Swing));
Bs(n,:) = [];
Bs(:,n) = [];
v = find(ismember(bt, Gen));
f = find(ismember(bt, Load));
P = zeros(Nb,1)
P = 6×1
0 0 0 0 0 0
P= -Pload + Pgen
P = 
P(n,:)=[]
P = 
Q=Bs*P
Q = 
sum(P)==Pg
ans = 
for i = ln , j = rn
Pt(i,j)=(Q(i)-Q(j))/X(i,j); %Transmission power
end
j = 11×1
2 4 5 3 4 5 6 5 6 5
Index exceeds the number of array elements. Index must not exceed 5.

Error in sym/subsref (line 997)
R_tilde = builtin('subsref',L_tilde,Idx);
function [L]=LineData
% ---------------------------------data input------------------------------
%{
Transmission line parameters:
1st & 2nd column for line "From-To"
From | To | R | X | Bsh
%}
L =[1 2 0.1 0.2 0.02
1 4 0.05 0.2 0.02
1 5 0.08 0.3 0.03
2 3 0.05 0.25 0.03
2 4 0.05 0.1 0.01
2 5 0.1 0.3 0.02
2 6 0.07 0.2 0.025
3 5 0.12 0.26 0.025
3 6 0.02 0.1 0.01
4 5 0.2 0.4 0.04
5 6 0.1 0.3 0.03];
end
function [B]=BusData
% ---------------------------------data input------------------------------
%bus number| Bus type | voltage schedule | Pgen | Pload | Qload
syms Swing
syms Gen
syms Load
syms Pg
syms Pl
syms Ql
B =[1 Swing 1.05 Pg Pl Ql
2 Gen 1.05 0.5 0 0
3 Gen 1.07 0.6 0 0
4 Load 0 0 0.7 0.7
5 Load 0 0 0.7 0.7
6 Load 0 0 0.7 0.7];
end
  2 comentarios
arian hoseini
arian hoseini el 10 de En. de 2022
thank u so the problem is that Index exceed 5.so the Q has 5 values but it should be 6...so Q depends on Busdata so if first or second or...bt=swing Q of that row is zero ..(as i said it in the first time..looks like u missed it)
for example here Q = -2701139479547903547/11529215046068469760
-2345688154072473701/23058430092136939520
-7373970668296261/72057594037927936
80609037767370081/180143985094819840
-2468031588874529/1441151880758558720
from BusData the first row is Swing so i wanna add 0 to the up matrix
Q = [0
-2701139479547903547/11529215046068469760
-2345688154072473701/23058430092136939520
-7373970668296261/72057594037927936
80609037767370081/180143985094819840
-2468031588874529/1441151880758558720]
and i wrote P= -Pload + Pgen but i want to combine them instead of P= -Pload + Pgen
i tried P= [-Pload,Pgen] but i want it to be like this P=[
Pg orPl
1/2
3/5
-7/10
-7/10
-7/10]
Walter Roberson
Walter Roberson el 10 de En. de 2022
Your values in column 1 and column 2 of your line data are absolute node numbers. You try to use them as indices. However, remember that you deleted data from your matrix, so any absolute index that was greater than the row or column that was deleted, needs to be reduced by the number of entries deleted.
maxnodes = max([ln; rn]);
forward_map = 1:maxnodes;
forward_map(n) = []; %delete any entries corresponding to deleted nodes
BM = nan(1, maxnodes);
BM(forward_map) = 1:length(forward_map));
for i = BM(ln)
for j = BM(rn)
Pt(i,j)=(Q(i)-Q(j))/X(i,j); %Transmission power
end
end
or something like that.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by