Created
April 27, 2015 10:05
-
-
Save lan496/e85c27c4492e985c4bf8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (square x) (* x x)) | |
| (define (cube x) (* x x x)) | |
| (define (abs x) | |
| (if (< x 0) | |
| (- x) | |
| x | |
| ) | |
| ) | |
| (define (improve guess x) | |
| (/ (+ (/ x (square guess)) (* 2 guess)) | |
| 3 | |
| ) | |
| ) | |
| (define (good-enough? guess x) | |
| (< (abs (/ (- (cube guess) x) x)) | |
| 0.00001 | |
| ) | |
| ) | |
| (define (cube-root-iter guess x) | |
| (if (good-enough? guess x) | |
| guess | |
| (cube-root-iter (improve guess x) | |
| x | |
| ) | |
| ) | |
| ) | |
| (define (cube-root x) | |
| (cube-root-iter 1.0 x) | |
| ) | |
| (display (cube-root 8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment