7. Rectangle rule integration

Monte Carlo integration is relatively simple, but it's also not repeatable. If you perform the same test multiple times with a different selection of random points, you'll get slightly different results.

Another method for estimating an area is to use a Riemann sum. (The method is named after the 19th-century German mathematician Bernhard Riemann who made great contributions to integral geometry and other fields.) To calculate a Riemann sum, also known as applying the rectangle rule, you divide the area into thin slices and add up the areas of the slices. The following diagram shows an area being approximated by a Riemann sum:

In this example, the height of each rectangle is given by the function's value at the rectangle's left edge, so this is sometimes called the left Riemann sum. Other variations use the function's value at the rectangle's right edge (the right Riemann sum) or in the rectangle's middle (the midpoint rule).

The widths of the rectangles depend on the number of rectangles. Using more, thinner rectangles gives a closer approximation to the actual area.

Write a program that uses the left Riemann sum to approximate the area under a function. Use your program to estimate the areas for the curves described in the preceding problem.

If you remember your calculus, make the program calculate the areas exactly and compare the calculated and estimated results.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.250.203