-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComp_N2N_node_elim2.m
More file actions
199 lines (186 loc) · 6.29 KB
/
Comp_N2N_node_elim2.m
File metadata and controls
199 lines (186 loc) · 6.29 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
%% Generate test values
clear all;
%%inputs
f = 50; %frequency 5 Hz
N = [5 6;4 95;42 7;95 5;42 52; 94 54; 44 92; 96 94];
N_wi = [1 0 0 1;1 0 1 0;1 1 0 1; 0 1 0 1;1 0 1 1; 0 1 1 1; 1 1 1 0; 0 1 1 0];
R = [41 20 45 22; 93 21 97 24;39 68 45 72; 93 66 97 70 ];
val_R = [3 2 5 4];
C = [];
val_C = [];
V = [6 47 6;65 53 5];
% voltages are positive on upper side and also on the left side ie. [+ -]
% or [+
% -]
val_V = [3 4];
L = [];
val_L = [];
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1-> right
%2-> left
%3-> up
%4-> down
% N -> contains (only orthogonal intersctions)nodes of the form (x,y)
% R,C,L -> contains diagonal corners (x1,y1,x2,y2)
% V -> contains centre of the voltage sources and radius (x,y,r)
% N_wi -> contains 4 columns correspondng to each direction and they will
% be 1 if there is a wire in that direction and will be 0 otherwise (right left up down)
% val_R,val_C,val_L,val_V -> contains values of corresponding R,C,L,V
% outputs
% du_N -> a matrix containing duplicate nodes clubed together,number of
% different nodes = size(du_N,1). The node numbers corresponding to the
% input matrix are given from the 2nd colum of each row. The first column
% of each row gives the number of duplicate nodes in each cluster
% Z_N,V_N -> and n*n matrix where element (i,j) gives the impedence and voltage source connected
% between node i & j
% adj_N -> element (i,j) is 1 if there is a connection between node i and j
du_N = ones(size(N,1),1);
du_N(:,2) = 1:size(N,1);
% finding reactance of C and L
for i = 1:size(val_C,2)
val_C(i) = -(1/(2*pi*f*val_C(i)))*(i);
end
for i = 1:size(val_L,2)
val_L(i) = (2*pi*f*val_C(i))*(i);
end
if(size(R,1)~=0)
Rp = [(R(:,1)+R(:,3))/2 (R(:,2)+R(:,4))/2];
end
if(size(C,1)~=0)
Cp = [(C(:,1)+C(:,3))/2 (C(:,2)+C(:,4))/2];
end
if(size(L,1)~=0)
Lp = [(L(:,1)+L(:,3))/2 (L(:,2)+L(:,4))/2];
end
Vp = V(:,1:2);
r_m = mean(V(:,3));
Z_N = zeros(size(N,1));
V_N = zeros(size(N,1));
%making window for nodes
for i=1:size(N,1)
w_N(i,:) = [N(i,1)+r_m N(i,2)+r_m N(i,1)-r_m N(i,2)-r_m ];
end
%making window for voltage source
for i=1:size(V,1)
w_V(i,:) = [V(i,1)+V(i,3) V(i,2)+V(i,3) V(i,1)-V(i,3) V(i,2)-V(i,3) ];
end
clear V;
V = w_V;
%matrix with centre points of everything in the circuit
p_CO = N;
if(size(R,1)~=0)
p_CO(size(p_CO,1)+1:size(p_CO,1)+size(Rp,1),:) = Rp;
end
if(size(C,1)~=0)
p_CO(size(p_CO,1)+1:size(p_CO,1)+size(Cp,1),:) = Cp;
end
if(size(L,1)~=0)
p_CO(size(p_CO,1)+1:size(p_CO,1)+size(Lp,1),:) = Lp;
end
p_CO(size(p_CO,1)+1:size(p_CO,1)+size(V,1),:) = Vp;
%matrix with window of everything in the circuit
w_CO = w_N;
if(size(R,1)~=0)
w_CO(size(w_CO,1)+1:size(w_CO,1)+size(R,1),:) = R;
end
if(size(C,1)~=0)
w_CO(size(w_CO,1)+1:size(w_CO,1)+size(C,1),:) = C;
end
if(size(L,1)~=0)
w_CO(size(w_CO,1)+1:size(w_CO,1)+size(L,1),:) = L;
end
w_CO(size(w_CO,1)+1:size(w_CO,1)+size(V,1),:) = V;
%generate matrix with all the values
val_CO = zeros(size(p_CO,1));
val_CO(size(N,1)+1:size(N,1)+size(R,1)) = val_R;
val_CO(size(N,1)+size(R,1)+1:size(N,1)+size(R,1)+size(C,1)) = val_C;
val_CO(size(N,1)+size(R,1)+size(C,1)+1:size(N,1)+size(R,1)+size(L,1)+size(C,1)) = val_L;
val_CO(size(N,1)+size(R,1)+size(C,1)+size(L,1)+1:size(N,1)+size(R,1)+size(L,1)+size(C,1)+size(V,1)) = val_V;
%% compute distance b/w each components and nodes
d_CO = 10000*ones(size(p_CO,1),size(p_CO,1));
o_CO = zeros(size(p_CO,1),size(p_CO,1));
for i =1:size(p_CO,1)
for j =i+1:size(p_CO,1)
d1 = p_CO(i,1)-p_CO(j,1);
d2 = p_CO(i,2)-p_CO(j,2);
%define distance matrix ->distance between everything in the matrix
d_CO(i,j) = sqrt(d1.^2 + d2.^2);
d_CO(j,i) = d_CO(i,j);
%obtaining orientation
%1-> right
%2-> left
%3-> up
%4-> down
if((p_CO(i,1)<max(w_CO(j,1),w_CO(j,3)) && (p_CO(i,1)>min(w_CO(j,1),w_CO(j,3)))))
if(d2>0) %left
o_CO(i,j) = 3;
o_CO(j,i) = 4;
else
o_CO(i,j) = 4;
o_CO(j,i) = 3;
end
elseif((p_CO(i,2)<max(w_CO(j,2),w_CO(j,4))&& (p_CO(i,2)>min(w_CO(j,4),w_CO(j,2)))))
if(d1>0) %left
o_CO(i,j) = 2;
o_CO(j,i) = 1;
else
o_CO(i,j) = 1;
o_CO(j,i) = 2;
end
end
end
end
%%
%we have distance and orientation between each components
N_wi_d = ones(size(N,1),4);
CO_d = zeros(size(p_CO,1),1);
adj_N = zeros(size(N,1),size(N,1));
for i = 1:size(N,1) %checking each node
for j = 1:4 %checking each direction
if(N_wi(i,j)==1 && N_wi_d(i,j)==1)
Z = 0+0i;
V_s = 0;
flag_n = 0;
i1 = i;
while (flag_n ==0)
t_min = 10000;
for k = 1:size(p_CO,1)
if(o_CO(i1,k)== j && d_CO(i1,k)<t_min && k~=i1 && CO_d(k)== 0)
t_min = d_CO(i1,k);
min_ind = k;
end
end
if(min_ind > size(N,1))
CO_d(min_ind) = 1;
if(min_ind > size(p_CO,1)-size(V,1))
V_s = V_s + val_CO(min_ind);
else
Z = Z+val_CO(min_ind);
end
i1 = min_ind;
else
flag_n = 1;
adj_N(i,min_ind) = 1;
adj_N(min_ind,i) = 1;
%if(Z == 0 && V_s ==0)
% Z_N(i,min_ind) = -1;
% Z_N(min_ind,i) = -1;
%else
if(j ==1 || j==4)
V_N(i,min_ind) = -V_s;
else
V_N(i,min_ind) = V_s;
end
V_N(min_ind,i) = -V_N(i,min_ind);
Z_N(i,min_ind) = Z;
Z_N(min_ind,i) = Z;
%end
N_wi_d(i,j) = 0;
N_wi_d(min_ind,j+rem(j,2)-rem(rem(j,2)+1,2)) = 0;
end
end
end
end
CO_d(i) = 1;
end