SUNY Geneseo Department of Mathematics
Friday, March 31
Math 230 02
Spring 2017
Prof. Doug Baldwin
I’m out of town next Friday (April 7). Class will be led by another math professor.
The basic idea is to evaluate a definite integral by numerically calculating the area under a curve:
Hand out lab
Goal for today: try some examples and develop pseudocode algorithms for numerical integration via Riemann sums and via the trapezoid rule.
For both methods, let’s use as an example function f(x) = x2 - x, integrated from x = 1 to x = 4, with 3 subintervals.
Relevant ideas or questions from video
Try the example by hand
Algorithm
riemann( f, a, b, n )
deltaX = ( b - a ) / n
for each i between 0 and n
xi = a + i * deltaX
fi = f( xi )
return (sum of f0 through fn-1) * deltaX # left Riemann sum
Try to work through the example, and write out an algorithm, on your own. The algorithm should look about like the one for Riemann sums, except that it will calculate the area of each subregion differently.
A new kind of loop: for
loops
Read textbook section 12.4