Basics of Trapezoidal and Simpson Rules
Basics of Trapezoidal and Simpson Rules
Let f be a continuous function on [a, b]. We subdivide the interval into n pieces and let x0 = a, x1 = a + (b a)/n, x2 = a + 2(b a)/n, . . . , xn = a + n(b a)/n = b. The Trapezoidal Rule approximation to
b
f (x) dx
a
ba f (x0 ) + 2f (x1 ) + + 2f (xn1 ) + f (xn ) . 2n Note that we are taking a kind of weighted average of values of f at n + 1 points, n 1 of them weighted by 2 and 2 of them weighted by 1. The sum of the weights is thus 2(n 1) + 2 = 2n, which is precisely the denominator. The error bound for this approximation is |error| max[a,b] |f (x)| (b a)3 . 12n2
is
The Simpsons Rule approximation to the integral (assuming n even) is ba f (x0 ) + 4f (x1 ) + 2f (x2 ) + 4f (x3 ) + + 2f (xn2 ) + 4f (xn1 ) + f (xn ) . 3n Again, the sum of the weights (all 1, 2, or 4) in the numerator is the denominator, 3n. The error bound for this approximation is |error| max[a,b] |f (x)| (b a)5 . 180n4
1
Example. Say we want to approximate 0 x4 dx = 1/5. Take a = 0, b = 1, xj = j/n, f (x) = x4 . Here f (x) = 12x2 , with maximum value of 12. So the error bound in the Trapezoidal Rule is 1/n2 . Since f (x) = 24, the error bound in Simpsons Rule is 24 2 = . 4 180n 15n4
So suppose we want accuracy to 4 decimal places, that is, an error no bigger than 104 . To guarantee this with the Trapezoidal Rule, we could take n big enough so that 1/n2 104 , or n2 104 . So n = 100 would work. But to guarantee this with Simpsons Rule, it would suce to choose n so that 15n4 20000, or n4 1334. For this, n = 6 almost suces, and we certainly could get the desired accuracy with n = 8. Indeed, we nd that the trapezoidal rule with n = 100 gives the approximation 0.200033333 to the integral, good to 4 but not to 5 decimal places, while Simpsons rule with n = 6 gives 0.200102881 and Simpsons rule with n = 8 gives 0.200032552 (very slightly better than the trapezoidal rule with n = 100). So certainly with smooth integrands like x4 , Simpsons rule is much more ecient.