Created
December 22, 2011 04:20
-
-
Save manishym/1508906 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 )) | |
(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