MTH 343 · 4.3 Elements of numerical integration

Trapezoidal vs Simpson Lab

Pick a function and an interval [a, b]. The lab approximates the integral with the trapezoidal rule and Simpson's rule, draws the line and the parabola each rule integrates in place of f, and compares both results with the exact value.

f(x) =

Use x as the variable. You can write + − * / ^, sin, cos, tan, exp, ln (or log), sqrt, abs, pi, e.

(a), (b) and (c) are the exercise from the slides. 5x⁴ − 6x² is a case where the trapezoidal rule beats Simpson's rule.

Interval [a, b]

Numbers or expressions such as pi, pi/2, 1/3, e, sqrt(2), or drag the a and b handles on the plot. The lab needs a < b.

Exact value—
Trapezoidal rule—
Simpson's rule—
Closer to the exact value—

Area under f on [a, b]

  • f(x)
  • Exact area
  • Trapezoidal: line P₁
  • Simpson's: parabola P₂
  • Nodes
Show

Each rule replaces f by a polynomial through its nodes and integrates that polynomial instead. Drag the handles at a and b to move the endpoints; hover over the plot to read values.

Nodes, weights and errors

Each rule is a weighted sum of values of f at its nodes. The trapezoidal rule uses the endpoints only; Simpson's rule also uses the midpoint.

Error as the interval shrinks

  • Trapezoidal rule
  • Simpson's rule
  • Reference slopes 3 and 5

The left endpoint a stays fixed and the right endpoint moves to a + w. Both axes are logarithmic, so an error of order w³ appears as a line of slope 3 and an error of order w⁵ as a line of slope 5. A logarithmic axis has no 0, so an error of 0 is drawn on the separate 0 line at the bottom. A curve drops to that line where the error changes sign. Where the error is too small to resolve in double precision, the curve stops and continues on the 0 line.