Created
October 11, 2020 15:21
-
-
Save jfacoustic/ebed34f5479af262bf2ae615b5c13901 to your computer and use it in GitHub Desktop.
1.29 SICP
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 (sum term a next b) | |
(if (> a b) | |
0 | |
(+ (term a) | |
(sum term (next a) next b)))) | |
(define (simpson-integral f a b n) | |
(let ((h (/ (- b a ) n))) | |
(define (term n) | |
(define y (f (+ a (* h n)))) | |
(if (even? n) | |
(* 2 y) | |
(* 4 y))) | |
(* (/ h 3) ; return | |
(+ (f a) | |
(f b) | |
(sum term | |
1 | |
(lambda (i) (+ i 1)) | |
(- n 1)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment