Numerical Differentiation and Integration Numerical Differentiation Basic Problems Problem 1: Derive a formula that approximates the derivative of a function using a linear combination of function values. This is applicable when the function is known.Problem 2: Approximate the value of a derivative of a function defined by discrete data.Solution Approaches Use Taylor Series Expansion. Pass a polynomial through the given data and differentiate the interpolating polynomial. Applications Solving Ordinary and Partial Differential Equations. First Derivative For a function f : [ a , b ] → R f : [a, b] \rightarrow R f : [ a , b ] → R , the derivative f ′ ( c ) f'(c) f ′ ( c ) at a point c c c is defined as: f ′ ( c ) = lim h → 0 f ( c + h ) − f ( c ) h f'(c) = \lim_{h \to 0} \frac{f(c + h) - f(c)}{h} f ′ ( c ) = lim h → 0 h f ( c + h ) − f ( c ) , for all c ∈ ( a , b ) c \in (a, b) c ∈ ( a , b ) Geometrically, f ′ ( c ) f'(c) f ′ ( c ) represents the slope of the tangent to the curve f ( x ) f(x) f ( x ) at x = c x = c x = c . Taylor Series Derivative Taylor's Theorem: If f f f has two continuous derivatives, then: f ( x < e m > 0 + h ) = f ( x < / e m > 0 ) + h f ′ ( x < e m > 0 ) + h 2 2 f ′ ′ ( θ ) f(x<em>0 + h) = f(x</em>0) + hf'(x<em>0) + \frac{h^2}{2}f''(\theta) f ( x < e m > 0 + h ) = f ( x < / e m > 0 ) + h f ′ ( x < e m > 0 ) + 2 h 2 f ′′ ( θ ) , where θ ∈ ( x < / e m > 0 , x 0 + h ) \theta \in (x</em>0, x_0 + h) θ ∈ ( x < / e m > 0 , x 0 + h ) Forward Formula: f ′ ( x < e m > 0 ) ≈ f ( x < / e m > 0 + h ) − f ( x 0 ) h f'(x<em>0) \approx \frac{f(x</em>0 + h) - f(x_0)}{h} f ′ ( x < e m > 0 ) ≈ h f ( x < / e m > 0 + h ) − f ( x 0 ) Absolute Error Error is defined as: ∣ true value − approximate value ∣ |\text{true value} - \text{approximate value}| ∣ true value − approximate value ∣ Error bound for the Forward Formula: ∣ E < e m > D ( f ) ∣ ≤ max < / e m > θ ∈ [ a , b ] h 2 ∣ f ′ ′ ( θ ) ∣ |E<em>D(f)| \leq \max</em>{\theta \in [a, b]} \frac{h}{2} |f''(\theta)| ∣ E < e m > D ( f ) ∣ ≤ max < / e m > θ ∈ [ a , b ] 2 h ∣ f ′′ ( θ ) ∣ Example: Find the derivative of f ( x ) = x 2 f(x) = x^2 f ( x ) = x 2 at x = 1 x = 1 x = 1 with h = 0.1 h = 0.1 h = 0.1 using the Taylor series.Backward Formula: f ′ ( x < e m > 0 ) = f ( x < / e m > 0 ) − f ( x 0 − h ) h f'(x<em>0) = \frac{f(x</em>0) - f(x_0 - h)}{h} f ′ ( x < e m > 0 ) = h f ( x < / e m > 0 ) − f ( x 0 − h ) Central Formula: f ′ ( x < e m > 0 ) = f ( x < / e m > 0 + h ) − f ( x 0 − h ) 2 h f'(x<em>0) = \frac{f(x</em>0 + h) - f(x_0 - h)}{2h} f ′ ( x < e m > 0 ) = 2 h f ( x < / e m > 0 + h ) − f ( x 0 − h ) Second Derivative Approximation: f ′ ′ ( x < e m > 0 ) ≈ f ( x < / e m > 0 + h ) − 2 f ( x < e m > 0 ) + f ( x < / e m > 0 − h ) h 2 f''(x<em>0) \approx \frac{f(x</em>0 + h) - 2f(x<em>0) + f(x</em>0 - h)}{h^2} f ′′ ( x < e m > 0 ) ≈ h 2 f ( x < / e m > 0 + h ) − 2 f ( x < e m > 0 ) + f ( x < / e m > 0 − h ) Derivative for Discrete Data Given data points: ( x < e m > 0 , f ( x < / e m > 0 ) ) , ( x < e m > 1 , f ( x < / e m > 1 ) ) , ( x < e m > 2 , f ( x < / e m > 2 ) ) , … , ( x < e m > n , f ( x < / e m > n ) ) (x<em>0, f(x</em>0)), (x<em>1, f(x</em>1)), (x<em>2, f(x</em>2)), …, (x<em>n, f(x</em>n)) ( x < e m > 0 , f ( x < / e m > 0 )) , ( x < e m > 1 , f ( x < / e m > 1 )) , ( x < e m > 2 , f ( x < / e m > 2 )) , … , ( x < e m > n , f ( x < / e m > n )) Assumption: Data points are equispaced, i.e., x < e m > i − x < / e m > i − 1 = h x<em>i - x</em>{i-1} = h x < e m > i − x < / e m > i − 1 = h Remark 1: Newton's divided difference (or Forward/Backward) formula can be used, depending on the point's location. Remark 2: If data is not equispaced, Lagrange interpolating polynomial can be used. Formula: f ( x ) ≈ P < e m > n ( x ) = f ( x < / e m > 0 ) + ∑ < e m > k = 1 n ( s k ) Δ k f ( x < / e m > 0 ) f(x) \approx P<em>n(x) = f(x</em>0) + \sum<em>{k=1}^{n} \binom{s}{k} \Delta^k f(x</em>0) f ( x ) ≈ P < e m > n ( x ) = f ( x < / e m > 0 ) + ∑ < e m > k = 1 n ( k s ) Δ k f ( x < / e m > 0 ) , where x = x 0 + s h x = x_0 + sh x = x 0 + s h We use P < e m > n ( x ) P<em>n(x) P < e m > n ( x ) to calculate the derivatives of f f f , i.e., f ′ ( x ) ≈ P ′ < / e m > n ( x ) f'(x) \approx P'</em>n(x) f ′ ( x ) ≈ P ′ < / e m > n ( x ) for all x ∈ [ x < e m > 0 , x < / e m > n ] x \in [x<em>0, x</em>n] x ∈ [ x < e m > 0 , x < / e m > n ] Derivative Calculation Using Newton's Forward Difference First derivative: f ′ ( x ) ≈ P ′ ( x ) = d P < e m > n d x = 1 h d P < / e m > n d s f'(x) \approx P'(x) = \frac{dP<em>n}{dx} = \frac{1}{h} \frac{dP</em>n}{ds} f ′ ( x ) ≈ P ′ ( x ) = d x d P < e m > n = h 1 d s d P < / e m > n Second derivative: f ′ ′ ( x ) ≈ d 2 P < e m > n d x 2 = 1 h 2 d 2 P < / e m > n d s 2 f''(x) \approx \frac{d^2P<em>n}{dx^2} = \frac{1}{h^2} \frac{d^2P</em>n}{ds^2} f ′′ ( x ) ≈ d x 2 d 2 P < e m > n = h 2 1 d s 2 d 2 P < / e m > n In general: f ( K ) ( x ) = 1 h K d K P n d s K f^{(K)}(x) = \frac{1}{h^K} \frac{d^KP_n}{ds^K} f ( K ) ( x ) = h K 1 d s K d K P n Example: Compute the first and second derivatives at x = 2 x = 2 x = 2 for the function defined by the following data using Taylor series expansion and Newton's forward divided difference.x: 1, 2, 3, 4 f(x): 2, 5, 7, 10 Solution using Taylor Series Here h = 1 h = 1 h = 1 f ′ ( 2 ) = f ( 2 + h ) − f ( 2 ) h = f ( 3 ) − f ( 2 ) 1 = 2 f'(2) = \frac{f(2 + h) - f(2)}{h} = \frac{f(3) - f(2)}{1} = 2 f ′ ( 2 ) = h f ( 2 + h ) − f ( 2 ) = 1 f ( 3 ) − f ( 2 ) = 2 f ′ ′ ( 2 ) = f ( 2 + h ) − 2 f ( 2 ) + f ( 2 − h ) h 2 = f ( 3 ) − 2 f ( 2 ) + f ( 1 ) 1 = 1 f''(2) = \frac{f(2 + h) - 2f(2) + f(2 - h)}{h^2} = \frac{f(3) - 2f(2) + f(1)}{1} = 1 f ′′ ( 2 ) = h 2 f ( 2 + h ) − 2 f ( 2 ) + f ( 2 − h ) = 1 f ( 3 ) − 2 f ( 2 ) + f ( 1 ) = 1 Difference table:
x: 1, 2, 3, 4 f(x): 2, 5, 7, 10 Δ f \Delta f Δ f : 3, 2, 3Δ 2 f \Delta^2 f Δ 2 f : -1, 1Δ 3 f \Delta^3 f Δ 3 f : 2f ( x ) ≈ P < e m > n ( x ) = f ( x < / e m > 0 ) + s Δ f ( x < e m > 0 ) + s ( s − 1 ) 2 ! Δ 2 f ( x < / e m > 0 ) + s ( s − 1 ) ( s − 2 ) 3 ! Δ 3 f ( x 0 ) f(x) \approx P<em>n(x) = f(x</em>0) + s\Delta f(x<em>0) + \frac{s(s - 1)}{2!} \Delta^2 f(x</em>0) + \frac{s(s - 1)(s - 2)}{3!} \Delta^3 f(x_0) f ( x ) ≈ P < e m > n ( x ) = f ( x < / e m > 0 ) + s Δ f ( x < e m > 0 ) + 2 ! s ( s − 1 ) Δ 2 f ( x < / e m > 0 ) + 3 ! s ( s − 1 ) ( s − 2 ) Δ 3 f ( x 0 )
f ′ ( x ) ≈ 1 h d P < e m > n d s = 1 h [ Δ f ( x < / e m > 0 ) + 2 s − 1 2 ! Δ 2 f ( x < e m > 0 ) + 3 s 2 − 6 s + 2 3 ! Δ 3 f ( x < / e m > 0 ) ] f'(x) \approx \frac{1}{h} \frac{dP<em>n}{ds} = \frac{1}{h} \left[\Delta f(x</em>0) + \frac{2s - 1}{2!} \Delta^2 f(x<em>0) + \frac{3s^2 - 6s + 2}{3!} \Delta^3 f(x</em>0)\right] f ′ ( x ) ≈ h 1 d s d P < e m > n = h 1 [ Δ f ( x < / e m > 0 ) + 2 ! 2 s − 1 Δ 2 f ( x < e m > 0 ) + 3 ! 3 s 2 − 6 s + 2 Δ 3 f ( x < / e m > 0 ) ]
Here x = 2 , x 0 = 1 , s = 1 , h = 1 x = 2, x_0 = 1, s = 1, h = 1 x = 2 , x 0 = 1 , s = 1 , h = 1
f ′ ( 2 ) = 3 − 1 2 + 2 6 = 13 6 f'(2) = 3 - \frac{1}{2} + \frac{2}{6} = \frac{13}{6} f ′ ( 2 ) = 3 − 2 1 + 6 2 = 6 13
f ′ ′ ( x ) ≈ 1 h 2 d 2 P < e m > n d s 2 = 1 h 2 [ Δ 2 f ( x < / e m > 0 ) + ( s − 1 ) Δ 3 f ( x 0 ) ] f''(x) \approx \frac{1}{h^2} \frac{d^2P<em>n}{ds^2} = \frac{1}{h^2} \left[\Delta^2 f(x</em>0) + (s - 1)\Delta^3 f(x_0)\right] f ′′ ( x ) ≈ h 2 1 d s 2 d 2 P < e m > n = h 2 1 [ Δ 2 f ( x < / e m > 0 ) + ( s − 1 ) Δ 3 f ( x 0 ) ]
f ′ ′ ( 2 ) = − 1 f''(2) = -1 f ′′ ( 2 ) = − 1
Example 3: Calculate f ( 4 ) ( 0.15 ) f^{(4)}(0.15) f ( 4 ) ( 0.15 )
Given data:x: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 f(x): 0.425, 0.475, 0.400, 0.450, 0.525, 0.575 Numerical Integration Basics If f : [ a , b ] → R f : [a, b] \rightarrow R f : [ a , b ] → R is integrable, we obtain a new function F : [ a , b ] → R F : [a, b] \rightarrow R F : [ a , b ] → R defined by: F ( x ) = ∫ a x f ( t ) d t F(x) = \int_{a}^{x} f(t)dt F ( x ) = ∫ a x f ( t ) d t , for all x ∈ [ a , b ] x \in [a, b] x ∈ [ a , b ] If f f f is a nonnegative function, then ∫ a b f ( x ) d x \int_{a}^{b} f(x)dx ∫ a b f ( x ) d x represents the area under the curve f ( x ) f(x) f ( x ) . Antiderivative If f = F ′ f = F' f = F ′ , then F F F is called an antiderivative of f f f . Fundamental Theorem of Calculus: If f : [ a , b ] → R f : [a, b] \rightarrow R f : [ a , b ] → R is integrable and has an antiderivative F F F , then: ∫ a b f ( x ) d x = F ( b ) − F ( a ) \int_{a}^{b} f(x)dx = F(b) - F(a) ∫ a b f ( x ) d x = F ( b ) − F ( a ) Basic Problems Difficult to find an antiderivative (e.g., f ( x ) = e − x 2 f(x) = e^{-x^2} f ( x ) = e − x 2 ). Function is given in discrete form (data points). Based on polynomial interpolation. Replace f f f by P < e m > n ( x ) P<em>n(x) P < e m > n ( x ) and evaluate ∫ < / e m > a b P n ( x ) d x \int</em>{a}^{b} P_n(x)dx ∫ < / e m > a b P n ( x ) d x ∫ < e m > a b f ( x ) d x ≈ ∫ < / e m > a b P < e m > n ( x ) d x = ∫ < / e m > a b ∑ < e m > i = 0 n L < / e m > i ( x ) f ( x < e m > i ) d x = ∑ < / e m > i = 0 n f ( x < e m > i ) ∫ < / e m > a b L < e m > i ( x ) d x = ∑ < / e m > i = 0 n A < e m > i f ( x < / e m > i ) \int<em>{a}^{b} f(x)dx \approx \int</em>{a}^{b} P<em>n(x)dx = \int</em>{a}^{b} \sum<em>{i=0}^{n} L</em>i(x)f(x<em>i)dx = \sum</em>{i=0}^{n} f(x<em>i) \int</em>{a}^{b} L<em>i(x)dx = \sum</em>{i=0}^{n} A<em>i f(x</em>i) ∫ < e m > a b f ( x ) d x ≈ ∫ < / e m > a b P < e m > n ( x ) d x = ∫ < / e m > a b ∑ < e m > i = 0 n L < / e m > i ( x ) f ( x < e m > i ) d x = ∑ < / e m > i = 0 n f ( x < e m > i ) ∫ < / e m > a b L < e m > i ( x ) d x = ∑ < / e m > i = 0 n A < e m > i f ( x < / e m > i ) Where A < e m > i = ∫ < / e m > a b L i ( x ) d x A<em>i = \int</em>{a}^{b} L_i(x)dx A < e m > i = ∫ < / e m > a b L i ( x ) d x is called the weight. Quadrature formulae or rule n=1: Trapezoidal Rule n=2: Simpson’s rule n=3: Simpson’s Three-Eighths rule n=4: Generalized formula If x < e m > 0 , … , x < / e m > n x<em>0, …, x</em>n x < e m > 0 , … , x < / e m > n are distinct numbers in [ a , b ] [a, b] [ a , b ] And f ∈ C n + 1 [ a , b ] f \in C^{n+1}[a, b] f ∈ C n + 1 [ a , b ] . Then, for all x ∈ [ a , b ] x \in [a, b] x ∈ [ a , b ] , there exists ξ ( x ) ∈ ( a , b ) \xi(x) \in (a, b) ξ ( x ) ∈ ( a , b ) such that:f ( x ) = P < e m > n ( x ) + f ( n + 1 ) ( ξ ( x ) ) ( n + 1 ) ! ( x − x < / e m > 0 ) ( x − x < e m > 1 ) … ( x − x < / e m > n ) f(x) = P<em>n(x) + \frac{f^{(n+1)}(\xi(x))}{(n + 1)!} (x - x</em>0)(x - x<em>1)…(x - x</em>n) f ( x ) = P < e m > n ( x ) + ( n + 1 )! f ( n + 1 ) ( ξ ( x )) ( x − x < / e m > 0 ) ( x − x < e m > 1 ) … ( x − x < / e m > n ) Where P < e m > n ( x ) P<em>n(x) P < e m > n ( x ) is the interpolating polynomial defined as: P < / e m > n ( x ) = ∑ < e m > i = 0 n f ( x < / e m > i ) L i ( x ) P</em>n(x) = \sum<em>{i=0}^{n} f(x</em>i)L_i(x) P < / e m > n ( x ) = ∑ < e m > i = 0 n f ( x < / e m > i ) L i ( x ) Quadrature Formula:f ( x ) ≈ ∑ < e m > i = 0 n A < / e m > i f ( x i ) f(x) \approx \sum<em>{i=0}^{n} A</em>i f(x_i) f ( x ) ≈ ∑ < e m > i = 0 n A < / e m > i f ( x i ) Error Term:E ( f ) = 1 ( n + 1 ) ! ∫ < e m > a b f ( n + 1 ) ( ξ ( x ) ) ∏ < / e m > i = 0 n ( x − x i ) d x E(f) = \frac{1}{(n + 1)!} \int<em>{a}^{b} f^{(n+1)}(\xi(x)) \prod</em>{i=0}^{n} (x - x_i) dx E ( f ) = ( n + 1 )! 1 ∫ < e m > a b f ( n + 1 ) ( ξ ( x )) ∏ < / e m > i = 0 n ( x − x i ) d x Trapezoidal Rule Objective: To approximate F = ∫ a b f ( x ) d x F = \int_{a}^{b} f(x)dx F = ∫ a b f ( x ) d x First order Lagrange polynomial: n = 1 , x < e m > 0 = a , x < / e m > 1 = b , h = ( b − a ) n = 1, x<em>0 = a, x</em>1 = b, h = (b - a) n = 1 , x < e m > 0 = a , x < / e m > 1 = b , h = ( b − a ) P < e m > n ( x ) = x − x < / e m > 1 x < e m > 0 − x < / e m > 1 f ( x < e m > 0 ) + x − x < / e m > 0 x < e m > 1 − x < / e m > 0 f ( x 1 ) P<em>n(x) = \frac{x - x</em>1}{x<em>0 - x</em>1} f(x<em>0) + \frac{x - x</em>0}{x<em>1 - x</em>0} f(x_1) P < e m > n ( x ) = x < e m > 0 − x < / e m > 1 x − x < / e m > 1 f ( x < e m > 0 ) + x < e m > 1 − x < / e m > 0 x − x < / e m > 0 f ( x 1 ) ∫ < e m > a b f ( x ) d x = ∫ < / e m > x < e m > 0 x < / e m > 1 [ x − x < e m > 1 x < / e m > 0 − x < e m > 1 f ( x < / e m > 0 ) + x − x < e m > 0 x < / e m > 1 − x < e m > 0 f ( x < / e m > 1 ) ] d x + 1 2 ∫ < e m > x < / e m > 0 x < e m > 1 f ′ ′ ( ξ ( x ) ) ( x − x < / e m > 0 ) ( x − x 1 ) d x \int<em>{a}^{b} f(x)dx = \int</em>{x<em>0}^{x</em>1} \left[\frac{x - x<em>1}{x</em>0 - x<em>1} f(x</em>0) + \frac{x - x<em>0}{x</em>1 - x<em>0} f(x</em>1)\right]dx + \frac{1}{2} \int<em>{x</em>0}^{x<em>1} f''(\xi(x))(x - x</em>0)(x - x_1)dx ∫ < e m > a b f ( x ) d x = ∫ < / e m > x < e m > 0 x < / e m > 1 [ x < / e m > 0 − x < e m > 1 x − x < e m > 1 f ( x < / e m > 0 ) + x < / e m > 1 − x < e m > 0 x − x < e m > 0 f ( x < / e m > 1 ) ] d x + 2 1 ∫ < e m > x < / e m > 0 x < e m > 1 f ′′ ( ξ ( x )) ( x − x < / e m > 0 ) ( x − x 1 ) d x Trapezoidal Rule Error The term ( x − x < e m > 0 ) ( x − x < / e m > 1 ) (x - x<em>0)(x - x</em>1) ( x − x < e m > 0 ) ( x − x < / e m > 1 ) does not change sign in [ x < e m > 0 , x < / e m > 1 ] [x<em>0, x</em>1] [ x < e m > 0 , x < / e m > 1 ] therefore applying weighted mean value theorem:∫ < e m > x < / e m > 0 x < e m > 1 f ′ ′ ( ξ ( x ) ) ( x − x < / e m > 0 ) ( x − x < e m > 1 ) d x = f ′ ′ ( ξ ) ∫ < / e m > x < e m > 0 x < / e m > 1 ( x − x < e m > 0 ) ( x − x < / e m > 1 ) d x = f ′ ′ ( ξ ) [ x 3 3 − ( x < e m > 1 + x < / e m > 0 ) x 2 2 + x < e m > 0 x < / e m > 1 x ] < e m > x < / e m > 0 x 1 = − h 3 6 f ′ ′ ( ξ ) \int<em>{x</em>0}^{x<em>1} f''(\xi(x))(x - x</em>0)(x - x<em>1)dx= f''(\xi) \int</em>{x<em>0}^{x</em>1} (x - x<em>0)(x - x</em>1)dx = f''(\xi) \Big[\frac{x^3}{3} - (x<em>1 + x</em>0) \frac{x^2}{2} + x<em>0x</em>1x \Big]<em>{x</em>0}^{x_1} = - \frac{h^3}{6} f''(\xi) ∫ < e m > x < / e m > 0 x < e m > 1 f ′′ ( ξ ( x )) ( x − x < / e m > 0 ) ( x − x < e m > 1 ) d x = f ′′ ( ξ ) ∫ < / e m > x < e m > 0 x < / e m > 1 ( x − x < e m > 0 ) ( x − x < / e m > 1 ) d x = f ′′ ( ξ ) [ 3 x 3 − ( x < e m > 1 + x < / e m > 0 ) 2 x 2 + x < e m > 0 x < / e m > 1 x ] < e m > x < / e m > 0 x 1 = − 6 h 3 f ′′ ( ξ ) ∫ < e m > a b f ( x ) d x = ( x − x < / e m > 1 ) 2 2 ( x < e m > 0 − x < / e m > 1 ) f ( x < e m > 0 ) + ( x − x < / e m > 0 ) 2 2 ( x < e m > 1 − x < / e m > 0 ) f ( x < e m > 1 ) ∣ < / e m > x < e m > 0 x < / e m > 1 − h 3 12 f ′ ′ ( ξ ) = ( x < e m > 1 − x < / e m > 0 ) 2 ( f ( x < e m > 0 ) + f ( x < / e m > 1 ) ) − h 3 12 f ′ ′ ( ξ ) \int<em>{a}^{b} f(x)dx=\frac{(x - x</em>1)^2}{2(x<em>0 - x</em>1)}f(x<em>0) + \frac{(x - x</em>0)^2}{2(x<em>1 - x</em>0)}f(x<em>1)\Big|</em>{x<em>0}^{x</em>1} − \frac{h^3}{12}f''(\xi) = \frac{(x<em>1 - x</em>0)}{2} (f(x<em>0) + f(x</em>1)) - \frac{h^3}{12}f''(\xi) ∫ < e m > a b f ( x ) d x = 2 ( x < e m > 0 − x < / e m > 1 ) ( x − x < / e m > 1 ) 2 f ( x < e m > 0 ) + 2 ( x < e m > 1 − x < / e m > 0 ) ( x − x < / e m > 0 ) 2 f ( x < e m > 1 ) < / e m > x < e m > 0 x < / e m > 1 − 12 h 3 f ′′ ( ξ ) = 2 ( x < e m > 1 − x < / e m > 0 ) ( f ( x < e m > 0 ) + f ( x < / e m > 1 )) − 12 h 3 f ′′ ( ξ ) With h = x < e m > 1 − x < / e m > 0 h = x<em>1 - x</em>0 h = x < e m > 1 − x < / e m > 0 the Trapezoidal rule is:∫ < e m > a b f ( x ) d x = h 2 ( f ( x < / e m > 0 ) + f ( x 1 ) ) − h 3 12 f ′ ′ ( ξ ) \int<em>{a}^{b} f(x)dx= \frac{h}{2} (f(x</em>0) + f(x_1)) - \frac{h^3}{12}f''(\xi) ∫ < e m > a b f ( x ) d x = 2 h ( f ( x < / e m > 0 ) + f ( x 1 )) − 12 h 3 f ′′ ( ξ ) Exact for polynomials of degree one or less as the error term involves f ′ ′ ( ξ ) f''(\xi) f ′′ ( ξ ) Simpson's 1/3 Rule Objective: To approximate F = ∫ a b f ( x ) d x F = \int_{a}^{b} f(x)dx F = ∫ a b f ( x ) d x Second order Lagrange polynomial: n = 2 , x < e m > 0 = a , x < / e m > 2 = b , x 1 = a + h , h = ( b − a ) / 2 n = 2, x<em>0 = a, x</em>2 = b, x_1 = a + h, h = (b - a)/2 n = 2 , x < e m > 0 = a , x < / e m > 2 = b , x 1 = a + h , h = ( b − a ) /2 ∫ < e m > a b f ( x ) d x = ∫ < / e m > x < e m > 0 x < / e m > 2 P n ( x ) d x + ∫ < e m > x < / e m > 0 x < e m > 2 ( x − x < / e m > 0 ) ( x − x < e m > 1 ) ( x − x < / e m > 2 ) f ′ ′ ′ ( ξ ( x ) ) 6 d x \int<em>{a}^{b} f(x)dx = \int</em>{x<em>0}^{x</em>2} Pn(x)dx + \int<em>{x</em>0}^{x<em>2} (x - x</em>0)(x - x<em>1)(x - x</em>2) \frac{f'''(\xi(x))}{6}dx ∫ < e m > a b f ( x ) d x = ∫ < / e m > x < e m > 0 x < / e m > 2 P n ( x ) d x + ∫ < e m > x < / e m > 0 x < e m > 2 ( x − x < / e m > 0 ) ( x − x < e m > 1 ) ( x − x < / e m > 2 ) 6 f ′′′ ( ξ ( x )) d x Third Taylor polynomial about x < e m > 1 x<em>1 x < e m > 1 :
f ( x ) = f ( x < / e m > 1 ) + f ′ ( x < e m > 1 ) ( x − x < / e m > 1 ) + f ′ ′ ( x < e m > 1 ) ( x − x < / e m > 1 ) 2 2 + f ′ ′ ′ ( x < e m > 1 ) ( x − x < / e m > 1 ) 3 6 + f ( 4 ) ( ξ ( x ) ) 24 ( x − x 1 ) 4 f(x) = f(x</em>1) + f'(x<em>1)(x - x</em>1) + f''(x<em>1)\frac{(x - x</em>1)^2}{2} + f'''(x<em>1)\frac{(x - x</em>1)^3}{6} + \frac{f^{(4)}(\xi(x))}{24}(x - x_1)^4 f ( x ) = f ( x < / e m > 1 ) + f ′ ( x < e m > 1 ) ( x − x < / e m > 1 ) + f ′′ ( x < e m > 1 ) 2 ( x − x < / e m > 1 ) 2 + f ′′′ ( x < e m > 1 ) 6 ( x − x < / e m > 1 ) 3 + 24 f ( 4 ) ( ξ ( x )) ( x − x 1 ) 4 Integration of the Taylor polynomial:∫ < e m > x < / e m > 0 x < e m > 2 f ( x ) d x = 2 h f ( x < / e m > 1 ) + h 3 3 f ′ ′ ( x < e m > 1 ) + f ( 4 ) ( ξ < / e m > 1 ) 60 h 5 \int<em>{x</em>0}^{x<em>2} f(x)dx = 2hf(x</em>1) + \frac{h^3}{3} f''(x<em>1) + \frac{f^{(4)}(\xi</em>1)}{60}h^5 ∫ < e m > x < / e m > 0 x < e m > 2 f ( x ) d x = 2 h f ( x < / e m > 1 ) + 3 h 3 f ′′ ( x < e m > 1 ) + 60 f ( 4 ) ( ξ < / e m > 1 ) h 5 Replacing f ′ ′ ( x < e m > 1 ) f''(x<em>1) f ′′ ( x < e m > 1 ) by its approximation:
∫ < / e m > x < e m > 0 x < / e m > 2 f ( x ) d x = h 3 [ f ( x < e m > 0 ) + 4 f ( x < / e m > 1 ) + f ( x < e m > 2 ) ] − h 5 12 ( 1 3 f ( 4 ) ( ξ < / e m > 2 ) − 1 5 f ( 4 ) ( ξ 1 ) ) \int</em>{x<em>0}^{x</em>2} f(x)dx = \frac{h}{3} [f(x<em>0) + 4f(x</em>1) + f(x<em>2)] - \frac{h^5}{12} (\frac{1}{3} f^{(4)}(\xi</em>2) - \frac{1}{5} f^{(4)}(\xi_1) ) ∫ < / e m > x < e m > 0 x < / e m > 2 f ( x ) d x = 3 h [ f ( x < e m > 0 ) + 4 f ( x < / e m > 1 ) + f ( x < e m > 2 )] − 12 h 5 ( 3 1 f ( 4 ) ( ξ < / e m > 2 ) − 5 1 f ( 4 ) ( ξ 1 )) ∫ < e m > x < / e m > 0 x < e m > 2 f ( x ) d x = h 3 [ f ( x < / e m > 0 ) + 4 f ( x < e m > 1 ) + f ( x < / e m > 2 ) ] − h 5 90 f ( 4 ) ( ξ ) \int<em>{x</em>0}^{x<em>2} f(x)dx=\frac{h}{3} [f(x</em>0) + 4f(x<em>1) + f(x</em>2)] - \frac{h^5}{90} f^{(4)}(\xi) ∫ < e m > x < / e m > 0 x < e m > 2 f ( x ) d x = 3 h [ f ( x < / e m > 0 ) + 4 f ( x < e m > 1 ) + f ( x < / e m > 2 )] − 90 h 5 f ( 4 ) ( ξ ) Simpson's 3/8 Rule Objective: To approximate F = ∫ a b f ( x ) d x F = \int_{a}^{b} f(x)dx F = ∫ a b f ( x ) d x
Third order Lagrange polynomial: n = 3 , x < e m > 0 = a , x < / e m > 3 = a + 3 h = b , x < e m > 1 = a + h , x < / e m > 2 = a + 2 h , h = ( b − a ) / 3 n = 3, x<em>0 = a, x</em>3 = a + 3h = b, x<em>1 = a + h, x</em>2 = a + 2h, h = (b - a)/3 n = 3 , x < e m > 0 = a , x < / e m > 3 = a + 3 h = b , x < e m > 1 = a + h , x < / e m > 2 = a + 2 h , h = ( b − a ) /3
∫ < e m > x < / e m > 0 x < e m > 3 f ( x ) d x = 3 h 8 [ f ( x < / e m > 0 ) + 3 f ( x < e m > 1 ) + 3 f ( x < / e m > 2 ) + f ( x 3 ) ] − 3 h 5 80 f ( 4 ) ( ξ ) \int<em>{x</em>0}^{x<em>3} f(x)dx = \frac{3h}{8} [f(x</em>0) + 3f(x<em>1) + 3f(x</em>2) + f(x_3)] - \frac{3h^5}{80} f^{(4)}(\xi) ∫ < e m > x < / e m > 0 x < e m > 3 f ( x ) d x = 8 3 h [ f ( x < / e m > 0 ) + 3 f ( x < e m > 1 ) + 3 f ( x < / e m > 2 ) + f ( x 3 )] − 80 3 h 5 f ( 4 ) ( ξ ) , with ξ ∈ ( a , b ) \xi \in (a, b) ξ ∈ ( a , b )
Example 4: Using Trapezoidal, Simpson 1/3 and 3/8 rules, find ∫ < e m > 0 2 x 4 d x \int<em>{0}^{2} x^4 dx ∫ < e m > 0 2 x 4 d x and ∫ < / e m > 0 2 s i n ( x ) d x \int</em>{0}^{2} sin(x) dx ∫ < / e m > 0 2 s in ( x ) d x and find the upper bound for the error.
Composite Rules If the interval [ a , b ] [a, b] [ a , b ] is large, the error using Trapezoidal or Simpson's rule will be large. Idea: Divide [ a , b ] [a, b] [ a , b ] into equal subintervals and apply Trapezoidal or Simpson's rules in each subinterval to reduce error. Composite Simpson's Rule With h = ( b − a ) / n h = (b - a)/n h = ( b − a ) / n and x j = a + j h x_j = a + jh x j = a + j h , for j = 0 , 1 , … , n j = 0, 1, …, n j = 0 , 1 , … , n ∫ < e m > a b f ( x ) d x = ∑ < / e m > j = 1 n / 2 ∫ < e m > x < / e m > 2 j − 2 x < e m > 2 j f ( x ) d x = ∑ < / e m > j = 1 n / 2 h 3 [ f ( x < e m > 2 j − 2 ) + 4 f ( x < / e m > 2 j − 1 ) + f ( x < e m > 2 j ) ] − h 5 90 f ( 4 ) ( ξ < / e m > j ) \int<em>{a}^{b} f(x)dx = \sum</em>{j=1}^{n/2} \int<em>{x</em>{2j-2}}^{x<em>{2j}} f(x)dx = \sum</em>{j=1}^{n/2} \frac{h}{3} [f(x<em>{2j-2}) + 4f(x</em>{2j-1}) + f(x<em>{2j})] - \frac{h^5}{90} f^{(4)}(\xi</em>j) ∫ < e m > a b f ( x ) d x = ∑ < / e m > j = 1 n /2 ∫ < e m > x < / e m > 2 j − 2 x < e m > 2 j f ( x ) d x = ∑ < / e m > j = 1 n /2 3 h [ f ( x < e m > 2 j − 2 ) + 4 f ( x < / e m > 2 j − 1 ) + f ( x < e m > 2 j )] − 90 h 5 f ( 4 ) ( ξ < / e m > j ) ∫ < e m > a b f ( x ) d x = h 3 f ( x < / e m > 0 ) + 2 ∑ < e m > j = 1 ( n / 2 ) − 1 f ( x < / e m > 2 j ) + 4 ∑ < e m > j = 1 n / 2 f ( x < / e m > 2 j − 1 ) + f ( x < e m > n ) − h 5 90 ∑ < / e m > j = 1 n / 2 f ( 4 ) ( ξ j ) \int<em>{a}^{b} f(x)dx= \frac{h}{3} f(x</em>0) + 2 \sum<em>{j=1}^{(n/2)-1} f(x</em>{2j}) + 4\sum<em>{j=1}^{n/2} f(x</em>{2j-1}) + f(x<em>n) − \frac{h^5}{90} \sum</em>{j=1}^{n/2} f^{(4)}(\xi_j) ∫ < e m > a b f ( x ) d x = 3 h f ( x < / e m > 0 ) + 2 ∑ < e m > j = 1 ( n /2 ) − 1 f ( x < / e m > 2 j ) + 4 ∑ < e m > j = 1 n /2 f ( x < / e m > 2 j − 1 ) + f ( x < e m > n ) − 90 h 5 ∑ < / e m > j = 1 n /2 f ( 4 ) ( ξ j ) Composite Simpson's Rule Error Error: E ( f ) = − h 5 90 ∑ < e m > j = 1 n / 2 f ( 4 ) ( ξ < / e m > j ) E(f) = - \frac{h^5}{90} \sum<em>{j=1}^{n/2} f^{(4)}(\xi</em>j) E ( f ) = − 90 h 5 ∑ < e m > j = 1 n /2 f ( 4 ) ( ξ < / e m > j ) for ξ < e m > j ∈ ( x < / e m > 2 j − 2 , x 2 j ) \xi<em>j \in (x</em>{2j-2}, x_{2j}) ξ < e m > j ∈ ( x < / e m > 2 j − 2 , x 2 j ) and j = 1 , … , n / 2 j = 1, …, n/2 j = 1 , … , n /2 If f ∈ C 4 [ a , b ] f \in C^4[a, b] f ∈ C 4 [ a , b ] , there exists μ ∈ ( a , b ) \mu \in (a, b) μ ∈ ( a , b ) such that:E ( f ) = − ( b − a ) 180 h 4 f ( 4 ) ( μ ) E(f) = - \frac{(b - a)}{180} h^4 f^{(4)}(\mu) E ( f ) = − 180 ( b − a ) h 4 f ( 4 ) ( μ ) Composite Simpson's Rule Theorem Let f ∈ C 4 [ a , b ] f \in C^4[a, b] f ∈ C 4 [ a , b ] and n be even, h = ( b − a ) / n h = (b - a)/n h = ( b − a ) / n , x < e m > j = a + j h x<em>j = a + jh x < e m > j = a + j h , for j = 0 , 1 , … , n j = 0, 1, …, n j = 0 , 1 , … , n . There exists a μ ∈ ( a , b ) \mu \in (a, b) μ ∈ ( a , b ) for which the Composite Simpson’s rule for n subintervals can be written with its error term as:
∫ < / e m > a b f ( x ) d x = h 3 f ( a ) + 2 ∑ < e m > j = 1 ( n / 2 ) − 1 f ( x < / e m > 2 j ) + 4 ∑ < e m > j = 1 n / 2 f ( x < / e m > 2 j − 1 ) + f ( b ) − ( b − a ) 180 h 4 f ( 4 ) ( μ ) \int</em>{a}^{b} f(x)dx=\frac{h}{3} f(a) + 2 \sum<em>{j=1}^{(n/2)-1} f(x</em>{2j}) + 4\sum<em>{j=1}^{n/2} f(x</em>{2j-1}) + f(b) − \frac{(b - a)}{180} h^4 f^{(4)}(\mu) ∫ < / e m > a b f ( x ) d x = 3 h f ( a ) + 2 ∑ < e m > j = 1 ( n /2 ) − 1 f ( x < / e m > 2 j ) + 4 ∑ < e m > j = 1 n /2 f ( x < / e m > 2 j − 1 ) + f ( b ) − 180 ( b − a ) h 4 f ( 4 ) ( μ ) Composite Trapezoidal Rule Theorem Let f ∈ C 2 [ a , b ] f \in C^2[a, b] f ∈ C 2 [ a , b ] and h = ( b − a ) / n , x < e m > j = a + j h h = (b - a)/n, x<em>j = a + jh h = ( b − a ) / n , x < e m > j = a + j h , for j = 0 , 1 , … , n j = 0, 1, …, n j = 0 , 1 , … , n . There exists a μ ∈ ( a , b ) \mu \in (a, b) μ ∈ ( a , b ) for which the Composite Trapezoidal rule for n subintervals can be written with its error term as:
∫ < / e m > a b f ( x ) d x = h 2 f ( a ) + 2 ∑ < e m > j = 1 ( n − 1 ) f ( x < / e m > j ) + f ( b ) − ( b − a ) 12 h 2 f ′ ′ ( μ ) \int</em>{a}^{b} f(x)dx=\frac{h}{2} f(a) + 2 \sum<em>{j=1}^{(n-1)} f(x</em>{j}) + f(b) − \frac{(b - a)}{12} h^2 f''(\mu) ∫ < / e m > a b f ( x ) d x = 2 h f ( a ) + 2 ∑ < e m > j = 1 ( n − 1 ) f ( x < / e m > j ) + f ( b ) − 12 ( b − a ) h 2 f ′′ ( μ ) Composite Midpoint Rule Theorem Let f ∈ C 2 [ a , b ] f \in C^2[a, b] f ∈ C 2 [ a , b ] and n n n an even number, h = ( b − a ) / ( n + 2 ) , x < e m > j = a + ( j + 1 ) h h = (b - a)/(n + 2), x<em>j = a + (j + 1)h h = ( b − a ) / ( n + 2 ) , x < e m > j = a + ( j + 1 ) h , for j = − 1 , 0 , 1 , … , n + 1 j = -1, 0, 1, …, n + 1 j = − 1 , 0 , 1 , … , n + 1 . There exists a μ ∈ ( a , b ) \mu \in (a, b) μ ∈ ( a , b ) for which the Composite Midpoint rule for n + 2 n + 2 n + 2 subintervals can be written with its error term as:
∫ < / e m > a b f ( x ) d x = 2 h ∑ < e m > j = 0 n / 2 f ( x < / e m > 2 j ) + ( b − a ) 6 h 2 f ′ ′ ( μ ) \int</em>{a}^{b} f(x)dx= 2h\sum<em>{j=0}^{n/2} f(x</em>{2j}) + \frac{(b - a)}{6} h^2 f''(\mu) ∫ < / e m > a b f ( x ) d x = 2 h ∑ < e m > j = 0 n /2 f ( x < / e m > 2 j ) + 6 ( b − a ) h 2 f ′′ ( μ )
Example 6: Determine values of n that will ensure an approximation error of less than 0.00002 when approximating ∫ 0 π s i n ( x ) d x \int_{0}^{\pi} sin(x)dx ∫ 0 π s in ( x ) d x employing:
(a) Composite Trapezoidal rule (b) Composite Simpson’s rule For each case, approximate the integral with the smallest possible n.