about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/61a-pages/Lib/resist.scm
blob: 42c0e6bed9a88a0fc0b3cb3b43af0b56f3caaeed (plain) (blame)
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
(define (make-resistor resistance)
  (attach-type 'resistor resistance))

(define (resistor? ckt)
  (eq? (type ckt) 'resistor))

(define (make-series ckt1 ckt2)
  (attach-type 'series (list ckt1 ckt2)))

(define (series? ckt)
  (eq? (type ckt) 'series))

(define (make-parallel ckt1 ckt2)
  (attach-type 'parallel (list ckt1 ckt2)))

(define (parallel? ckt)
  (eq? (type ckt) 'parallel))


(define (resistance ckt)
  (cond ((resistor? ckt)
	 (resistance-resistor (contents ckt)))
	((parallel? ckt)
	 (resistance-parallel (contents ckt)))
	((series? ckt)
	 (resistance-series (contents ckt)))))

(define (conductance ckt)
  (cond ((resistor? ckt)
	 (conductance-resistor (contents ckt)))
	((parallel? ckt)
	 (conductance-parallel (contents ckt)))
	((series? ckt)
	 (conductance-series (contents ckt)))))


(define (resistance-resistor resistor)
  resistor)

(define (conductance-resistor resistor)
  (/ 1 (resistance-resistor resistor)))


(define (resistance-series ckt)
  (+ (resistance (left-branch ckt))
     (resistance (right-branch ckt))))

(define (conductance-series ckt)
  (/ 1 (resistance-series ckt)))

(define (conductance-parallel ckt)
  (+ (conductance (left-branch ckt))
     (conductance (right-branch ckt))))

(define (resistance-parallel ckt)
  (/ 1 (conductance-parallel ckt)))



(define left-branch car)
(define right-branch cadr)
(define attach-type cons)
(define type car)
(define contents cdr)



(define (repeated f n)
  (lambda (x)
    (if (= n 0)
	x
	((repeated f (-1+ n)) (f x)))))

(define (L-extend base series-part parallel-part)
  (make-series series-part (make-parallel parallel-part base)))

(define (ladder-extension stages base series-part parallel-part)
  ((repeated (lambda (x) (L-extend x series-part parallel-part)) stages)
   base))