数値積分のシンプソンの公式
SICPの問題1.29です。
(define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b)))) (define (integral f a b n) (let* ((h (/ (- b a) n)) (inc (lambda (x) (+ x 1))) (term (lambda (k) (cond [(or (= k 0) (= k n)) (f (+ a (* k h)))] [(odd? k) (* 4 (f (+ a (* k h))))] [else (* 2 (f (+ a (* k h))))])))) (* (sum term 0 inc n) (/ h 3.0))))