[racket] Implementation of Simpson's Rule (SICP Exercise 1.29)

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Mon Nov 4 12:59:10 EST 2013

2013/11/4 Ben Duan <yfefyf at gmail.com>:
> I've asked the question on Stack Overflow [1]. Óscar López gave me an
> answer. But I still don't understand it. So I re-post it here:
>
> Following is my code for SICP exercise 1.29 [2]. The exercise asks us to
> implement Simpson's Rule using higher order procedure `sum`. It's supposed
> to be more accurate than the original `integral` procedure. But I don't know why
> it's not the case in my code:

A couple of points:

 - to compare to methods M1 and M2 we need to specify the class of functions,
   we will use the methods on
 - when comparing the results of the two methods on a single function f,
   we must use the same number of evaluations of f
 - the most accurate method for a given number of evaluations n,
   is the method which has the best worst case behaviour

Thus when SICP says:
"Simpson's Rule is a more accurate method of numerical integration
than the method illustrated above."
it doesn't mean that the Simpson rule will work better than, say, the
midpoint method for all
function. Some methods give very good results for polynomials of a small degree.
Try your methods on some non-polynomials: say 1/x , ln(x), sqrt(x) and sin(x).

See also some interesting examples here:

http://www.math.uconn.edu/~heffernan/math1132s13/files/trapezoid_rule.pdf


--
Jens Axel Søgaard


Posted on the users mailing list.