-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex354.scm
83 lines (64 loc) · 1.85 KB
/
ex354.scm
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
; Answers for 3-5-4
(load "ex352.scm")
(define (integral delayed-integrand initial-value dt)
(define int
(cons-stream initial-value
(let ((integrand (force delayed-integrand)))
(add-streams (scale-stream integrand dt)
int))))
int)
(define (solve f y0 dt)
(define y (integral (delay dy) y0 dt))
(define dy (stream-map f y))
y)
; Exercise 3.77
(define (integral delayed-integrand initial-value dt)
(cons-stream initial-value
(let ((integrand (force delayed-integrand)))
(if (stream-null? integrand)
the-empty-stream
(integral (delay (stream-cdr integrand))
(+ (* dt (stream-car integrand))
initial-value)
dt)))))
; Exercise 3.78
(define (solve-2nd a b dt y0 dy0)
(define y (integral (delay dy) y0 dt))
(define dy (integral (delay ddy) dy0 dt))
(define ddy (add-streams (scale-stream dy a)
(scale-stream y b)))
y)
; Exercise 3.79
;; todo: I need to look up second-order differential equations. ...
; Exercise 3.80
(define (RLC R L C dt)
(lambda (vC0 iL0)
(define vC (integral (delay dvC) vC0 dt))
(define iL (integral (delay diL) iL0 dt))
(define diL (add-streams (scale-stream iL (- (/ r L)))
(scale-stream vC (/ 1 L))))
(define dvC (scale-stream iL (- (/ 1 C))))
(cons vC iL)))
(define exampleRLC ((RLC 1 1 0.2 0.1) 10 0))
;; 1 ]=> (show 10 (car exampleRLC))
;; 10
;; 10
;; 9.5
;; 8.55
;; 7.220000000000001
;; 5.5955
;; 3.77245
;; 1.8519299999999999
;; -.0651605000000004
;; -1.8831384500000004
;; 1 ]=> (show 10 (cdr exampleRLC))
;; 0
;; 1.
;; 1.9
;; 2.66
;; 3.249
;; 3.6461
;; 3.84104
;; 3.834181
;; 3.6359559
;; 3.2658442599999997