Exercise 1.8
Use the following approximation to calculate the cube root using the Newton’s Method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | (define (square x) (* x x)) (define (cube x) (* x x x)) (define (good-enough? guess x) (< (abs (- (cube guess) x)) 0.0000001)) (define (improve guess x) (/ (+ (/ x (square guess)) (* 2 guess)) 3)) (define (cubert-iter guess x) (if (good-enough? guess x) guess (cubert-iter (improve guess x) x))) |
1 | (cubert-iter 1 9) |
Value: 2.0800838230519042806950087
1 | (cubert-iter 6.8 8) |
Value: 2.0000000000010389297385368

This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.0 UK: England & Wales License.