Integration and numerical methods: area and the trapezoidal rule
IB Math AI · Calculus
Integration as accumulated change
If $f'(t)$ is a rate, then $\displaystyle\int_{a}^{b}f'(t)\,dt=f(b)-f(a)$ is the total change between $t=a$ and $t=b$. This single sentence answers most AI integration questions: litres flowed in, extra cost incurred, distance covered.
$$\int x^{n}\,dx=\frac{x^{n+1}}{n+1}+c\ (n\ne-1),\qquad \int e^{kx}\,dx=\frac{e^{kx}}{k}+c$$Area between two curves
$$A=\int_{a}^{b}\bigl(y_{\text{tren}}-y_{\text{duoi}}\bigr)\,dx$$The limits come from solving $y_1=y_2$. Subtracting in the wrong order gives the negative of the area.
The trapezoidal rule
$$\int_{a}^{b}y\,dx\approx\frac{h}{2}\Bigl(y_{0}+2(y_{1}+y_{2}+\cdots+y_{n-1})+y_{n}\Bigr),\qquad h=\frac{b-a}{n}$$With $n$ strips there are $n+1$ ordinates. The two end ordinates appear once; every interior ordinate appears twice, because it is shared by two strips.
This is the only method available when the data is a table of measurements and no formula exists — which is precisely the AI situation.
Over- or under-estimate
Where the curve is concave up, each chord lies above the curve and the rule overestimates. Where it is concave down, the rule underestimates. Doubling the number of strips divides the error by roughly $4$.
Worked example: the trapezoidal rule on a real table of measurements
The velocity of a car is recorded every $2$ seconds for the first $10$ seconds.
| $t$ (s) | $0$ | $2$ | $4$ | $6$ | $8$ | $10$ |
|---|---|---|---|---|---|---|
| $v$ (m/s) | $0$ | $7.5$ | $13.2$ | $17.1$ | $19.4$ | $20.5$ |
Estimate the distance the car travels, and say whether that estimate is an overestimate or an underestimate of the true distance.
Solution
Step 1: count the strips and ordinates. There are $6$ ordinates so $5$ strips, and $h=2$ s. This is where an off-by-one error most often occurs: $6$ data points do not give $6$ strips.
Step 2: apply the formula. The first and last ordinates are $0$ and $20.5$; the four interior ordinates are $7.5;\ 13.2;\ 17.1;\ 19.4$ with sum $57.2$.
$$s\approx\frac{2}{2}\Bigl(0+2(57.2)+20.5\Bigr)=1\times(114.4+20.5)=134.9\ \text{m}$$Step 3: overestimate or underestimate. Look at the sequence of velocities: the successive increases are $7.5;\ 5.7;\ 3.9;\ 2.3;\ 1.1$, decreasing, so the velocity graph is concave down. For a concave-down curve, the chord lies below the curve, so the trapezoidal rule gives an underestimate of the true distance.
Why this problem can only be solved numerically: the problem does not give a formula for $v(t)$ and there is no way to find one. This is the default situation in AI, and also the reason the trapezoidal rule is in the syllabus.
Three common errors, all giving reasonable-looking numbers. Forgetting to multiply by $\dfrac{h}{2}$ and multiplying by $h$ only: you get $269.8$ m, double. Forgetting to double the interior ordinates: you get $\dfrac{2}{2}(0+57.2+20.5)=77.7$ m. Adding all the ordinates directly and multiplying by $h$: you get $2(77.7)=155.4$ m; this is in fact a right-hand rectangle sum, which always overestimates when the function is increasing.
Worked example: area between two curves and accumulated quantity
(a) Calculate the area of the region bounded by $y=x(4-x)$ and $y=x$.
(b) Water flows into a tank at a rate $r(t)=4+0.6t^{2}$ liters per minute, for $0\le t\le 5$. Calculate the amount of water that flows in during the first $5$ minutes.
Solution
(a) Step 1: find the limits by solving for the intersections.
$$x(4-x)=x\;\Longrightarrow\;4x-x^{2}=x\;\Longrightarrow\;3x-x^{2}=0\;\Longrightarrow\;x(3-x)=0$$So $x=0$ and $x=3$. Note that you must not divide both sides by $x$: doing so loses the solution $x=0$ and with it one of the limits.
Step 2: decide which curve is on top. Test $x=1$: the parabola gives $y=3$, the line gives $y=1$. The parabola is on top.
$$A=\int_{0}^{3}\bigl[(4x-x^{2})-x\bigr]dx=\int_{0}^{3}(3x-x^{2})\,dx=\left[\frac{3x^{2}}{2}-\frac{x^{3}}{3}\right]_{0}^{3}$$$$A=\frac{27}{2}-9=13.5-9=4.5$$If you get $-4.5$ you subtracted in the wrong order; area is never negative.
(b) The rate is in liters per minute, so its integral over time gives the number of liters:
$$V=\int_{0}^{5}(4+0.6t^{2})\,dt=\left[4t+0.2t^{3}\right]_{0}^{5}=20+0.2(125)=20+25=45\ \text{liters}$$Reasonableness check. The rate runs from $r(0)=4$ to $r(5)=19$ liters/min. If the rate stayed at $4$ throughout you would get $20$ liters; if it stayed at $19$ throughout you would get $95$ liters. The answer $45$ lies between those two bounds, and leans toward the low side because the rate is small for most of the time, exactly as the shape of a quadratic suggests.
The two typical wrong answers are exactly the two bounds just mentioned: $19$ liters (confusing the final rate with the total amount) and $95$ liters (multiplying the final rate by the time). Both result from forgetting that the rate is changing.