All pastes #918666 Raw Edit

Stuff

public text v1 · immutable
#918666 ·published 2008-02-26 08:27 UTC
rendered paste body
(define (inc n) (+ n 1))

(define (cube x) (* x x x))

(define (sum term a next b)
  (if (> a b)
      0
      (+ (term a)
         (sum term (next a) next b))))

(define (simpson f a b n)
  (define k 0)
  (define h (/ (- b a) n))
  (define (coeff k)
    (cond ((= k 0) 1)
          ((= k n) 1)
          ((= k 1) 4)
          ((= (remainder k 2) 0) 2)
          (else 4)))
  (define (my_term k) 
    (* (coeff k) 
       (f (+ a (* k h)))))
  (* (/ h 3.0)
     (sum my_term k inc n)))


=========

Now, any even value of value of n returns 1/4 ...