MTH 343 · 4.3 Elements of numerical integration

Newton–Cotes Formulas Lab

Choose a closed or open Newton–Cotes formula, a function, an interval [a, b] and n up to 10. The lab places the n + 1 equally spaced nodes, draws the polynomial Pₙ through them that the formula integrates in place of f, and compares the result with the exact value and the error bound.

f(x) =

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

x⁴ on [0, 1] is the error-bound exercise from the slides. For 1/(1 + 25x²) a larger n is not always better. ln x on [0, 1] needs an open formula, since f(0) is undefined (the chip selects Open).

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.

Newton–Cotes formula

Closed: a and b are nodes, h = (b − a)/n. Open: a and b are not nodes, h = (b − a)/(n + 2).

n (the formula uses n + 1 nodes)

Exact value—
Approximation—
Absolute error—
Error bound—

Area under f on [a, b]

  • f(x)
  • P₃ through the nodes
  • Area under P₃
  • Nodes
Shade

Nodes and weights

The formula is a weighted sum of the values of f at the nodes.

Every n at once

The same integral with every formula of the selected kind. Click an n to select it.

Error as n grows

  • Closed formulas
  • Open formulas
  • Closed error bound
  • Open error bound

Each solid point is the absolute error of one formula on your interval, and each hollow point on a dashed line is its error bound. An error never exceeds the bound of the same color. The vertical axis is logarithmic. A logarithmic axis has no 0, so an exact result or a bound of 0 sits on the separate 0 line at the bottom. The kind you did not select is faded. Click a point to select that n.

Error as the interval shrinks

  • Closed, n = 3
  • Open, n = 3
  • Reference slope 5