Open Source WEB

##(link2sicp "book-Z-H-12.html#%_thm_1.29" "Exercise 1.29")

解答例

Simpsonの公式

(define (simpson f a b n)
  (define h (/ (- b a) n))
  (define (y k) (f (+ a (* k h))))
  (define (term i)
    (+ (y (- (* 2 i) 2))
       (* 4 (y (- (* 2 i) 1)))
       (y (* 2 i))))
  (define (next i) (+ i 1))
  (/ (* h (sum term 1 next (/ n 2))) 3))

計算の比較

gosh> (integral cube 0 1 0.01)
0.24998750000000042
gosh> (integral cube 0 1 0.001)
0.249999875000001
gosh> (simpson cube 0 1 100)
0.25000000000000017
gosh> (simpson cube 0 1 1000)
0.25000000000000017

Simpsonの公式で計算するほうが精度がよい。

コード

##(sicp-answer-code "ex-1.29.scm")

このサイトは、 IPA の「平成15年度オープンソフトウエア活用基盤整備事業」 の委託事業として開発されたKahuaで試験的に運用しております。

Copyright (c) 2004-2007 株式会社タイムインターメディア About Us