huangzworks / SICP-answers

我的 SICP 解题集
http://sicp.readthedocs.org/
882 stars 183 forks source link

验证 1.29 的积分下界是否需要设为 0 #7

Open huangzworks opened 11 years ago

huangzworks commented 11 years ago

http://sicp.readthedocs.org/en/latest/chp1/29.html#comment-775467789

wdanxna commented 10 years ago
(define (simpson a b f n)
  (define h (/ (- b a) n))

  (define (simpson-step k)
    (define (f-wapper x)
      (cond ((= k 0) (f x))
            ((= k n) (f x))
            ((even? k) (* 2 (f x)))
            (else (* 4 (f x)))))
    (f-wapper (+ a (* k h))))

  (define (next-k x) (+ x 1))

  (* (/ h 3) (sum-tem simpson-step 0 next-k n))
  )

从0开始是正确的,因为我们其实是计算simpson函数从0到n的积分^_^