# The Midpoint Rule

One alternative to the composite trapezoidal rule for integrating functions is to use the midpoint rule. The midpoint rule is simply a Riemann sum in which the points where the function is evaluated are the midpoints of subintervals of the interval of integration. Specifically, consider the integral \[\int_a^b f(x)\,dx\] where \(f\) is twice continuously differentiable. Let \(a=x_0\lt x_1\lt\dots\lt x_n=b\) be an equally-spaced partition of \([a,b]\), and let \(z_i=(x_i+x_{i-1})/2\) for \(i=1,2,\dots,n\) denote the midpoints of the subintervals defined by the \(x_i\) values. When \(h=(b-a)/n\) is the uniform width of the subintervals, the midpoint rule is \[\int_a^b f(x)\,dx = h\sum_{i=1}^n f(z_i) + O(h^2). \] Write a Matlab function that takes four arguments: an integrand function, the lower and upper limits of integration, and the value of \(n\), which returns the value of the midpoint approximation to the integral.

The "final exam" for this course will take place
at 8:00 AM on Tuesday, 12 December. This will be an ordinary
50 minute test. It will be comprehensive, but weighted toward
the latter half of the semester. As always, paper notes will
be permitted, but no electronic devices will be allowed.
A sample exam is available.

A
Solution example is available
for the quiz. The solution to
Test 1 is still available too.

The ultimate assignment is posted.