SICP問題3.80

直列RLC回路(series RLC circuit)の振る舞いをモデル化する一対のストリームを生成する手続き。これも全然分からないんだけど、図のままに実装。

(define (RLC R C L dt)
  (define (rlc vc0 il0)
    (define vc (integral (delay dvc) vc0 dt))
    (define il (integral (delay dil) il0 dt))
    (define dvc (scale-stream il (/ -1 C)))
    (define dil (add-streams 
                 (scale-stream vc (/ 1 L))
                 (scale-stream il (- (/ R L)))))
    (stream-map (lambda (x y) (cons x y)) vc il))
  rlc)

テスト

(define RLC1 (RLC 1 0.2 1 0.1))
; (stream-ref-range (RLC1 10 0) 0 20)
; (10 . 0)
; (10.0 . 1.0)
; (9.5 . 1.9)
; (8.55 . 2.66)
; (7.220000000000001 . 3.249)
; (5.5955 . 3.6461)
; (3.77245 . 3.84104)
; (1.8519299999999999 . 3.834181)
; (-0.0651605000000004 . 3.6359559)
; (-1.8831384500000004 . 3.2658442599999997)
; (-3.5160605800000004 . 2.750945989)
; (-4.8915335745 . 2.1242453320999997)
; (-5.95365624055 . 1.4226674414399998)
; (-6.66498996127 . 0.6850350732409998)
; (-7.0075074978905 . -0.049967430210100305)
; (-6.982523782785449 . -0.7457214369781403)
; (-6.609663064296379 . -1.3694016715588713)
; (-5.924962228516943 . -1.893427810832622)
; (-4.978248323100632 . -2.296581252601054)
; (-3.829957696800105 . -2.5647479596510117)
; #<undef>