Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created December 5, 2012 09:09
Show Gist options
  • Save yao2030/4214099 to your computer and use it in GitHub Desktop.
Save yao2030/4214099 to your computer and use it in GitHub Desktop.
(define (integral f a b n)
(define h (/ (- b a) n))
(define (i-next x) (+ x 1))
(define (i-term x)
(cond ((or (= x 0) (= x n)) (f (+ a (* x h))))
((even? x) (* 2 (f (+ a (* x h)))))
(else (* 4 (f (+ a (* x h)))))))
(* (/ h 3) (sum i-term 0 i-next n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment