Example 1.
Approximate the integral of f(x) = x3 on the interval [1, 2] with four subintervals.
First, h = (2 - 1)/4 = 0.25, and thus we calculate:
= ½⋅(13 + 2⋅(1.253 + 1.53 + 1.753) + 23)⋅0.25 = 3.796875
If we double the number of intervals, that is, eight, we set h = (2 - 1)/8 = 0.125, and thus we calculate:
= ½⋅(13+2⋅(1.1253+1.253+1.3753+1.53+1.6253+1.753+1.8753)+23)⋅0.25 = 3.76171875
The second approximation is much closer to the correct answer of 3.75.
Example 2
Find the integral of the function f(x) = e-xsin(x) on the interval [0, 3], with N = 10 and εstep = 0.001. In this case, the initial width is h = 3.0 and therefore T0 = 0.010539. The subsequent iterations are shown in Table 1.
Table 1. The composite-trapezoidal rule applied to f(x) = e-xsin(x).
n | Tn − 1 | Tn | |Tn - Tn − 1| |
---|---|---|---|
1 | 0.010539 | 0.33913 | 0.33 |
2 | 0.33913 | 0.47256 | 0.13 |
3 | 0.47256 | 0.50881 | 0.036 |
4 | 0.50881 | 0.51804 | 0.0092 |
5 | 0.51804 | 0.52036 | 0.0023 |
6 | 0.52036 | 0.52094 | 0.00058 |
Thus, our approximation to the integral is 0.52094 which has an absolute error of 0.00019 (or relative error of less than 0.04%) when compared to the correct five digit approximation 0.52113.
Copyright ©2005 by Douglas Wilhelm Harder. All rights reserved.