Out of memory. The likely cause is an infinite recursion within the program.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% Bus Admittance Matrix
% Copyright (c) 1998 by H. Saadat.
function[Ybus] = ybus(zdata)
nl=zdata(:,1); nr=zdata(:,2); R=zdata(:,3); X=zdata(:,4);
nbr=length(zdata(:,1)); nbus = max(max(nl), max(nr));
Z = R + j*X; %branch impedance
y= ones(nbr,1)./Z; %branch admittance
Ybus=zeros(nbus,nbus); % initialize Ybus to zero
for k = 1:nbr; % formation of the off diagonal elements
if nl(k) > 0 & nr(k) > 0
Ybus(nl(k),nr(k)) = Ybus(nl(k),nr(k)) - y(k);
Ybus(nr(k),nl(k)) = Ybus(nl(k),nr(k));
end
end
for n = 1:nbus % formation of the diagonal elements
for k = 1:nbr
if nl(k) == n | nr(k) == n
Ybus(n,n) = Ybus(n,n) + y(k);
else, end
end
end
i want to run this code but i get this error Out of memory. The likely cause is an infinite recursion within the program.
% From To R X
zdata = [ 0 1 0 1.0
0 2 0 0.8
1 2 0 0.4
1 3 0 0.2
2 3 0 0.2
3 4 0 0.08];
[Ybus] = ybus(zdata) % bus admittance matrix
Ibus = [-j*1.1; -j*1.25; 0; 0]; % vector of injected bus currents
Zbus = inv(Ybus) % bus impedance matrix
Vbus = Zbus*Ibus
%Vbus = Ybus\Ibus
0 comentarios
Respuestas (2)
essrra
el 4 de Mzo. de 2023
function [neighborIds, neighborDistances] = kNearestNeighbors(dataMatrix, queryMatrix, k)
%--------------------------------------------------------------------------
% Program to find the k - nearest neighbors (kNN) within a set of points.
% Distance metric used: Euclidean distance
%
% Usage:
% [neighbors distances] = kNearestNeighbors(dataMatrix, queryMatrix, k);
% dataMatrix (N x D) - N vectors with dimensionality D (within which we search for the nearest neighbors)
% queryMatrix (M x D) - M query vectors with dimensionality D
% k (1 x 1) - Number of nearest neighbors desired
%
% Example:
% a = [1 1; 2 2; 3 2; 4 4; 5 6];
% b = [1 1; 2 1; 6 2];
% [neighbors distances] = kNearestNeighbors(a,b,2);
%
% Output:
% neighbors =
% 1 2
% 1 2
% 4 3
%
% distances =
% 0 1.4142
% 1.0000 1.0000
% 2.8284 3.0000
%--------------------------------------------------------------------------
neighborIds = zeros(size(queryMatrix,1),k);
neighborDistances = neighborIds;
numDataVectors = size(dataMatrix,1);
numQueryVectors = size(queryMatrix,1);
for i=1:numQueryVectors
dist = sum((repmat(queryMatrix(i,:),numDataVectors,1)-dataMatrix).^2,2);
[sortval, sortpos] = sort(dist,'ascend');
neighborIds(i,:) = sortpos(1:k);
neighborDistances(i,:) = sqrt(sortval(1:k));
endfunction [neighborIds, neighborDistances] = kNearestNeighbors(dataMatrix, queryMatrix, k)
%--------------------------------------------------------------------------
% Program to find the k - nearest neighbors (kNN) within a set of points.
% Distance metric used: Euclidean distance
%
% Usage:
% [neighbors distances] = kNearestNeighbors(dataMatrix, queryMatrix, k);
% dataMatrix (N x D) - N vectors with dimensionality D (within which we search for the nearest neighbors)
% queryMatrix (M x D) - M query vectors with dimensionality D
% k (1 x 1) - Number of nearest neighbors desired
%
% Example:
% a = [1 1; 2 2; 3 2; 4 4; 5 6];
% b = [1 1; 2 1; 6 2];
% [neighbors distances] = kNearestNeighbors(a,b,2);
%
% Output:
% neighbors =
% 1 2
% 1 2
% 4 3
%
% distances =
% 0 1.4142
% 1.0000 1.0000
% 2.8284 3.0000
%--------------------------------------------------------------------------
neighborIds = zeros(size(queryMatrix,1),k);
neighborDistances = neighborIds;
numDataVectors = size(dataMatrix,1);
numQueryVectors = size(queryMatrix,1);
for i=1:numQueryVectors
dist = sum((repmat(queryMatrix(i,:),numDataVectors,1)-dataMatrix).^2,2);
[sortval, sortpos] = sort(dist,'ascend');
neighborIds(i,:) = sortpos(1:k);
neighborDistances(i,:) = sqrt(sortval(1:k));
endfunction [neighborIds, neighborDistances] = kNearestNeighbors(dataMatrix, queryMatrix, k)
%--------------------------------------------------------------------------
% Program to find the k - nearest neighbors (kNN) within a set of points.
% Distance metric used: Euclidean distance
%
% Usage:
% [neighbors distances] = kNearestNeighbors(dataMatrix, queryMatrix, k);
% dataMatrix (N x D) - N vectors with dimensionality D (within which we search for the nearest neighbors)
% queryMatrix (M x D) - M query vectors with dimensionality D
% k (1 x 1) - Number of nearest neighbors desired
%
% Example:
% a = [1 1; 2 2; 3 2; 4 4; 5 6];
% b = [1 1; 2 1; 6 2];
% [neighbors distances] = kNearestNeighbors(a,b,2);
%
% Output:
% neighbors =
% 1 2
% 1 2
% 4 3
%
% distances =
% 0 1.4142
% 1.0000 1.0000
% 2.8284 3.0000
%--------------------------------------------------------------------------
neighborIds = zeros(size(queryMatrix,1),k);
neighborDistances = neighborIds;
numDataVectors = size(dataMatrix,1);
numQueryVectors = size(queryMatrix,1);
for i=1:numQueryVectors
dist = sum((repmat(queryMatrix(i,:),numDataVectors,1)-dataMatrix).^2,2);
[sortval, sortpos] = sort(dist,'ascend');
neighborIds(i,:) = sortpos(1:k);
neighborDistances(i,:) = sqrt(sortval(1:k));
endV
i want to run this code but i get this error Out of memory. The likely cause is an infinite recursion within the program.
0 comentarios
Walter Roberson
el 22 de Dic. de 2021
Put the function after the script.
% From To R X
zdata = [ 0 1 0 1.0
0 2 0 0.8
1 2 0 0.4
1 3 0 0.2
2 3 0 0.2
3 4 0 0.08];
[Ybus] = ybus(zdata) % bus admittance matrix
Ibus = [-j*1.1; -j*1.25; 0; 0]; % vector of injected bus currents
Zbus = inv(Ybus) % bus impedance matrix
Vbus = Zbus*Ibus
%Vbus = Ybus\Ibus
% Bus Admittance Matrix
% Copyright (c) 1998 by H. Saadat.
function[Ybus] = ybus(zdata)
nl=zdata(:,1); nr=zdata(:,2); R=zdata(:,3); X=zdata(:,4);
nbr=length(zdata(:,1)); nbus = max(max(nl), max(nr));
Z = R + j*X; %branch impedance
y= ones(nbr,1)./Z; %branch admittance
Ybus=zeros(nbus,nbus); % initialize Ybus to zero
for k = 1:nbr; % formation of the off diagonal elements
if nl(k) > 0 & nr(k) > 0
Ybus(nl(k),nr(k)) = Ybus(nl(k),nr(k)) - y(k);
Ybus(nr(k),nl(k)) = Ybus(nl(k),nr(k));
end
end
for n = 1:nbus % formation of the diagonal elements
for k = 1:nbr
if nl(k) == n | nr(k) == n
Ybus(n,n) = Ybus(n,n) + y(k);
else, end
end
end
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!