Skip to main content

Section 13.2 Left, right, midpoint rules

The three rules considered here use equal subintervals, but different choices of same points. In a subinterval \([x_{k-1}, x_k]\) we have three natural choices for a sample point: left endpoint \(x_{k-1}\text{,}\) right endpoint \(x_k\text{,}\) and midpoint \(\bar x_k = (x_{k-1} + x_k)/2\text{.}\) They give us three ways of approximating the integral:

  • Left endpoint approximation \(L_n=h(f(x_0)+f(x_1)+\dots+f(x_{n-1}))\)
  • Right endpoint approximation \(R_n=h (f(x_1)+f(x_2)+\dots+f(x_{n}))\)
  • Midpoint Rule: \(M_n=h (f(\bar x_1)+f(\bar x_2)+\dots+f(\bar x_{n}))\)

For the function \(f(x) = \sin(x^2)\) on the interval \([1, 3]\text{,}\) use Matlab to compute the left-, right, and midpoint approximations with \(n=10\)

Solution
f = @(x) sin(x.^2);
a = 1;
b = 3;
n = 10;
h = (b-a)/n;
x = a:h:b;

L = sum(f(x(1:end-1)))*h;
R = sum(f(x(2:end)))*h;
midpoints = (x(1:end-1) + x(2:end))/2;
M = sum(f(midpoints))*h;
fprintf('Leftpoint %g, Rightpoint %g, Midpoint %g\n', L, R, M);

The output is “Leftpoint 0.483958, Rightpoint 0.398087, Midpoint 0.474599”. (One can check with WolframAlpha that the actual value of the integral is about 0.4633.)