forked from jsoftware/labs_labs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircuittheoryii.ijt
2288 lines (1791 loc) · 70 KB
/
circuittheoryii.ijt
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
LABTITLE=: 'Circuit Theory II'
LABAUTHOR=: 0 : 0
John C. Wilson
Comments to J Forum or [email protected]
)
LABDEPENDS=: 'math/lapack plot'
NB. =========================================================
Lab Chapter Introduction to part II
NB. =========================================================
Lab Section Outline
Circuit Theory I dealt with the mathematical definition of a
circuit (as a function) and with the operations by which new
circuits may be created from old ones.
Circuit Theory II suggests a taxonomy or classification of
circuits according to their special properties (i.e.,
according to their external behaviour rather than their
internal composition). Realization (or synthesis) questions
are also addressed.
A final chapter considers some conventionally acceptable
circuits that are not circuits in this theory.
)
PREPARE
NB. Definitions from Circuit Theory I
ures =: (- |.)"1 NB. a circuit (unit resistor)
rci =: ({~ (?@#)) "1 NB. random choice of an item from vector
qc =: rci @ i: "0 NB. random choice from i:n
rac =: qc @: $ ~ "0 1 NB. random array of shape y from i: x
ra =: 2&rac "1 NB. random array of shape y from i: 2
res =: ures : (*ures) NB. resistor
dp =: +/ . * NB. dot product
M =: >1 _1 0; 1 3 _4; _2 _2 4
ex14 =: M&dp "1 NB. 3-terminal circuit
zero =: 0"0 NB. The open circuit
sq =: *: NB. square
n2 =: (+,-) @ sq @ (-/) "1 NB. a 2-terminal nonlinear circuit
sort =: /:~
ramp =: (-sort)"1 NB. n-terminal circuit
load 'plot'
plot3 =: conjunction : '''surface'' plot m&{&.tr v"1 >{y'
tr =: |: NB. transpose
load 'numeric'
mean =: +/ % # NB. arithmetic mean
cf =: -mean NB. circuit: centering function
diff =: - 1&|. NB. circuit: differencer
sq =: *: "1
cube =: ^&3
VOLS =: */\
c2c =: cf@sq@cf
c3c =: cf@cube@cf
mc3c =: -@c3c
d3c =: diff@cube@cf
md3c =: -@d3c
cvd =: cf@VOLS@diff
ics =: 6 _2 _4 "1 NB. A 3-terminal current source
ans =: , (- @ (+/)) NB. append neg sums
trig =: ans @ sq @ (1 2&o.) @ (3 _2 _1&dp)
P =: > 1 1 2 0 _1 0; 0 _1 _1 _1 1 0; _1 0 _1 1 0 0
Q =: > 2 _1 _1; _1 2 _1; _1 _1 2
ex18 =: (P&dp)@(,sq)@(dp&Q)
exp =: ^"1
P =: _1e_6 * >40 _38 _2; _38 50 _12; _2 _12 14
Q =: _40 * > 1 0 0; 0 1 0; _1 _1 0
npn =: (P&dp)@exp@(dp&Q) NB. transistor
P =: _1e_11* >1 _1; _1 1
Q =: _40* >1 0;_1 0
diode =: (P&dp)@exp@(dp&Q) NB. diode
sc =: 1e6&res NB. A 2-terminal short circuit
vccs3 =: (> 0 0 0; 1 0 _1; _1 0 1)&dp
vccs4 =: (> 0 0 0 0;0 0 0 0;1 _1 0 0;_1 1 0 0)&dp
Grad =: adverb : 'tr@(u D.1)' NB. Gradient
mea =: >./@: | @ , NB. max |element of an array
dbm =: % mea NB. divide array by max elt
Apprx =: conjunction : 0
J =. (u f.)Grad n
b =. (u n)-J dp n
(b&+)@(J&dp)
)
Nia =: adverb : '- ((0.1&*)@((u %.(u f. Grad))))'
Newton =: adverb : 'u f. Nia^:_' NB. Newton solution
solve =: adverb : '(u,(+/))f. Newton'
iv14 =: ics + vccs3 + ex14
id =: =&i. NB. identity matrix
matrix =: conjunction : 'tr u"1 id n'
transpose =: conjunction : '((u"1 id n)&dp)"1'
under =: conjunction : '(v f. transpose(#y))@u@v y'
map =: conjunction : '(u f.)under(n&{)'
rvd =: ((2&res)map 0 1)+(vccs4 map 1 2 0 2)+(diff map 2 1 0)
twores =: (2&res map 1 2)+(res map 0 1)
tir =: (2&res map 0 1)+(res map 2 3)
apply =: 128!:2
CFL =: &((+/)@:apply) NB. adverb: Circuit From Listing
interc =: conjunction : 0 NB. g interc t
z =. (#y)$0 NB. eg, (g0`g1`g2)interc(t0;t1;t2)
for_k. n do.
z =. z+((u @. k_index)f. map(>k_index}n))y
end.
)
eachg =: adverb : 0 NB. "each" for gerunds
z =. (#y)$,:<0 NB. eg, (f0`f1`f2)eachg(y0;y1;y2)
for_k. y do.
t =. (u @. k_index)&.> k
z =. t k_index}z
end.
)
expand =: #^:_1
r1b =: (,@[ expand ]) ($~ $) [ NB. replace 1's in boolean x by y
ti =: (2&!)^:_1 NB. inverse of triangular numbers
ut =: </~ & i. NB. upper triangular matrix
setut =: ut@ti@# r1b ]@- NB. set upper triangle to y
insdiag =: + (id@# r1b -@(+/)) NB. add (-+/y) into the diag of y
szm =: insdiag@(+ tr)@setut NB. symmetric 0-sum matrix
rzv =: zsv@ra NB. rzv s random zero sum vector of length s
NB. or random zero column sum matrix
zsv =: (*#) -"1 +/ NB. make zero sum (integer from integer arg)
rzm =: zsm@ra NB. rzm s: random zero sum matrix of shape s
zsm =: zsv&.tr @ zsv NB. zsm M: make zero sum matrix from M
rcrsm =: qc@:(0&{) + tr@rzv@:|. NB. rndm cst row sum matrix
restr1 =: conjunction : 0 NB. restriction of g to t
't s' =. n
g =. u f.
vt =. y
v =. (/:&(t,s))@(vt&,) NB. v as a fn of vs
vs =. (((s&{)@g@v f.)Newton) 0"0 s
ct=. (t&{)@g@v vs
vs;ct NB. returns both vs and ct
)
restr =: conjunction : '(1&pick)@(u f. restr1 n)'
NB. End of definitions from Circuit Theory I
NB. Circuit Theory II: Passive & linear
pwr =: adverb : 'dp u' NB. The power absorbed by a circuit
Tfm =: dyad : '(tr y)dp x dp y'
sum =: (+each)/
Interc =: conjunction : '>@sum x Tfm each y'
pind =: <each @{@ ,~ @ < NB. partitioning indices
pmat =: pind@] {each <@[ NB. partitioned matrix
require '~addons/math/lapack/lapack.ijs'
require '~addons/math/lapack/dgeev.ijs'
eiv =: >@(1&{)@dgeev_jlapack_ NB. compute eigenvalues
eivs =: eiv@(] ..tr) NB. eivs G <-> eiv(G+tr G)%2
conn =: |."1 @ ($ (#.^:_1) i.@(*/@$)) NB. connections
cmpv =: ":"0 @, NB. component values
info =: ('&*@vccs3 map '&,)"1 NB. constant info
RLC =: (cmpv,.info @ ": @(conn ,. #))@(_1 _1&}.)
apply =: 128!:2
CFL =: &((+/)@:apply) NB. adverb: Circuit From Listing
NB. Solution & restriction of Batteries & linears
pivot=: 4 : 0 NB.(row,col) pivot M
'r c'=. x
col =. c{"1 y
y - (col-r=i.#y) */ (r{y)%r{col
)
rswap =: 4 : '(|. x{y) x}y' NB. swap rows of matrix y
ima =: $ #: imar NB. index of max abs
imar =: (i. max)@avr NB. index of max abs of ravel
avr =: | @, NB. absolute value of ravel
max =: >./ NB. maximum item
iszero =: >: -: 1"0
Show =: (1!:2)&2 NB. Write y to screen
NB. Gb Solve t
Solve =: dyad : 0
G =. x [ t =. y
s =. (i.#G) -. t
r =. ((-.&>)~/)@((i. each)@$) G
p =. 0#0
while. 0<#s do.
ijs =. (ima (<s;s){G){s NB. si,sj
if. iszero (<ijs){G do. break. end.
G =. ijs rswap G NB. swap rows si and sj
sj =. 1{ijs
G =. (sj,sj) pivot G
p =. p, sj NB. move sj from s to p
s =. s -. sj
end.
q =. s
if. -. iszero (<q;t,r){G do. msg =. 'No Vs exists'
elseif. -. iszero (<t;q){G do. msg =. 'Ct is not unique'
elseif. do. msg =. ''
end.
G;t;p;q;r;msg
)
Restr =: dyad : 0
'H t p q r msg' =. x Solve(,y)
if. msg -: '' do.
(<t;t){H
else.
Show H pfm (t;p;q);<(t;p;q;r)
Show ('t= ',":t),('; p= ',":p),('; q= ',":q),('; r= ',":r)
msg assert 0
end.
)
Restrb =: dyad : 0
'H t p q r msg' =. (,.&>/x)Solve(,y)
if. msg -: '' do.
((<t;t){H) ; ((<t;r){H)
else.
Show H pfm (t;p;q);<(t;p;q;r)
Show ('t= ',":t),('; p= ',":p),('; q= ',":q),('; r= ',":r)
msg assert 0
end.
)
Solveb =: monad : 0
'H t p q r msg' =. (,.&>/y)Solve 0#0
if. msg -: '' do.
-,r{"1 H NB. Taking q{v to be 0. (It is arbitrary).
else.
Show H pfm (t;p;q);<(t;p;q;r)
Show ('t= ',":t),('; p= ',":p),('; q= ',":q),('; r= ',":r)
msg assert 0
end.
)
NB. Bilaterals
sut =: (,@ut@%:@#)# ] NB. select upper triangle
cmpv2 =: cmpv@:-@sut@, NB. component values
conn2 =: sut@($ #.^:_1 i.@(*/@$)) NB. connections
info2 =: ('&res map '&,)"1 NB. constant info
RRC =: cmpv2,.info2 @ ": @ conn2
NB. Gyrators
ans =: ,(-@(+/)) NB. append neg sums
border =: (ans"1)@ans NB. border with negative sums
sszm =: border @ (- tr) @ setut NB. create skew symm 0-sum matrix
NB. from -(truncated upper tri)
gyrator =: sszm@[ dp ]
info3 =: ('&gyrator map '&,)"1 NB. constant info
RGY =: (cmpv2,.info3 @ ": @(conn2 ,. #)) @ (_1 _1&drop)
NB. Ideals
a =: 1e9
sc =: a&res NB. short circuit
V =: 6
f =: (V*_1 1)"1 + res NB. battery
b =: 1e9
sixvolts =: b&*@f NB. 6-volt source (approx)
R =: >1 _1;_1 1
Res =: ; @: (,.each/"1) @: (R&*each) NB. "array of resistors"
n =: 10 NB. transformer ratio
T =: Res 2 2$ 1,(-n),(-n),n^2
b =: 1000
transformer =: (b&*)@(T&dp) NB. approx transformer
PREPARE
NB. =========================================================
Lab Section Classification of circuits
In the next series of chapters we introduce several classes
of circuits. They are all characterized by extra conditions
on the mapping beyond the current and voltage conditions. All
of the classes we consider have the property of being closed
under the operations of interconnection and restriction; that
is, every interconnection of members of a class is also a
member of the class, and a similar statement applies to
restriction.
This part is somewhat theoretical. That is the point: with
the "function" model of circuits, precise theoretical
statements are possible. There are many theorems stated in
this part without proof. You are expected to supply the
proofs, or at least perform enough experiments to convince
yourself of their truth.
We begin with passive circuits.
)
NB. =========================================================
Lab Chapter Passive circuits
NB. =========================================================
Lab Section Power absorbed by a circuit
The combination of a voltage v and a current c can be
maintained only by doing work at a certain rate (i.e., by
supplying power) equal to v dp c .
Definition. The power absorbed by an n-terminal circuit g
is the scalar-valued funtion g pwr whose value at v is
v dp g v .
Here for example is the power absorbed by the circuit ex14
at the voltage 6 3 _1.
)
pwr =: adverb : 'dp u' NB. The power absorbed by a circuit
v =: 6 3 _1
ex14 pwr v
v dp ex14 v
NB. =========================================================
Lab Section Power is insensitive to voltage reference level
Prove and illustrate the following theorems.
Theorem. Let g be an n-terminal circuit. Then for every
n-element vector v and scalar a ,
(g pwr v+a)-:(g pwr v)
Both of the current and voltage laws are used in the proof,
even though the statement looks a lot like just the voltage
law.
)
ex14 pwr v
ex14 pwr v+4.56
NB. =========================================================
Lab Section Power of a sum
Theorem. If f and g are n-terminal circuits then
(f+g)pwr -: (f pwr)+(g pwr) .
)
v =: 0 5 0.25
(ex14+npn)pwr v
(ex14 pwr v)+(npn pwr v)
NB. =========================================================
Lab Section Power of a transformed circuit
Theorem. If g is an n-terminal circuit and f is a
u-preserving linear function from Rm to Rn then
(g under f)pwr -: (g pwr)@f .
Corollary.
(g map t)pwr -: (g pwr)@(t&{) .
)
f =: (rcrsm 3 4)&dp NB. u-preserving linear function
g =: diff NB. sample circuit
v =: 2 3 8 0 NB. random voltage
(g under f) pwr v
(g pwr)@f v
(g pwr) f v
t =: 0 3 2
(g map t)pwr v
(g pwr)@(t&{)v
(g pwr) t{v
NB. =========================================================
Lab Section Definition: passive circuit
Definition. An n-terminal circuit g is passive if and only
if the power absorbed by it is never negative; i.e., for
every vector v,
(g pwr v) >: 0 .
We say that g is active if it is not passive.
)
*./ >:&0 (diff pwr"1) ra 100 4 NB. diff is passive
*./ >:&0 (vccs3 pwr"1) ra 100 3 NB. vccs3 is active
NB. =========================================================
Lab Section Examples of power
Exercise. Plot the power function of the 2-terminal
resistor res and observe that the resistor is a passive
device.
Exercise. Plot the power function for other 2-terminal
circuits such as diode and n2 . Are they passive?
)
v1 =: steps _1 1 30
p =: (res pwr"1)0,.v1
plot v1;p
NB. =========================================================
Lab Section
Exercise. Show theoretically that the voltage-controlled
current source vccs3 is active.
Exercise. Plot the power function of vccs3 . To reduce this
to a 3-dimensional problem, let v2 be zero (why is this
justified?).
)
v0 =: v1 =: steps _1 1 30
0 plot3 (,:@:(vccs3 pwr"1)) v0;v1;0
NB. (To get plot3 to work on a scalar-valued function
NB. it is necessary to add an axis to the result.)
NB. =========================================================
Lab Section Transistor
Exercise. Show that the transistor npn is passive. Can you
do it theoretically? At least plot the power function: start
your exploration near the origin and expand from there.
Exercise. Show that the approximation to the transistor,
npn Apprx p (let p=: 0 5 0.2 , for example), is active. Is
there an inconsistency here? Is this why some references say
the transistor is active and some say it is passive?
)
vc =: steps _0.01 0.01 30 NB. collector voltage
vb =: steps _0.01 0.01 30 NB. base voltage
0 plot3 (,:@:(npn pwr"1)) 0;vc;vb
NB. =========================================================
Lab Section Closure theorems
The following are the closure theorems for passive circuits.
Prove them.
Theorem. Every sum of passive circuits is passive.
Theorem. If g is passive and f is a u-preserving linear
function then (g under f) is passive.
Exercise. Disprove: If (g under f) is passive then g is
passive.
Theorem. If g is passive then (g map t) is passive.
Theorem. Every interconnection of passive circuits is
passive.
Theorem. Every restriction of a passive circuit is passive.
)
NB. =========================================================
Lab Section The derivative of the power function of a circuit
Let f be a function mapping n-element vectors into scalars.
Then (f Grad) is a function which maps n-element vectors into
n-element vectors. A critical point v of f is a point such
that (f Grad v) = o where o =: 0"0 v . A critical point
locates a potential extremum of f .
Theorem. The derivative at v of the power absorbed by a
circuit g is (g v)+v dp(g Grad)v .
Corollary. The critical points v of the power absorbed by a
circuit g satisfy o -: (g v)+v dp(g Grad)v .
Later we will apply this result to the problem of extracting
the maximum power from a battery.
)
NB. =========================================================
Lab Section Conservation of power/Tellegen's theorem
Theorem. The power absorbed by an interconnection of
circuits is the sum of the powers absorbed by the constituent
circuits.
Example. Recall the definition of iv14 .
)
iv14 =: ics + vccs3 + ex14
v =: 2 9 _6
iv14 pwr v
(ics pwr v),(vccs3 pwr v),(ex14 pwr v)
(ics pwr v)+(vccs3 pwr v)+(ex14 pwr v)
NB. =========================================================
Lab Chapter Linear circuits
NB. =========================================================
Lab Section Linear circuit and its matrix
A linear circuit is a linear function, and so it is
completely specified by its matrix.
The matrix of a linear circuit has been referred to in the
literature (in the context of AC networks) as the "indefinite
admittance matrix".
Theorem. The matrix of any linear circuit is a zero-sum
matrix (that is, a matrix whose row and column sums are all
zero).
It follows from the above that there is a 1-1 correspondence
between linear circuits and square, zero-sum matrices. This
idea is an important one. As we will see, the special
classes of linear circuits (reciprocal, passive, resistors,
and so on) correspond to special classes of 0-sum matrices.
)
V =: ra 1000 3 NB. 1000 random voltages
a =: ra 1000 NB. 1000 random coefficients
(ex14 a dp V) -: (a dp ex14"1 V) NB. ex14 is linear
(];(+/);(+/"1)) ex14 matrix 3 NB. a 0-sum matrix
(];(+/);(+/"1)) trig matrix 3 NB. why isn't this 0-sum?
NB. =========================================================
Lab Section Contrast with conventional treatment
By contrast, in conventional treatments of circuit theory the
necessary concern with internal detail leads one author who
is studying linear circuits, for example, to consider
circuits "consisting of positive linear resistors,
independent current and voltage sources and ideal operational
amplifiers modeled by norator-nullator pairs", while another
adds "the four types of linear controlled sources and
negative linear resistors".
)
NB. =========================================================
Lab Section Matrix of a linear circuit
Examples. Many of our previous examples have been linear.
Here are their matrices.
)
(3&res) matrix 2 NB. a 3 mho resistor
vccs3 matrix 3 NB. 3-terminal VCCS
vccs4 matrix 4 NB. 4-terminal vccs
diff matrix 3
cf matrix 4
ex14 matrix 3
zero matrix 1 NB. 1-terminal zero
zero matrix 2 NB. 2-terminal zero
twores matrix 3 NB. two resistors in series
tir matrix 4 NB. two isolated resistors
ex14 matrix 3
rvd matrix 3
NB. =========================================================
Lab Section Derivative of a linear circuit
Theorem. The derivative of a linear circuit is its matrix.
)
diff matrix 3
diff Grad ra 3
NB. =========================================================
Lab Section transpose of a circuit is a circuit
Theorem. If g is an n-terminal linear circuit then
(g transpose n) is a linear circuit.
)
diff matrix 5
(diff transpose 5) matrix 5
NB. =========================================================
Lab Section Closure theorem: sum
Theorem. If g and h are linear n-terminal circuits with
matrices G and H respectively, then the circuit g+h is linear
and its matrix is G+H .
)
G =: diff matrix 3 NB. matrix of diff
H =: ex14 matrix 3 NB. matrix of ex14
G+H NB. sum
(diff+ex14)matrix 3 NB. matrix of diff+ex14
NB. =========================================================
Lab Section Closure theorem: under
Theorem. If g is a linear circuit with matrix G and f is a
u-preserving linear function with matrix F, then g under f is
a linear circuit and its matrix is (tr F)dp G dp F .
)
f =: (rcrsm 3 4)&dp"1 NB. u-preserving linear function
f 1 1 1 1
(rvd under f)matrix 4 NB. matrix of rvd under f
F =: f matrix 4 NB. matrix of f
G =: rvd matrix 3 NB. matrix of rvd
(tr F)dp G dp F NB. F'.G.F
NB. =========================================================
Lab Section Closure theorem: interconnection
Theorem. Every interconnection of linear circuits is a
linear circuit.
)
NB. Three linear circuits:
g1 =: (>2 _2; _2 2)&dp
g2 =: (>4 _1 _1 _2; _2 3 0 _1; _3 _1 5 _1; 1 _1 _4 4)&dp
g3 =: (>5 _2 _3; _1 3 _2; _4 _1 5)&dp
NB. An interconnection of them:
g =: (g1 map 0 1)+(g2 map 1 2 0 2)+(g3 map 2 1 0)
g ra 3
V =: ra 1000 3 NB. 1000 random voltages
a =: ra 1000 NB. 1000 random coefficients
(g a dp V) -: (a dp g"1 V) NB. g is linear
g matrix 3 NB. matrix of the interconnection
NB. =========================================================
Lab Section Interconnection
We can formulate the interconnection of linear circuits in
terms of their matrices.
)
G1 =: g1 matrix 2
G2 =: g2 matrix 4
G3 =: g3 matrix 3
M1 =: 0 1&{ matrix 3 NB. attachment matrix for g1
M2 =: 1 2 0 2&{ matrix 3 NB. attachment matrix for g2
M3 =: 2 1 0&{ matrix 3 NB. attachment matrix for g3
((tr M1)dp G1 dp M1)+((tr M2)dp G2 dp M2)+((tr M3)dp G3 dp M3)
NB. Compare this with g matrix 3
NB. =========================================================
Lab Section
We can put this in the form of a conjunction:
)
Tfm =: dyad : '(tr y)dp x dp y'
sum =: (+each)/
] G =: G1;G2;G3
] M =: M1;M2;M3
>@sum G Tfm each M
Interc =: conjunction : '>@sum x Tfm each y'
G Interc M NB. matrix of the interconnection
NB. =========================================================
Lab Section Restriction
We next show how the operation of restriction specializes in
the case of linear circuits.
Let g =: G&dp be a linear circuit and let t and s partition
the terminals of g . To find the restriction of g to t we
need to solve the two equations
ct -: t{ g (vt,vs)/:(t,s)
(0"0 s) -: s{ g (vt,vs)/:(t,s)
for vs and ct , given vt . We begin with the first equation.
ct
t{ g (vt,vs)/:(t,s)
t{ G dp (vt,vs)/:(t,s) NB. g =: G&dp
((<t;t,s){G) dp vt,vs NB. reorder G instead of v
(((<t;t){G) dp vt) + (((<t;s){G) dp vs)
(Gtt dp vt) + (Gts dp vs) NB. where Gtt =: (<t;t){G
NB. and Gts =: (<t;s){G
Similarly, the second equation gives
0"0 s
s{ g (vt,vs)/:(t,s)
s{ G dp (vt,vs)/:(t,s) NB. g =: G&dp
((<s;t,s){G) dp vt,vs NB. reorder G instead of v
(((<s;t){G) dp vt) + (((<s;s){G) dp vs)
(Gst dp vt) + (Gss dp vs) NB. where Gst =: (<s;t){G
NB. and Gss =: (<s;s){G
)
NB. =========================================================
Lab Section
So informally, in conventional form,
ct = Gtt.vt + Gts.vs
os = Gst.vt + Gss.vs
where os =: 0"0 s , and the dot represents dp .
The function pmat displays a matrix in partitioned form.
)
] G =: diff matrix 7 NB. matrix of a 7-terminal circuit
t =: 0 1 3 5 [ s =: 2 4 6 NB. partitioning of its terminals
G pmat t;s NB. partitioned matrix
'Gtt Gts Gst Gss' =: ,G pmat t;s
NB. =========================================================
Lab Section
Clearly the second equation has to be solved first for vs and
then the solution substituted into the first equation to get
ct.
If Gss is nonsingular we can easily solve the second
equation. But in general Gss may be singular even though the
restriction exists. This corresponds to the case where vs is
not uniquely determined by vt .
There always exist row operations, and a partitioning of s
into p and q , which will transform these equations into an
equivalent set of equations of the following form:
ct = Htt.vt + Htq.vt
op = Hpt.vt + vp + Hpq.vp
oq = Hqt.vt
where op =: 0"0 p and oq =: 0"0 q .
Either p or q may be empty. (The case where q is empty is the
case where Gss is nonsingular.)
)
NB. =========================================================
Lab Section
The function Solve produces the required transformation.
)
'H t p q r msg' =: G Solve t
H pmat t;p;q
NB. =========================================================
Lab Section
Now there exist solutions vs (i.e., vp and vq ) for every vt
if and only if Hqt is zero and then
vp
-((Hpt dp vt) + (Hpq dp vq))
-(%.Gpp)dp((Gpt dp vt) + (Gpq dp vq))
Finally it is clear that ct depends only on vt (and not on
vs) if and only if Htq is zero and then
ct
Htt dp vt
(Gtt - Gtp dp(%.Gpp)dp Gpt) dp vt
Since this relationship is linear, we have proved
Theorem. Every restriction of a linear circuit is a
linear circuit.
)
NB. =========================================================
Lab Section
In the above example there is no problem: q is empty. There
is a unique value of vt for every vt and c depends only on
vt.
The matrix of the restriction of G&dp to t is Htt. The
function Restr extracts that from Solve.
)
'Htt Hts Hst Hss' =: ,2 2$,H pmat t;p;q
Htt
G Restr t
NB. =========================================================
Lab Section Failure of restriction (1)
In the example below, Hqt is not zero and so no solution
exists. That is, for an arbitrary value of vt there are no
values of vs that satisfy the second equation.
)
] G =: x: >2 0 _1 _1; _4 1 4 _1; 0 _1 3 _2; 2 0 _6 4
t =: 0 1 [ s =: 2 3
'H t p q r msg' =: G Solve t
H pmat t;p;q
msg
NB. =========================================================
Lab Section Failure of restriction (2)
Here is another example.
)
] G =: x: >2 0 _1 _1; _2 _1 4 _1; 0 _1 3 _2; 0 2 _6 4
t =: 0 1 [ s =: 2 3
'H t p q r msg' =: G Solve t
H pmat t;p;q
msg
NB. =========================================================
Lab Section
In this case, solutions exist for vp , specifically
vp -: - (0 _1r3 dp vt) + _2r3*vq
for every scalar vq , but since Hts is not zero, ct is not
uniquely determined by vt . Therefore once again the
restriction of G to t does not exist.
)
NB. =========================================================
Lab Section Suppressing isolated terminals
Here is an example where the restriction is obvious.
)
] G =: x: >4 _1 _3 0 0;_2 3 _1 0 0;_2 _2 4 0 0;0 0 0 0 0;0 0 0 0 0
t=: 0 1 2 [ s =: 3 4
NB. =========================================================
Lab Section
In this case there is nothing to be done. The restriction of
G to t exists and its matrix is just Gtt .
)
'H t p q r msg' =: G Solve t
H pmat t;p;q
G Restr t
NB. =========================================================
Lab Section Passivity in linear circuits
The next theorem gives a test for passivity in linear
circuits.
Theorem. The linear circuit G&dp is passive if and only if
every eigenvalue of -:(G+tr G) is nonnegative.
Proof. By definition, G&dp is passive if and only if for
every n-element vector v , (v dp G dp v) >: 0
Now
v dp G dp v
tr v dp G dp v NB. tr scalar
v dp(tr G)dp v
-:(v dp G dp v)+(v dp(tr G)dp v) NB. half sum of equals
v dp(-:G+tr G)dp v
It is a standard result of linear algebra that the last
expression is nonnegative for every v if and only if all of
the eigenvalues of -:G+tr G (a real, symmetric matrix) are
nonnegative.
Remark. One eigenvalue of a 0-sum matrix G is always 0 since
(G dp u) -: 0*u where u is a vector of 1's.
In J we can use the eigenvalue finder in the addon "lapack":
)
require '~addons/math/lapack/lapack.ijs'
require '~addons/math/lapack/dgeev.ijs'
eiv =: >@(1&{)@dgeev_jlapack_ NB. compute eigenvalues
eivs =: eiv@(] ..tr) NB. eivs G <-> eiv(G+tr G)%2
NB. =========================================================
Lab Section
We can check the passivity of the linear circuits we have seen so far.
)
NB. A 1 mho resistor
eivs (1&res)matrix 2
NB. The eigenvalues are 0 and 2. The device is passive.
NB. A _1 mho resistor
eivs (_1&res)matrix 2
NB. The eigenvalues are 0 and _2 . The device is active.
NB. Two resistors.
eivs twores matrix 3
NB. The eigenvalues are 0 , 3-*3 and 3+*3 . The device is passive.
NB. The zero device
eivs zero matrix 1
NB. The only eigenvalue is 0 . The device is passive.
NB. Three-terminal voltage-controlled current source, vccs3
eivs vccs3 matrix 3
NB. The eigenvalues are 0 , _1r2 and 3r2 . Therefore vccs3 is active.
NB. The 3-terminal version of diff is a passive circuit.
eivs diff matrix 3
NB. =========================================================
Lab Section
Exercise. Is diff of valence n passive for all n?
)
NB. =========================================================
Lab Section
Exercise. Let g be an n-terminal linear circuit. Prove that
(g transpose n)pwr -: g pwr
)
NB. =========================================================
Lab Section
Theorem. A linear circuit is active if its matrix has a
negative diagonal element.
Proof. Let G be a linear circuit. Suppose the k th diagonal
element (<k,k){G is negative. Let v be a vector whose only
nonzero element is a 1 in the k th position. Then
v dp G dp v
(<k,k){G
which is negative, so G is active.
Exercise. Create an example.
)
NB. =========================================================
Lab Section
The absence of negative diagonal elements is not a guarantee
of passivity. For example the following circuit is active.
)
] G =: > 1 2 _3;_3 0 3; 2 _2 0
v =: 0 1 _1
v dp G dp v
eivs G NB. 0 , _1r2 and 3r2
NB. =========================================================
Lab Section Realization of linear circuits
We next consider the problem of realizing a given linear
circuit in terms of other circuits (a synthesis problem).
Theorem. Every linear circuit of valence 3 or more has a
realization as an interconnection of multiples of the
3-terminal voltage-controlled current source.
Proof. The proof is constructive. Let G be the matrix of an
n-terminal linear circuit (n>:3). G is determined by the
values of its first n-1 rows and columns. We create a circuit
whose matrix is G by interconnecting components: one
component for each element of _1 _1 drop G . This is done by
observing that for i<n-1 and j<n-1 the n x n matrix of
vccs3 map(i,j,n-1)
has a 1 in element (j,i) and other nonzero entries
only in the nth row and column. Here is a program that does
just that, listing the components that result.
)
conn =: |."1 @ ($ (#.^:_1) i.@(*/@$)) NB. connections
cmpv =: ":"0 @, NB. component values
info =: ('&*@vccs3 map '&,)"1 NB. constant info
RLC =: (cmpv,.info @ ": @(conn ,. #))@(_1 _1&}.)
NB. =========================================================
Lab Section
In the example, compare the list of components with the
elements in the first 3 rows and columns of G.
)
] G =: > 3 _1 2 _4;_2 1 1 0; 0 2 4 _6;_1 _2 _7 10
RLC G
NB. =========================================================
Lab Section
It is emphatically not claimed that this is a particularly
good realization. One obvious improvement would be to filter
the output to remove zero circuits.
Exercise. Notice that several components in the above example
are connected in a way that shorts together the first two
terminals of a vccs3. Prove that the result is a resistor.
)
NB. =========================================================
Lab Section Circuit from listing
We can check the claim that this program produces G&dp .
First we define operations apply and CFL that are useful
in creating a circuit from a listing of its components.
)
apply =: 128!:2
CFL =: &((+/)@:apply) NB. adverb: Circuit From Listing
NB. =========================================================
Lab Section