Skip to content

Instantly share code, notes, and snippets.

@aoeuidht
Created June 7, 2013 14:33
Show Gist options
  • Select an option

  • Save aoeuidht/5729676 to your computer and use it in GitHub Desktop.

Select an option

Save aoeuidht/5729676 to your computer and use it in GitHub Desktop.
1.30
(defun cube (x) (* x x x))
(defun sum-iter (term a next b)
(defun iter (a result)
(if (> a b)
result
(iter (funcall next a) (+ result (funcall term a)))))
(iter a 0))
(defun simp-integral (f a b n)
(let ((h (/ (- b a) n)))
(defun add-dx (x) (+ x (* 2 h)))
(defun simp-term (a)
(+ (funcall f a)
(* 4 (funcall f (+ a h)))
(funcall f (+ a (* 2 h)))))
(* (/ h 3.0)
(sum-iter #'simp-term a #'add-dx (- b (* 2 h))))
))
(simp-integral #'cube 0 1 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment