(wat-aro)

無職から有職者にランクアップしました

SICP 問題1.8

ニュートン法で立方根を求める 
 

(define (cube-root-iter guess x)
  (if (good-enough? guess x)
      guess
      (cube-root-iter (cube-improve guess x)
                 x)))

(define (cube-improve guess x)
  (/ (+ (/ x
           (square guess))
        (* 2 guess))
     3))

(define (good-enough? guess x)
  (< (abs (- 1.0 (/ guess (cube-improve guess x)))) 0.001))

(define (cube-root x)
  (cube-root-iter 1.0 x))