Created
December 22, 2011 06:02
-
-
Save manishym/1509146 to your computer and use it in GitHub Desktop.
Cube root by newton's method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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