Trying out exercises from "Structure and Interpretation of Computer Programs" second edition
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.

23 lines
508 B

(define (square x) (* x x))
(define (cubic-iter guess guess-prev x)
(if (good-enough? guess guess-prev)
(cubic-iter (improve guess x) guess
(define (improve guess x)
(average (* 2 guess) (/ x (square guess))))
(define (average x y)
(/ (+ x y) 3))
(define (good-enough? guess guess-prev)
(< (abs (- guess guess-prev)) 0.001))
(define (cubic-root x)
(if (= x 0) x (cubic-iter 1.0 999 x)))
(cubic-root 1892379832.0)
(cubic-root 8.0)
(cubic-root 27.0)