Add 1.8
This commit is contained in:
parent
3d0a35684d
commit
8d27dd2d10
|
@ -0,0 +1,23 @@
|
|||
(define (square x) (* x x))
|
||||
|
||||
(define (cubic-iter guess guess-prev x)
|
||||
(if (good-enough? guess guess-prev)
|
||||
guess
|
||||
(cubic-iter (improve guess x) guess
|
||||
x)))
|
||||
|
||||
(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)
|
Loading…
Reference in New Issue