forked from sustainable-computing/dist_grid_identification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectLoads2Nodes.m
27 lines (22 loc) · 912 Bytes
/
connectLoads2Nodes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function [P,Q] = connectLoads2Nodes(Pn, homesPerNode, startIndex, endIndex, pf)
% FUNCTION connectLoads2Nodes: creates real and reactive power injection vectors
% INPUT:
% Pn: a HOMES by simLength matrix containing individual household loads
% homesPerNode: a vector of size NODES specifying the number of household
% loads aggregated at each bus. Note that sum(homesPerNode) <= HOMES
% startIndex: the start index
% endIndex: the end index
% pf: predefined power factor at each node injecting power
% OUTPUT:
% P: total real power injection for each node
% Q: total reactive power injection for each node
nNodes = length(homesPerNode);
P = zeros(nNodes, endIndex-startIndex+1);
% Q = zeros(nNodes, endIndex-startIndex+1);
ind = 1;
for i=1:nNodes
P(i,:) = sum(Pn(ind:ind+homesPerNode(i)-1,startIndex:endIndex));
ind = ind + homesPerNode(i);
end
%pf = pf * (1+.1*(rand-.5));
Q = sqrt(1/(pf*pf)-1)*P;