1.8 Exercise 1.8
To make this exercise more interesting, I’ve written an iteration procedure which
takes an improve function as an argument. This means that the only difference
between a procedure computing square roots and a procedure computing cube roots is
the choice of improvement function. This generalization is handled differently
later in the chapter.
(I use my previously-defined good-enough? procedure with a good-enough-factor
of 0.001.)
| (define (cube-root x) | | (root-iter x 1.0 0.0 cube-root-improve)) |
|
| (define (root-iter x guess previous-guess improve) | | (if (good-enough? guess previous-guess) guess | | (root-iter x (improve guess x) guess improve))) |
|
| (define (cube-root-improve x guess) | | (/ | | (+ | | (/ x (* guess guess)) | | (* 2 guess)) | | 3)) |
|