Chat (Lingr.com)
Informaiton
Daily
Column
- MySQL日本語の旅(5/1)
- アクセス向上秘伝(5/9)
- 一風変ったHaskellλ門(6/13)
- SICP Answer Book (5/31) 問題3.26追加
Zope Solution
Extra
アーカイブ
OSS案内所
Site Info
関連リンク
##(link2sicp "book-Z-H-10.html#%_thm_1.8" "Exercise 1.8")
解答例
(define (cubic-root-iter old-guess new-guess x)
(if (cubic-good-enough? old-guess new-guess)
new-guess
(cubic-root-iter new-guess (cubic-improve new-guess x) x)))
(define (cubic-improve guess x)
(+ (/ x (* 3 (square guess))) (/ (* 2 guess) 3)))
(define (cubic-good-enough? old-guess new-guess)
(< (abs (- (/ old-guess new-guess) 1.0)) 0.0001))
(define (cubic-root x)
(cubic-root-iter 1.0 x x))
実行例は
gosh> (cubic-root 2) 1.2599210498953948 gosh> (cube (cubic-root 2)) 2.000000000002484 gosh> (cubic-root 8) 2.0000000010711885 gosh> (cube (cubic-root 8)) 8.000000012854262
コード
##(sicp-answer-code "ex-1.8.scm")