Skip to content

Instantly share code, notes, and snippets.

@manishym
Created December 22, 2011 06:02
Show Gist options
  • Save manishym/1509146 to your computer and use it in GitHub Desktop.
Save manishym/1509146 to your computer and use it in GitHub Desktop.
Cube root by newton's method
(defun my-cube-rt (x)
(labels (
(try (guess)
(let ((improved (improve guess)))
(if (good-enough? guess improved)
improved
(try improved))))
(improve (guess)
(/ (+ (/ x (square guess)) (* 2 guess)) 3))
(good-enough? ( guess improved)
(if (< (abs (- 1 (/ guess improved))) eps )
improved
nil)))
(try 1.0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment