We discussed in class the problem of writing a general-purpose integration routine in Java. In this assignment you will complete the sketch we outlined, and add some graphic frills to it.

We want to define a class Integrators that exports several integration methods. For this assignment you only have to write one, the simplest one: Simpson's method. This method reduces the problem of computing the area under a function f (x) between a and b to the sum of the areas of vertical strips of equal width dx. The area is given by the formula:

[(f(a) + f(b)) / 2 + Sum (f (a + n*dx)) ] * dx, for n = 1, 2,.. (b-a)/dx-1

The precision of the method depends on the choice of dx. Taking 1000 steps will be good enough for this exercise, so choose dx = (b-a) / 1000, but feel free to experiment.

a) The integration method takes three parameters: an interface type and two doubles that specify the bounds. You want to define the interface type so it is easy to create an instance of it for any function you want. For example you can test your integration routine with the trigonometric Math.sin and verify that its integral from 0 to pi equals 2 (you can expect some roundoff errors depending on the number of steps you use).

b) The interface type (let's call it Evaluator, in analogy to the Comparator interface we have used to sort) can also be used with a function that you write explicitly. For example, you should verify that the integral of 1 / (1 + x*x) between 0 and 1 is (about) pi/4.

c) Find a reasonable way of handling functions such as 1/(1-x) when integrated between -2 and 2.

In the next assignment, we will add a graphical component to this program, and display a graph of the function that is being integrated.