Fall 2014 MAT 375 Numerical Metods (Capter 9)
Idea: Definition of te derivative at x Obviuos approximation: f (x) = lim 0 f (x + ) f (x) f (x) f (x + ) f (x) forward-difference formula? ow good is tis approximation wit respect to
Taylor s teorem: so f (x + ) = f (x) + f (x) + 2 2 f (ξ), ξ [x, x + ] f (x) = f (x + ) f (x) 2 f (ξ) Te term 2 f (ξ) is truncation/discretization error It is of order, so we ave 1st order approximation.
Let s generalize Mes on [a, b]: a = x 0 < x 1 < < x N 1 < x N = b, wit x i = a + i, step of discretization = (b a)/n Forward-difference formula f (x i ) f x,i = f (x i+1) f (x i ) Backward-difference formula f (x i ) f x,i = f (x i) f (x i 1 ) Centered-difference formula f (x i ) f x,i = f (x i+1) f (x i 1 ) 2
Truncation errors f x,i = f (x i ) + 2 f (ξ i ); f x,i = f (x i ) + 2 f (ξ i ) similar to f x,i For centered-difference formula: Taylor s teorem: f (x + ) = f (x) + f (x) + 2 2 f (x) + 3 6 f (ξ), ξ [x, x + ] f (x ) = f (x) f (x) + 2 2 f (x) 3 6 f (η), η [x, x] Ten for x = x i So f x,i = f (x i+1) f (x i 1 ) 2 = f (x i ) + 2 12 (f (ξ i ) + f (η i )) f x,i = f (x i ) + 2 6 f (ξ i ), 2nd degree ξ i [x i 1, x i+1 ]
Some conclusions Forward-difference formula: f x,i = f (x i) f (x i 1 ) Backward-difference formula: f x,i = f (x i+1) f (x i ) = f (x i ) + O() = f (x i ) + O() Centered-difference formula: f x,i = f (x i+1) f (x i 1 ) 2 = f (x i ) + O( 2 )
Examples: f (x) = e x at x = 1 f (x) = e x and f (1) = e at x = 1 Taking = 1/8: f (1) f x = e1+0.125 e 0.125 = 2.895480164 Errors: f (1) f x = e1+0.125 e 1 0.125 0.125 Err(f x ) = 0.17777... = 2.2536622 Err(f x ) = 7.084... 10 3
Wat appens if 0? Approximating f (x) for f (x) = e x at x = 1 1 f x Error f x Error 2 3.526814461-0.808532e+00 2.832967758-0.114686e+00 4 3.088244438-0.36996e+00 2.746685505-0.284037e-01 8 2.895481110-0.177199e+00 2.725366592-0.708484e-02 16 2.805027008-0.867452e-01 2.720052719-0.177097e-02 32 2.761199951-0.429182e-01 2.718723297-0.441551e-03 64 2.739639282-0.213575e-01 2.718391418-0.109672e-03 128 2.728942871-0.106611e-01 2.718307495-0.257492e-04 Conclusion: Error 0 as 0 and Err(f x ) < Err(f x ) (or Err(f x )) So if we take to be small, life is good. Or is it?
Wat about roundoff error? Let f (x) be te rounded value of f (x). Ten f (x) = f (x)(1 + ε) fx = f (x + ) f (x) f (x + ) f (x) = Since δ i < ε - macine epsilon Rounding error = f (x + )(1 + δ 1) f (x)(1 + δ 2 ) + δ 1f (x + ) δ 2 f (x) δ 1 f (x + ) δ 2 f (x) ε ( f (x + ) + f (x) ) ε Rounding error ε as 0 Is it te end of te world as we know it?
Best results: truncation error rounding error 2 f (ξ) ε ( f (x + ) + f (x) ) ε So ε ten Error ε
Example: Find f x for f (x) = sin x at x = π/3 f (π/3) = 0.5 ε 10 8
How about centered-difference f x? Let f (x) be te rounded value of f (x). Ten f (x) = f (x)(1 + ε) f x = f (x + ) f (x ) 2 f (x + ) f (x ) = 2 Since δ i < ε - macine epsilon Rounding error = f (x + )(1 + δ 1) f (x )(1 + δ 2 ) 2 + δ 1f (x + ) δ 2 f (x ) 2 δ 1 f (x + ) δ 2 f (x ) 2 ε 2 ( f (x + ) + f (x ) ) ε
Best results: truncation error rounding error 2 6 f (ξ) 2 ε ε ( f (x + ) + f (x ) ) 2 So ε 1/3 ten Error ε 2/3
Example: Find f x for f (x) = sin x at x = π/3 f (π/3) = 0.5 ε 1/3 10 5
Higer-order derivatives f (x i ) f xx,i = f x,i f x,i = f (x i+1) 2f (x i ) + f (x i 1 ) 2 Error: Taylor s expansion of f (x i+1 ) and f (x i 1 ) at point x i : f xx,i = f (x i ) + 2 12 f (4) (ξ i ) Truncation error 2 (2nd order) Rounding error ε 2 (ε is macine epsilon) Best results: ε 2 2 ε 1/4 wit Err ε (if ε 10 6, ten 10 4 )
Unappy conclusion: Operation of numerical differentiation is ill-conditioned: Error as 0 Solution: coose so tat truncation error rounding error
Using polynomial interpolation for numerical differentiation f (x) = p n (x) f (x) = p n(x)
Mes on [a, b]: a = x 0 < x 1 < < x n 1 < x n = b Lagrange form of interpolation polynomial: f (x) = p n (x) + R n (x) n = f (x k )L k (x) + (x x 0)... (x x n ) f (n+1) (ξ(x)) (n + 1)! k=1 wit L k (x) = n i=0 i k x x i x k x i Differentiate: n [ ] (x f (x) = f (x k )L k (x) + D x0 )... (x x n ) x f (n+1) (ξ(x)) (n + 1)! k=1 + (x x 0)... (x x n ) ] D x [f (n+1) (ξ(x)) (n + 1)!
f (x) = n [ ] (x f (x k )L k (x) + D x0 )... (x x n ) x f (n+1) (ξ(x)) (n + 1)! k=1 + (x x 0)... (x x n ) ] D x [f (n+1) (ξ(x)) (n + 1)! How to estimate te truncation error? If we take x = x i for i = 0,..., n ten (x x 0)... (x x n ) (n + 1)! = 0 Ten f (x i ) = n k=1 f (x k )L k (x i) + f (n+1) (ξ(x i )) (n + 1)! (n + 1)-point formula to approximate f (x i ) n (x i x j ) j=0 j i