(define (cubert x)
(cubert-iter 1.0 x))
(define (cubert-iter guess x)
(if (good-enough? guess x)
guess
(cubert-iter (improve guess x)
x)))
(define (good-enough? guess x)
(< (abs (- (cube guess) x)) 0.001))
(define (cube x) (* x x x))
(define (improve guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))
The thing to notice is that due to appropriate use of procedural abstraction only improve(and good-enough a little bit) is changed between sqrt and cubert.
No comments:
Post a Comment