-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.8.scm
23 lines (19 loc) · 834 Bytes
/
1.8.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
; --------------------------------------------------------------------------------------------------
; Implement Newton's method for finding cube roots (defined in the book)
; --------------------------------------------------------------------------------------------------
; The heart of the method: returns a closer approximation of the cube root
(define (improve guess target)
(/ (+ (/ target (square guess))
(* 2 guess))
3))
(define (good-enough? guess prev-guess target)
(< (abs (- guess prev-guess))
0.001))
(define (cube-root-iter guess prev-guess target)
(if (good-enough? guess prev-guess target)
guess
(cube-root-iter (improve guess target)
guess
target)))
(define (cube-root target)
(cube-root-iter 1.0 0 target))