Technical Appendix

Main Menu           Previous Topic                                                           Next Topic

Simpson's Rule

Our goal is to compute definite integrals of the demand functions entered by the user in Slides 2 and 4 of Topic 2, and Slide 1 of Topic 3. To this end, we use an approximation of a definite integral known as Simpson's Rule. According to the Simpson's rule:




The function f's domain, [a,b], is divided into m intervals of length 2h each. On each interval, the function is approximated as a quadratic, and the integral is calculated accordingly. Adding up all the small areas of this piecewise function results in equations [4] and [5].

Certainly, as the length of each interval h decreases, and their number m increases, the right hand side of equation [4] gets closer and closer to the integral on the left hand side. In the limit, as h approaches 0, equation [4] becomes an exact equality. We found that for our purposes, setting m to a value of 100 yields sufficiently precise integration.

In our implementation, we wrote a MiniScheme function, integral, which encompasses equations [4] and [5] above, and computes an integral of any other MiniScheme function defined on the interval [a,b]:

(define integral (f a b m)
    (let ((h (/ (- b a) (* 2 m))) (sum 0))
            (for i (< i m)
                (set sum
                    (+ sum (f (+ a (* 2 i h)))
                           (* 4 (f (+ a (* h (+ (* 2 i) 1)))))
                           (f (+ a (* h 2 (+ i 1)))))))
            (set sum (* h (/ sum 3)))

For example, a MiniScheme expression (integral demand 1 2 10) integrates function demand of one variable between 1 and 2 using 10 subdivisions of this domain, given that the function is defined for every point in [1, 2].

                   Previous Slide                                                           Next Slide