Created
January 17, 2012 01:17
-
-
Save jbochi/1623970 to your computer and use it in GitHub Desktop.
Cube root in lisp (SICP ex 1.8)
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
(define (croot x) | |
(croot-iter 1.00 x)) | |
(define (croot-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(croot-iter (improve guess x) | |
x))) | |
(define (improve guess x) | |
(/ (+ (/ x (square guess)) | |
(* 2 guess)) | |
3)) | |
(define (cube x) | |
(* x x x)) | |
(define (good-enough? guess x) | |
(< (abs (- (cube guess) x)) | |
0.001)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment