AlidN i lApplied Numerical Analysis - دانشگاه صنعتی شریف - خانه fatemizadeh/Courses/ANA/07-Differentiation...AlidN i lApplied Numerical Analysis Differentiation and Integration Lecturer: Emad Fatemizadeh Applied Numerical Methods E. Fatemizadeh Numerical DifferentiationNumerical Differentiation Need for numerical differentiation:

  • View
    213

  • Download
    0

Embed Size (px)

Transcript

  • A li d N i lA li d N i lApplied Numerical Applied Numerical AnalysisAnalysisAnalysisAnalysis

    Differentiation and IntegrationDifferentiation and IntegrationLecturer: Emad FatemizadehLecturer: Emad FatemizadehLecturer: Emad FatemizadehLecturer: Emad Fatemizadeh

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Need for numerical differentiation:Need for numerical differentiation:Need for numerical differentiation:Need for numerical differentiation: No explicit function (x(t) No explicit function (x(t) v(t)=?)v(t)=?) Too complex functionToo complex function Too complex functionToo complex function

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Initial Ideas:Initial Ideas:Initial Ideas:Initial Ideas:( ) ( ) ( ) ( ) ( )2 31 1

    2! 3!f x h f x hf x h f x h f x + = + + + +

    ( ) ( ) ( ) ( ) ( )21 12! 3!

    f x h f xf x hf x h f x

    h+

    = + + +

    ( ) ( ) ( ) ( ) ( )

    ( ) ( )

    2 31 12 3!

    1 1

    f x h f x hf x h f x h f x

    f x f x h

    = + +

    ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( )

    2

    2

    1 12 3!1

    f x f x hf x hf x h f x

    hf x h f x h

    f h f

    = +

    +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

    ( ) ( ) ( ) ( )22 3!

    f ff x h f x

    h = + +

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Forward and Backward EstimationForward and Backward EstimationForward and Backward EstimationForward and Backward Estimation

    ( ) ( )Forward Estimation:

    f x h f x+( ) ( ) ( )

    Backward Estimation:

    f x h f xf x

    h+

    ( ) ( ) ( )f x f x hf xh

    ( ) ( ) ( )Central:

    f x h f x hf x

    +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

    ( )2

    f xh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Richardson Method:Richardson Method:Richardson Method:Richardson Method:

    ( ) ( ) ( ) ( )2 8 8 2f h f h f h f h+ + + +( ) ( ) ( ) ( ) ( )

    ( ) ( )54

    2 8 8 212

    f x h f x h f x h f x hf x

    hh f c

    + + + +

    ( )30

    h f cE =

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Example:Example:Example:Example:( ) ( )cos , 0.8, 0.01f h = = =

    MethodMethod ForwardForward BackwardBackward AverageAverage RichardsonRichardson

    ErrorError --0.00350.0035 0.00350.0035 1.1956e1.1956e--005005 2.3911e2.3911e--010010

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    22ndnd DerivativeDerivative22 DerivativeDerivative

    ( ) ( ) ( ) ( )22f x h f x h f x h f x+ + = + +( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )422

    2

    2 112

    f x h f x h f x h f x

    f x h f x f x hf x h f c

    h

    + + = + +

    + + = +

    ( ) ( ) ( ) ( )2

    122

    hf x h f x f x h

    f xh

    + +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Gauss Method:Gauss Method:Gauss Method:Gauss Method: We have a set of We have a set of xxii and and ffii for for ii==00,,11,,,,NN

    N( ) ( )

    ( )0

    1

    Nk

    i i ii

    n

    f x A f

    f x x x=

    =

    Now solve for (n+1) unknown parameters.Now solve for (n+1) unknown parameters.( ) 1, , ,f x x x=

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Gauss MethodGauss Method--Example (1Example (1stst):):Gauss MethodGauss Method Example (1Example (1 ):): We have (xWe have (xii,f,fii), (x), (xi+1i+1,f,fi+1i+1))

    ( ) ( ) ( )( ) ( ) ( )

    1

    11 0i i i

    i i

    f x Af x Bf x

    f x Af x Bf x A B+ = +

    = = + = +( ) ( ) ( )( ) ( ) ( )

    ( ) ( )

    1

    1 1

    1 0

    1

    1

    i i

    i i i i

    f x Af x Bf x A B

    f x x Af x Bf x Ax Bx

    f x f x

    +

    + +

    + +

    = = + = +

    ( ) ( ) ( )11 1

    1 i ii

    i i i i

    f x f xA B f x

    x x x x+

    + +

    = = =

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Gauss MethodGauss Method--Example(1Example(1stst):):Gauss MethodGauss Method Example(1Example(1 ):): We have (xWe have (xii--11,f,fii--11), (x), (xii,f,fii), (x), (xi+1i+1,f,fi+1i+1)) xx == h xh x =0 x=0 x =h=h xxii--11==--h, xh, xii=0, x=0, xi+1i+1=h=h

    ( ) ( ) ( ) ( )1 1i i i if x Af x Bf x Cf x+ = + +( )( ) ( ) ( ) ( )

    1 0

    1 0

    f x A B C

    f x x A h B C h

    = = + +

    = = + + +

    ( ) ( ) ( ) ( )

    ( ) ( ) ( )

    2 2 2

    1 1

    2 0 0i

    i i

    f x x x A h B C h

    f x f xf +

    = = = + +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

    ( ) ( ) ( )1 12

    i iif x h

    + =

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Gauss MethodGauss Method--Example(2Example(2ndnd):):Gauss MethodGauss Method Example(2Example(2 ):): We have (xWe have (xii--11,f,fii--11), (x), (xii,f,fii), (x), (xi+1i+1,f,fi+1i+1)) xx == h xh x =0 x=0 x =h=h xxii--11==--h, xh, xii=0, x=0, xi+1i+1=h=h

    ( ) ( ) ( ) ( )1 1i i i if x Af x Bf x Cf x+ = + +( )( ) ( ) ( ) ( )

    1 0

    0 0

    f x A B C

    f x x A h B C h

    = = + +

    = = + + +

    ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( )

    2 2 2

    1 1

    2 0

    2i i i

    f x x A h B C h

    f x f x f x+

    = = + +

    +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

    ( ) ( ) ( ) ( )1 122i i i

    i

    f x f x f xf x

    h+ + =

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Introduction the Introduction the zz operator:operator:Introduction the Introduction the zz operator:operator:

    ( )( ) ( )1i iz f x f x +=( )( ) ( )( )( ) ( )

    22

    11

    i i

    i i

    z f x f x

    z f x f x+

    =

    =( )( ) ( )( )( ) ( )2 2i iz f x f x =

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Summary of Method for 1Summary of Method for 1stst derivative:derivative:Summary of Method for 1Summary of Method for 1 derivative:derivative:1z

    h

    1

    1

    1 zh

    1

    1

    24 3

    z zh

    z z

    +

    2 1 2

    4 328 8

    z zh

    z z z z

    +

    + +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

    12h

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Summary of Method for 2Summary of Method for 2stst derivative:derivative:Summary of Method for 2Summary of Method for 2 derivative:derivative:1

    2

    2z zh

    +

    1 2 2 1

    2 2

    4 5 2 4 5 2h

    z z z z z zh h

    + + + +

    2 1 2

    2

    3 1 3 22

    z z z zh

    + +

    2 1 2

    2

    16 30 1612

    z z z zh

    + +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Summary of Method for 3rd derivative:Summary of Method for 3rd derivative:Summary of Method for 3rd derivative:Summary of Method for 3rd derivative:1 2 2 1

    3 3

    3 3 3 3z z z z z zh h

    + +

    2 1 2

    3

    2 22

    h hz z z z

    h

    +

    Summary of Method for 3rd derivative:Summary of Method for 3rd derivative:

    2 1 2

    4

    4 6 4z z z zh

    + +

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

    h

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Differentiation Using Interpolation:Differentiation Using Interpolation:Differentiation Using Interpolation:Differentiation Using Interpolation: Find an interpolator or do curve fitting:Find an interpolator or do curve fitting: Take DerivativeTake Derivative Take Derivative.Take Derivative.

    Applied Numerical MethodsApplied Numerical MethodsE. FatemizadehE. Fatemizadeh

  • Numerical DifferentiationNumerical DifferentiationNumerical DifferentiationNumerical Differentiation

    Example (Lagrange Polynomial):Example (Lagrange Polynomial):Example (Lagrange Polynomial):Example (Lagrange Polynomial):

    ( ) ( ) ( )1 1 1 1 1 1, , , , , ,k k k k k k k k k kx f x f x f x x x x h + + + = =

    ( ) ( )( )( )( )( )( )( )( )

    1 1 11

    1 1 1 1 1

    k k k kk k

    k k k k k k k k

    x x x x x x x xf x f f

    x x x x x x x x+ +

    + +