Numerical integration · CMNA Laboratory

Simpson's rule

Replace the integrand with local quadratics, integrate those easy curves, and add the pieces. Then do it to your own R function.

Three samples define the panel

CMNA's simp() divides the interval into m panels. For each panel it evaluates the function at the left endpoint, midpoint, and right endpoint. Those three values determine a quadratic approximation, whose area is

h / 6 × [f(x₀) + 4f(xₘ) + f(x₁)]

The factor of four on the midpoint is not decoration: it is exactly the weight produced by integrating the interpolating quadratic.

Bring your own integrand

Let R draw the curve. Let Simpson tile it.

Write any vectorized R function f(x), choose bounds and a panel count, then play the approximation panel by panel.

RuntimePreparing R…
RDefine f(x)

panelx₀xₘx₁panel arearunning area
Book§5.2.1 · Multipanel Interpolation Rules · p. 131Book details
CMNA packagesimp
TeachingInstructor notes and chapter contextOpen teaching material
Numerical ZooWorked problems