You are on page 1of 17

# Numerical Analysis

Lecture 20

DIFFERENTIATION

Lecture 19

P1

Eng. Malek Abuwarda

Malek Abuwarda . The mathematical definition of the derivative begins with a difference approximation: Δy f ( x i + Δx ) − f ( x i ) = Δx Δx Lecture 19 P2 f ( x i + Δx ) − f ( x i ) dy = lim dx Δx →0 Δx Eng.Numerical Differentiation  Differentiation Differentiate means to mark off by differences or to perceive the differences in or between.

Numerical Differentiation  Forward Divided Difference f '(x i ) ≅ f ( x i +1 ) − f ( x i ) x i +1 − x i f ' ' ( xi ) ≅ f ( xi + 2 ) − 2 f ( xi +1 ) + f ( xi ) h2  Backward Divided Difference f ( x i ) − f ( x i −1 ) h f ( xi ) − 2 f ( xi −1 ) + f ( xi − 2 ) ( ) f ' ' xi ≅ h2 f '(x i ) ≅  Central Divided Difference f ( x i +1 ) − f ( x i −1 ) f '(x i ) ≅ 2(h ) f (xi +1 ) − 2 f ( xi ) + f ( xi −1 ) ( ) f ' ' xi ≅ 2 h Lecture 19 P3 Eng. Malek Abuwarda .

2 at x = 0.0 f (1.2 x i +1 = 1.2 − 0.backward and centered difference approximations to estimate the first derivative of f (x ) = −0.5 with h = 0. f ( 0.2 Forward difference f ( x i +1 ) − f ( x i ) 0.45 f '(x i ) ≅ h 0.25x + 1.5 ) = 0.925 ⇒ f ' ( 0.) = 1.Numerical Differentiation  Example 1 Use forward .15x 3 − 0.9125) Solution h = 0.1x 4 − 0.5 ) ≅ = −1.0 ) = 0.925 x i −1 = 0. Malek Abuwarda .5 f ( 0.5 Lecture 19 P4 Eng.25 (exact solution = -0.5 and 0.5x 2 − 0.5 x i = 0.

5 ) ≅ = −0.925 − 1.5 ) ≅ − 0.2 ⇒ f ' ( 0.) = 1.1035 x i +1 = 0.5 ) ≅ − 0.00 2(h ) 2 × 0.155 Backward difference ⇒ f ' ( 0.925 x i −1 = 0.934 Lecture 19 P5 Eng.6363 Forward difference ⇒ f ' ( 0.5 Centered difference f ( x i +1 ) − f ( x i −1 ) 0.5 h = 0.2 − 1.25 x i = 0.2 f '(x i ) ≅ ⇒ f ' ( 0.5 ) ≅ − 1.75 f (1.Numerical Differentiation Backward difference f ( x i ) − f ( x i −1 ) 0.5 f ( 0.55 f '(x i ) ≅ h 0.5 ) ≅ = −1.25 f ( 0.0 ) = 0.714 Centered difference ⇒ f ' ( 0. Malek Abuwarda .5 ) = 0.

