Skip to content

Instantly share code, notes, and snippets.

@jfacoustic
Created October 11, 2020 15:21
Show Gist options
  • Save jfacoustic/ebed34f5479af262bf2ae615b5c13901 to your computer and use it in GitHub Desktop.
Save jfacoustic/ebed34f5479af262bf2ae615b5c13901 to your computer and use it in GitHub Desktop.
1.29 SICP
(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