2024-08-20 14:45:14 +00:00
|
|
|
(define (sqrt_iter new_guess last_guess x)
|
|
|
|
(if (good_enough? new_guess last_guess)
|
|
|
|
new_guess
|
|
|
|
(sqrt_iter (improve new_guess x) new_guess x)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (improve guess x)
|
|
|
|
(/ (+ guess (/ x guess)) 2))
|
|
|
|
|
|
|
|
|
|
|
|
(define (good_enough? guess last_guess)
|
|
|
|
(< (absolute (- guess last_guess)) 0.000000000000001))
|
|
|
|
|
|
|
|
(define (absolute x)
|
|
|
|
(if (< x 0)
|
|
|
|
(- 0 x)
|
|
|
|
x))
|
|
|
|
|
|
|
|
(define (sqrt x) (sqrt_iter (/ x 2.0) x x))
|
|
|
|
|
2024-09-02 14:22:04 +00:00
|
|
|
(print (sqrt 10))
|