t = 1.3sec and t = 1.1 1.75 10.0 1.03 Estimate velocity (dy/dt) and acceleration (dv/dt = d2y/dt2) at t = 1sec.4 1.40 8. sec 1.78 9.1)2 Lecture 19 P6 Eng.0 ≅ = = 4m / sec Velocity = dt h 0.1 d 2 y f (xi + 2 ) − 2 f ( xi +1 ) + f ( xi ) 8.78 − 2(8.45 9.Numerical Differentiation Example 2 An airplane’s position was timed during landing t.4 ) + 8 2 ≅ = − 2 / sec Acceleration = 2 ≅ m dt h2 (0. m 8. Malek Abuwarda .00 8.5 1.6 y.6sec Solution h = 0.2 1.4 − 8.13 9.3 1.1 At t = 1sec (using Forward Divided Difference) dy f ( xi +1 ) − f ( xi ) 8.

3sec (using Central Divided Difference) dy f ( xi +1 ) − f ( xi −1 ) 9.75) + 9.45 2 ≅ = − 2 / sec Acceleration = 2 ≅ m dt h2 (0.1 d 2 y f ( xi ) − 2 f ( xi −1 ) + f ( xi − 2 ) 10.45 − 8.1) d 2 y f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 ) 9.1)2 Velocity = Lecture 19 P7 Eng.6sec (using Backward Divided Difference) dy f ( xi ) − f ( xi −1 ) 10.Numerical Differentiation At t = 1.03 − 2(9.75 ≅ = = 2.35m / sec ≅ = dt 2h 2(0. Malek Abuwarda .78 Velocity = = 3.1) At t = 1.78 2 Acceleration = 2 ≅ ≅ = − 3 m / sec 2 dt h2 (0.03 − 9.45 − 2(9.13) + 8.8m / sec dt h 0 .

in ⎞ ' f (x i +1) ≅ f (x i ) + f (x i )h ⎜ ⎟ form of a straigh t line ⎝ ⎠ Lecture 19 P8 Eng. Malek Abuwarda . + 3! (n ) (x i )h n + Rn n! (ξ ) n +1 Rn = h the remainder term to account for all terms from n+1 to infinity (n + 1)! the ξ is a value of x that lies somewhere between x i and x i+1 f ( n +1) ⎛ zero order approximation. and its derivatives at another point General Expression f ''(x i )h 2 f f (x i +1 ) = f (x i ) + f (x i )h + + 2! Where: h = x i +1 − x i ' (3) (x i )h 3 f + .Numerical Differentiation  Taylor Series – Definition It provides means to predict a functional value at one point in terms of the function value.. only true if ⎞ f (x i +1) ≅ f (x i ) ⎜ ⎟ x and x are very close to each oth er i ⎝ i+1 ⎠ ⎛ first order approximation..

Malek Abuwarda ..High Accuracy Differentiation Formulas  High-accuracy divided-difference formulas High-accuracy finite-difference formulas can be generated by including additional terms from the Taylor series expansion Taylor series expansion 2 f ''( x ) h f i f (x i +1 ) ≅ f (x i ) + f ' (x i )h + + 2! (3) (x i )h 3 f + .. + 3! (n ) (x i )h n + Rn n! Solve for f ' ( x i ) −f ( x i + 2 ) + 4f ( x i +1 ) − 3f ( x i ) f ′(x i ) ≅ ( forward finite-divided-difference ) 2h 3f ( x i ) − 4f ( x i −1 ) + f ( x i − 2 ) ′ f (x i ) ≅ ( backward finite-divided-difference ) 2h −f ( x i + 2 ) + 8f ( x i +1 ) − 8f ( x i −1 ) + f ( x i − 2 ) f ′(x i ) ≅ ( centered finite-divided-difference ) 12 h Lecture 19 P9 Eng.

High Accuracy Differentiation Formulas  Forward finite-divided-difference formulas: Lecture 19 P10 Eng. Malek Abuwarda .

High Accuracy Differentiation Formulas  Backward finite-divided-difference formulas: Lecture 19 P11 Eng. Malek Abuwarda .

High Accuracy Differentiation Formulas  Centered finite-divided-difference formulas: Lecture 19 P12 Eng. Malek Abuwarda .

25 x i = 0.2 at x = 0.6363 f (1.25 ) = 1.75 x i + 2 = 1.25 (exact solution = -0.15x 3 − 0.1035 f ( 0.) = 1.00 Lecture 19 f ( 0.925 f ( 0. x i −1 = 0.50 x i +1 = 0.5 with h = 0.2 f ( 0.75 ) = 0.5 ) = 0.High Accuracy Differentiation Formulas  Example 3 Use High Accuracy Differentiation Formulas to estimate the first derivative of f (x ) = −0.0 ) = 0.9125) Solution h = 0.2 P13 Eng.25x + 1.1x 4 − 0.5 x i − 2 = 0.5x 2 − 0. Malek Abuwarda .

925) = −0.035156) + 1.925) − 4(1.2 + 8(0.6363281) − 3(0. Malek Abuwarda .5 ) ≅ 3(0.9125 12(0.5 ) ≅ 2(0.0351) = −0.8594 f ′ ( 0.8781 2(0.High Accuracy Differentiation Formulas Forward difference −f ( x i + 2 ) + 4f ( x i +1 ) − 3f ( x i ) f ′(x i ) ≅ 2h −0.5 ) ≅ Lecture 19 −0.2 = −0.25) Centered difference f ′ ( 0.25) P14 Eng.25) Backward difference f ′ ( 0.6363) − 8(1.2 + 4(0.

Forward difference Backward difference Centered difference Basic formulas Estimate -1.934 εt 26.8594 -0.58% 21.9125 εt 5.82% 3.75% 2.25 Lecture 19 P15 Eng.36% HighAccuracy formulas High Accuracy Differentiation Formulas Estimate -0.77% 0.00% h = 0.155 -0.714 -0.8781 -0. Malek Abuwarda .

6sec (use High Accuracy Formulas) Solution h = 0.6 y.00 8. sec 1.1) dt 2h d 2 y − f ( xi +3 ) + 4 f ( xi + 2 ) − 5 f ( xi +1 ) + 2 f ( xi ) Acceleration = 2 ≅ h2 dt − 9. m 8.1m / sec 2(0.4 1. t = 1.78 9.03 Estimate velocity (dy/dt) and acceleration (dv/dt = d2y/dt2) at t = 1sec.1 At t = 1sec (using Forward Finite-Deference) Velocity = dy − f ( xi + 2 ) + 4 f ( xi +1 ) − 3 f (xi ) − 8.3sec and t = 1.High Accuracy Differentiation Formulas Example 4 An airplane’s position was timed during landing t.75 10.1)2 Lecture 19 P16 Eng.13 + 4(8.13 9.0 ) = ≅ = 4.78 + 4(8.40 8.3 1.45 9. Malek Abuwarda .4 ) + 2(8) 2 ≅ = − 1 m / sec (0.78) − 5(8.5 1.0 1.1 1.2 1.4 ) − 3(8.

1)2 Lecture 19 P17 Eng.45) − 30(9.75 + 16(9. Malek Abuwarda .45) − 8(8.45) − 9.7 m / sec dt 2h 2(0.4 ≅ = 3.13) + 16(8.6sec (using Backward Finite-Deference) Velocity = dy 3 f ( xi ) − 4 f ( xi −1 ) + f ( xi − 2 ) 3(10.1) d 2 y 2 f ( xi ) − 5 f ( xi −1 ) + 4 f ( xi − 2 ) − f ( xi −3 ) Acceleration = 2 ≅ h2 dt 2(10.34m / sec 12(0.1) d 2 y − f ( xi + 2 ) + 16 f ( xi +1 ) − 30 f ( xi ) + 16 f ( xi −1 ) − f ( xi − 2 ) Acceleration = 2 ≅ dt 12h 2 − 9.High Accuracy Differentiation Formulas At t = 1.75) + 4(9.78) − 8.75) + 9.78) + 8.45 ≅ = = 2.1m / sec 2 2 12(0.3sec (using Centered Finite-Deference) Velocity = dy − f (xi + 2 ) + 8 f ( xi +1 ) − 8 f ( xi −1 ) + f ( xi − 2 ) ≅ dt 12h − 9.13 2 ≅ = − 2 m / sec (0.4 ≅ = −3.1) At t = 1.03) − 4(9.75 + 8(9.03) − 5(9.