deleted-page Moved to SICP-solutions Some Exercises I have r2q2 completed.
;;This program computes the cube root of a number. It also is in block structure (define (exercise-1.8 x) (define (good-enough? guess) (< (abs (- (cube guess) x)) 0.0001)) (define (cubert-iter guess) (if (good-enough? guess) guess (cubert-iter (improve guess)))) (define (improve guess) (/ (+ (/ x (* guess guess)) (* 2 guess)) 3)) (define (cube y) (* y y y)) (cubert-iter 1.0))
;;http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_thm_1.11 ;;Note f(n) is in recursive form (define (f n) (cond ((< n 3) n) ((>= n 3) (+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3))))))) ;;Testing (f 0) (f 5) (f 10)
You might try this again after completing exercise 1.7; it has the same problems the sqrt defined in the text has.