SICP Solutions - 1.8

Q: Newton's method for cube roots is based on the fact that if y is an approximation to the cube root of x, then a better approximation is given by the value:

Use this formula to implement a cube-root procedure analogous to the square-root procedure. (In section 1.3.4 we will see how to implement Newton's method in general as an abstraction of these square-root and cube-root procedures.)


;; The setup is the same, except for the names.
(define (cbrt-iter guess x)
  (if (good-enough? guess x)
    (cbrt-iter (improve guess x)

(define (cube x)
  (* x x x))

(define (good-enough? guess x)
  (< (abs (- (cube guess) x)) 0.001))

(define (cbrt x)
  (cbrt-iter 1.0 x))

;; The formula in scheme.
(define (improve guess x)
    (+ (/ x (* guess guess)) (* 2 guess))

;; A few guesses.
(display (cbrt 8))
(display (cbrt 27))
(display (cbrt 60))
3.91487458417134 ; My calculator gives 3.91486764117