Created
December 18, 2011 15:27
-
-
Save manishym/1493698 to your computer and use it in GitHub Desktop.
Square root by newtons 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 square-root (x) | |
(labels ( | |
(try (guess) | |
(if (good-enough? guess) | |
guess | |
(try (improve guess))) | |
) | |
(good-enough? (guess) | |
(if (< (abs (- guess (/ x guess))) (eps)) guess nil )) | |
(eps () | |
(* x eps eps)) | |
(improve (guess) | |
(average guess (/ x guess)))) | |
(try 1.0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment