Created
February 14, 2020 18:51
-
-
Save aj07mm/40e88dea94ca65f2ac22e5ec334b063e to your computer and use it in GitHub Desktop.
solve.scm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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