#%config InlineBackend.figure_format = 'svg'
from pylab import *
The error formulae we have derived so far assume certain derivatives exist and are continuous. This may be a restrictive assumption in many cases. Even if the function is not differentiable everywhere, the derivatives may be integrable. In this case, we can use Taylor formula with an integral remainder term to perform the error analysis.
8.5.1 Trapezoidal rule ¶ Assume that f f f is continuously differentiable and f ′ ′ f'' f ′′ is integrable on [ a , b ] [a,b] [ a , b ] , i.e.,
∫ a b ∣ f ′ ′ ( x ) ∣ d x < ∞ \int_a^b |f''(x)| \ud x < \infty ∫ a b ∣ f ′′ ( x ) ∣ d x < ∞ Single interval. Taylor’s theorem gives
f ( x ) = f ( a ) + ( x − a ) f ′ ( a ) + ∫ a x ( x − t ) f ′ ′ ( t ) d t = : p 1 ( x ) + R 2 ( x ) \begin{align}
f(x) &= \clr{red}{f(a) + (x-a) f'(a)} + \clr{blue}{ \int_a^x (x-t) f''(t) \ud t } \\
&=: \clr{red}{p_1(x)} + \clr{blue}{ R_2(x) }
\end{align} f ( x ) = f ( a ) + ( x − a ) f ′ ( a ) + ∫ a x ( x − t ) f ′′ ( t ) d t =: p 1 ( x ) + R 2 ( x ) The quadrature error E n E_n E n is a linear operator
E n ( F + G ) = E n ( F ) + E n ( G ) , F , G ∈ C [ a , b ] E_n(F+G) = E_n(F) + E_n(G), \qquad F,G \in \cts[a,b] E n ( F + G ) = E n ( F ) + E n ( G ) , F , G ∈ C [ a , b ] Thus
E 1 ( f ) = E 1 ( p 1 ) + E 1 ( R 2 ) = E 1 ( R 2 ) E_1(f) = E_1(p_1) + E_1(R_2) = E_1(R_2) E 1 ( f ) = E 1 ( p 1 ) + E 1 ( R 2 ) = E 1 ( R 2 ) since Trapezoidal rule is exact for linear polynomials. Now
E 1 ( R 2 ) = ∫ a b R 2 ( x ) d x − b − a 2 [ R 2 ( a ) + R 2 ( b ) ] , R 2 ( a ) = 0 = ∫ a b ∫ a x ( x − t ) f ′ ′ ( t ) d t d x − b − a 2 ∫ a b ( b − t ) f ′ ′ ( t ) d t \begin{aligned}
E_1(R_2)
&= \int_a^b R_2(x) \ud x - \frac{b-a}{2}[R_2(a) + R_2(b)], \qquad R_2(a) = 0 \\
&= \int_a^b \int_a^x (x-t) f''(t) \ud t \ud x - \frac{b-a}{2}\int_a^b (b-t) f''(t) \ud t
\end{aligned} E 1 ( R 2 ) = ∫ a b R 2 ( x ) d x − 2 b − a [ R 2 ( a ) + R 2 ( b )] , R 2 ( a ) = 0 = ∫ a b ∫ a x ( x − t ) f ′′ ( t ) d t d x − 2 b − a ∫ a b ( b − t ) f ′′ ( t ) d t For any integrable function G ( x , t ) G(x,t) G ( x , t ) , by Fubini theorem
∫ a b ∫ a x G ( x , t ) d t d x = ∫ a b ( ∫ a b G ( x , t ) χ [ a , x ] ( t ) d t ) d x = ∫ a b ( ∫ a b G ( x , t ) χ [ a , x ] ( t ) d x ) d t = ∫ a b ( ∫ a b G ( x , t ) χ [ t , b ] ( x ) d x ) d t = ∫ a b ∫ t b G ( x , t ) d x d t \begin{align}
\int_a^b \int_a^x G(x,t) \ud t \ud x
&= \int_a^b \left( \int_a^b G(x,t) \chi_{[a,x]}(t) \ud t \right) \ud x \\
&= \int_a^b \left( \int_a^b G(x,t) \chi_{[a,x]}(t) \ud x \right) \ud t \\
&= \int_a^b \left( \int_a^b G(x,t) \chi_{[t,b]}(x) \ud x \right) \ud t \\
&= \int_a^b \int_t^b G(x,t) \ud x \ud t
\end{align} ∫ a b ∫ a x G ( x , t ) d t d x = ∫ a b ( ∫ a b G ( x , t ) χ [ a , x ] ( t ) d t ) d x = ∫ a b ( ∫ a b G ( x , t ) χ [ a , x ] ( t ) d x ) d t = ∫ a b ( ∫ a b G ( x , t ) χ [ t , b ] ( x ) d x ) d t = ∫ a b ∫ t b G ( x , t ) d x d t Here χ is the characteristic function and we used χ [ a , x ] ( t ) = χ [ t , b ] ( x ) \chi_{[a,x]}(t) = \chi_{[t,b]}(x) χ [ a , x ] ( t ) = χ [ t , b ] ( x ) since a ≤ t ≤ x ≤ b a \le t \le x \le b a ≤ t ≤ x ≤ b . Using this result in the above error formula for G ( x , t ) = ( x − t ) f ′ ′ ( t ) G(x,t) = (x-t) f''(t) G ( x , t ) = ( x − t ) f ′′ ( t ) we get
E 1 ( R 2 ) = ∫ a b f ′ ′ ( t ) ∫ t b ( x − t ) d x d t − b − a 2 ∫ a b ( b − t ) f ′ ′ ( t ) d t = ∫ a b ( t − a ) ( t − b ) 2 f ′ ′ ( t ) d t \begin{aligned}
E_1(R_2)
&= \int_a^b f''(t) \int_t^b (x-t) \ud x \ud t - \frac{b-a}{2} \int_a^b (b-t) f''(t) \ud t \\
&= \int_a^b \frac{(t-a)(t-b)}{2} f''(t) \ud t
\end{aligned} E 1 ( R 2 ) = ∫ a b f ′′ ( t ) ∫ t b ( x − t ) d x d t − 2 b − a ∫ a b ( b − t ) f ′′ ( t ) d t = ∫ a b 2 ( t − a ) ( t − b ) f ′′ ( t ) d t Composite rule. For the composite Trapezoid rule, the error is obtained by adding the error from each interval and can be written as
E n ( f ) = ∫ a b K ( t ) f ′ ′ ( t ) d t E_n(f) = \int_a^b K(t) f''(t) \ud t E n ( f ) = ∫ a b K ( t ) f ′′ ( t ) d t where
K ( t ) = 1 2 ( t − x j − 1 ) ( t − x j ) , t ∈ [ x j − 1 , x j ] , j = 1 , 2 , … , n K(t) = \half (t - x_{j-1})(t - x_j), \qquad t \in [x_{j-1}, x_j], \qquad j=1,2,\ldots,n K ( t ) = 2 1 ( t − x j − 1 ) ( t − x j ) , t ∈ [ x j − 1 , x j ] , j = 1 , 2 , … , n This gives the following error estimate
∣ E n ( f ) ∣ ≤ ∥ K ∥ ∞ ∫ a b ∣ f ′ ′ ( t ) ∣ d t = h 2 8 ∫ a b ∣ f ′ ′ ( t ) ∣ d t |E_n(f)| \le \norm{K}_\infty \int_a^b |f''(t)| \ud t = \frac{h^2}{8} \int_a^b |f''(t)| \ud t ∣ E n ( f ) ∣ ≤ ∥ K ∥ ∞ ∫ a b ∣ f ′′ ( t ) ∣ d t = 8 h 2 ∫ a b ∣ f ′′ ( t ) ∣ d t Compare this to the previous error estimate
∣ E n ( f ) ∣ = b − a 12 h 2 ∣ f ′ ′ ( η ) ∣ ≤ b − a 12 h 2 ∥ f ′ ′ ∥ ∞ |E_n(f)| = \frac{b-a}{12} h^2 |f''(\eta)| \le \frac{b-a}{12} h^2 \norm{f''}_\infty ∣ E n ( f ) ∣ = 12 b − a h 2 ∣ f ′′ ( η ) ∣ ≤ 12 b − a h 2 ∥ f ′′ ∥ ∞ which may over-estimate the error if f ′ ′ f'' f ′′ has a peaky distribution, since
1 b − a ∫ a b ∣ f ′ ′ ( t ) ∣ d t ≤ ∥ f ′ ′ ∥ ∞ \frac{1}{b-a} \int_a^b |f''(t)|\ud t \le \norm{f''}_\infty b − a 1 ∫ a b ∣ f ′′ ( t ) ∣ d t ≤ ∥ f ′′ ∥ ∞