You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
368 B
21 lines
368 B
(define (square x) (* x x)) |
|
|
|
(define (cube x) (* x x x)) |
|
|
|
;; (x / y ^ 2 + 2y) / 3 |
|
|
|
(define (improve y x) |
|
(/ (+ (/ x (square y)) (* 2 y)) 3)) |
|
|
|
(define (good-enough? y old) |
|
(< (abs (- y old)) 0.001)) |
|
|
|
(define (cbrt-iter y old x) |
|
(if (good-enough? y old) |
|
y |
|
(cbrt-iter (improve y x) y x))) |
|
|
|
(define (my-cbrt x) |
|
(cbrt-iter 1.0 x x)) |
|
|
|
(display (my-cbrt 9))
|
|
|