Skip to content

Instantly share code, notes, and snippets.

@aj07mm
Created February 14, 2020 18:51
Show Gist options
  • Save aj07mm/40e88dea94ca65f2ac22e5ec334b063e to your computer and use it in GitHub Desktop.
Save aj07mm/40e88dea94ca65f2ac22e5ec334b063e to your computer and use it in GitHub Desktop.
solve.scm
(define (add-streams s1 s2)
(stream-map + s1 s2))
(define (scale-stream stream factor)
(stream-map (lambda (x) (* x factor)) stream))
(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 dy y0 dt))
; (define dy (stream-map f y))
; y)
(define (solve f y0 dt)
(define y (integral (delay dy) y0 dt))
(define dy (stream-map f y))
y)
(stream-ref (solve (lambda (y) y) 1 0.001) 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment