Independent study guide

Numerical Integration: Samples, Weights and Error Bounds

Choose midpoint, trapezoidal or Simpson rules from the available data. Three worked examples and six exercises distinguish estimates from error guarantees.

Nablio · 6 questionsPublished

1. Match the rule to the information

A numerical integral is a weighted sum, not a new antiderivative. To approximate I=∫abf(x) dxI=\int_a^b f(x)\,dx, first identify the interval, the sample locations and the units. The number n counts subintervals, not data points. With equal spacing, there are n+1 endpoints but n midpoints.

h=b−an,xi=a+ih.h=\frac{b-a}{n},\qquad x_i=a+ih.Mn=h∑i=1nf ⁣(xi−1+xi2).M_n=h\sum_{i=1}^{n}f\!\left(\frac{x_{i-1}+x_i}{2}\right).Tn=h(f(x0)2+∑i=1n−1f(xi)+f(xn)2).T_n=h\left(\frac{f(x_0)}2+\sum_{i=1}^{n-1}f(x_i)+\frac{f(x_n)}2\right).Sn=h3(f(x0)+4∑j=1n/2f(x2j−1)+2∑j=1n/2−1f(x2j)+f(xn)).S_n=\frac h3\left(f(x_0)+4\sum_{j=1}^{n/2}f(x_{2j-1})+2\sum_{j=1}^{n/2-1}f(x_{2j})+f(x_n)\right).

The midpoint rule uses one value at the centre of each interval. The trapezoidal rule joins successive endpoint values by straight segments and integrates that piecewise-linear model. Interior endpoints get full weight because they touch two trapezoids. Simpson’s composite one-third rule fits a quadratic over each pair of intervals: its endpoint weights alternate 1, 4, 2, 4, …, 2, 4, 1. It requires equal spacing and a positive even n. For n=2, the sum with coefficient 2 is empty and equals zero.

A table of endpoint values does not supply the midpoint values. Do not invent them silently. Likewise, more digits in the sum do not establish more accuracy. A numerical integral keeps signed contributions: integrating velocity estimates displacement, not automatically distance.

2. Worked example: compare rules on the same interval

Let f(x)=x2+2f(x)=x^2+2 on [0,2][0,2], with n=2n=2 and h=1h=1. The endpoint values are 2,3,62,3,6; the midpoint values at 1/2,3/21/2,3/2 are 9/4,17/49/4,17/4.

Therefore M2=1(9/4+17/4)=13/2M_2=1(9/4+17/4)=13/2, while T2=1(2/2+3+6/2)=7T_2=1(2/2+3+6/2)=7. Simpson’s rule gives S2=(1/3)(2+4(3)+6)=20/3S_2=(1/3)(2+4(3)+6)=20/3.

Here an antiderivative provides a check: I=[x3/3+2x]02=20/3I=[x^3/3+2x]_0^2=20/3. The midpoint and trapezoidal absolute errors are 1/61/6 and 1/31/3, respectively. The graph is convex because f′′=2>0f^{\prime\prime}=2>0, so midpoint underestimates and trapezoids overestimate. Simpson is exact for this quadratic. It is also exact for cubics, but not for an arbitrary curved function.

These are three different sampling recipes. In particular, M₂ needs values that T₂ and S₂ do not use. A fair data-cost comparison must count the function evaluations, not just compare the subscript.

3. Worked example: unequal time steps and signed velocity

A sensor records times t=0,1,3t=0,1,3 seconds and velocities v=2,−2,4v=2,-2,4 metres per second. Assume velocity varies linearly between each pair of readings. Use the individual widths, not a single averaged step.

The first contribution is (1−0)(2+(−2))/2=0(1-0)(2+(-2))/2=0 m; the second is (3−1)((−2)+4)/2=2(3-1)((-2)+4)/2=2 m. The displacement is therefore 22 m for this model.

In general, T=∑i=1n(xi−xi−1)[f(xi−1)+f(xi)]/2T=\sum_{i=1}^{n}(x_i-x_{i-1})[f(x_{i-1})+f(x_i)]/2 still works with unequal widths. This is exact for the piecewise-linear model, not necessarily for the unknown motion between measurements. The positive and negative velocity portions cancel in displacement; distance requires integrating ∣v∣|v|, splitting at each zero crossing. Standard composite Simpson weights cannot be applied directly to these unequally spaced readings.

4. Worked example: choose n from a guaranteed bound

For a function with continuous second derivative on [a,b][a,b], let ∣f′′(x)∣≤K2|f^{\prime\prime}(x)|\le K_2 throughout the interval. For Simpson, require a continuous fourth derivative and ∣f(4)(x)∣≤K4|f^{(4)}(x)|\le K_4. With equal steps, these sufficient bounds apply:

∣I−Mn∣≤K2(b−a)324n2,∣I−Tn∣≤K2(b−a)312n2.|I-M_n|\le\frac{K_2(b-a)^3}{24n^2},\qquad |I-T_n|\le\frac{K_2(b-a)^3}{12n^2}.∣I−Sn∣≤K4(b−a)5180n4.|I-S_n|\le\frac{K_4(b-a)^5}{180n^4}.

For f(x)=exf(x)=e^x on [0,1][0,1], choose trapezoids with guaranteed error at most 10−310^{-3}. Since f′′(x)=ex≤e<3f^{\prime\prime}(x)=e^x\le e<3, we may use K2=3K_2=3. Require 3/(12n2)≤10−33/(12n^2)\le10^{-3}, giving n2≥250n^2\ge250. Thus the smallest integer certified by this bound is n=16n=16. Its bound is 1/1024<10−31/1024<10^{-3}; n=15 does not satisfy this particular sufficient inequality.

A bound is a ceiling on error, not the actual error. A smaller n might work, but this bound would not certify it. For Simpson, round upward to an even integer. Derivative bounds do not follow from a few table entries, and these formulas do not include measurement noise or arithmetic rounding.

5. Six graduated exercises

1. Count intervals

On [−1,2][-1,2], use n=6n=6. Find h, the number of endpoint readings, and the number of midpoint readings. Is n admissible for composite Simpson?

Hint

Sketch the partition before counting.

Explained solution

h=(2−(−1))/6=1/2h=(2-(-1))/6=1/2. There are 77 endpoints and 66 midpoints. Yes: 6 is positive and even. Midpoint readings lie between the listed endpoints, so the two data sets are not interchangeable.

2. An exact linear check

For f(x)=3x+1f(x)=3x+1 on [0,2][0,2], compute T2T_2 and check it by integration.

Hint

The endpoint values are 1, 4 and 7.

Explained solution

T2=1(1/2+4+7/2)=8T_2=1(1/2+4+7/2)=8. Also I=[3x2/2+x]02=8I=[3x^2/2+x]_0^2=8. A straight line equals its piecewise-linear interpolation, so the trapezoidal estimate is exact here.

3. Weights from a table

At x=0,1/2,1,3/2,2x=0,1/2,1,3/2,2, the values are 1,2,0,4,31,2,0,4,3. Find T4T_4 and S4S_4. Does disagreement tell you which is closer to the true integral?

Hint

Use h=1/2 and write the weights before multiplying.

Explained solution

T4=(1/2)(1/2+2+0+4+3/2)=4T_4=(1/2)(1/2+2+0+4+3/2)=4. Meanwhile S4=(1/6)(1+4(2)+2(0)+4(4)+3)=14/3S_4=(1/6)(1+4(2)+2(0)+4(4)+3)=14/3. The samples alone do not identify the true curve between nodes, so they cannot tell which estimate is closer.

4. Reject an invalid recipe

A student applies Simpson weights to x=0,1,2,3x=0,1,2,3 with values 0,1,8,270,1,8,27. What fails, and what trapezoidal estimate can these readings provide?

Hint

Count subintervals, not values.

Explained solution

There are n=3n=3 subintervals, so the standard composite one-third rule does not apply to the whole interval. Trapezoids give T3=1(0/2+1+8+27/2)=45/2T_3=1(0/2+1+8+27/2)=45/2. Do not discard a reading or change n without obtaining the required data.

5. Choose an even n

On [0,2][0,2], a function has a continuous fourth derivative with ∣f(4)∣≤90|f^{(4)}|\le90. Find the smallest even n certified by the Simpson bound for error at most 10−310^{-3}.

Hint

Solve the fourth-power inequality, then enforce even parity.

Explained solution

The bound is 90(2)5/(180n4)=16/n490(2)^5/(180n^4)=16/n^4. We need n4≥16000n^4\ge16000. Since 104=1000010^4=10000 and 124=2073612^4=20736, the smallest admissible even value is n=12n=12. Its bound is 16/20736≈0.00077216/20736\approx0.000772. This is a guarantee, not a prediction of the exact error.

6. A table cannot certify accuracy

At the nodes 0,1,20,1,2, compare f(x)=0f(x)=0 and g(x)=sin⁡2(πx)g(x)=\sin^2(\pi x). What do trapezoids and Simpson return? What are the true integrals on [0,2][0,2]?

Hint

Use the identity for the square of sine.

Explained solution

Both functions have values 0,0,00,0,0, so T2=S2=0T_2=S_2=0 for both. Yet ∫02f(x) dx=0\int_0^2 f(x)\,dx=0, whereas sin⁡2(πx)=(1−cos⁡(2πx))/2\sin^2(\pi x)=(1-\cos(2\pi x))/2 gives ∫02g(x) dx=1\int_0^2 g(x)\,dx=1. Identical samples, or agreement between two rules, do not prove accuracy without further information about the function.

6. Final check

Check the widths, number of intervals, sampling locations, Simpson parity, signs and units. State whether you have computed an approximation to an unknown curve or an exact integral of an assumed interpolation. Use a justified derivative bound only when its assumptions hold.

This original general calculus lesson extends finite-sum practice; it is not a course outline or an exam prediction. Background reference: OpenStax, numerical integration. For prerequisites, review integration and finite-sum practice.

Useful for

Work on the step you’re missing.

Tell us the subject and your preferred time. Nablio confirms the details by text or email.

Request a lesson