Numerical Integration Lecture

download Numerical Integration Lecture

of 59

Transcript of Numerical Integration Lecture

  • 7/30/2019 Numerical Integration Lecture

    1/59

    1

    Advanced Computational MethodsNumerical IntegrationME753

  • 7/30/2019 Numerical Integration Lecture

    2/59

    2

    Introduction to NumericalIntegration

    Definitions Upper and Lower Sums Trapezoid Method (Newton-Cotes Methods)Simpsons Rules Romberg Method Gauss Quadrature Examples

  • 7/30/2019 Numerical Integration Lecture

    3/59

    3

    Integration

    Indefinite Integrals

    Indefinite Integrals of afunction are functionsthat differ from eachother by a constant.

    c

    xdxx

    2

    2

    Definite Integrals

    Definite Integrals arenumbers.

    2

    1

    2

    1

    0

    1

    0

    2

    xxdx

  • 7/30/2019 Numerical Integration Lecture

    4/59

    4

    Fundamental Theorem of Calculus

    :forsolutionformclosedNo

    :fortiveantiderivanoisThere

    )f(x)(x)'F(i.e.,foftiveantiderivais

    ,intervalanoncontinuousisIf

    2

    2

    b

    a

    x

    x

    b

    a

    dxe

    e

    F(a)F(b)f(x)dx

    F

    [a,b]f

  • 7/30/2019 Numerical Integration Lecture

    5/59

    5

    The Area Under the Curve

    b

    af(x)dxArea

    One interpretation of the definite integral is:

    Integral = area under the curve

    a b

    f(x)

  • 7/30/2019 Numerical Integration Lecture

    6/59

    6

    Upper and Lower Sums

    a b

    f(x)

    3210 xxxx

    iin

    i

    i

    ii

    n

    i

    i

    iii

    iii

    n

    xxMPfUsumUpper

    xxmPfLsumLower

    xxxxfM

    xxxxfmDefine

    bxxxxaPPartition

    1

    1

    0

    1

    1

    0

    1

    1

    210

    ),(

    ),(

    :)(max

    :)(min

    ...

    The interval is divided into subintervals.

  • 7/30/2019 Numerical Integration Lecture

    7/59

    7

    Upper and Lower Sums

    a b

    f(x)

    3210 xxxx

    2

    2integraltheofEstimate

    ),(

    ),(

    1

    1

    0

    1

    1

    0

    LUError

    UL

    xxMPfUsumUpper

    xxmPfLsumLower

    ii

    n

    i

    i

    ii

    n

    i

    i

  • 7/30/2019 Numerical Integration Lecture

    8/59

    8

    Example

    14

    3

    2

    1

    4

    103,2,1,0

    4

    1

    1,

    16

    9,

    4

    1,

    16

    1

    16

    9,

    4

    1,

    16

    1,0

    )intervalsequalfour(4

    1,4

    3,

    4

    2,

    4

    1,0:

    1

    3210

    3210

    1

    0

    2

    iforxx

    MMMM

    mmmm

    n

    PPartition

    dxx

    ii

  • 7/30/2019 Numerical Integration Lecture

    9/59

    9

    Example

    14

    3

    2

    1

    4

    10

    8

    1

    64

    14

    64

    30

    2

    1

    32

    11

    64

    14

    64

    30

    2

    1

    integraltheofEstimate

    64

    301

    16

    9

    4

    1

    16

    1

    4

    1),(

    ),(

    64

    14

    16

    9

    4

    1

    16

    10

    4

    1),(

    ),(

    1

    1

    0

    1

    1

    0

    Error

    PfU

    xxMPfUsumUpper

    PfL

    xxmPfLsumLower

    ii

    n

    i

    i

    ii

    n

    i

    i

  • 7/30/2019 Numerical Integration Lecture

    10/59

    10

    Upper and Lower Sums

    Estimates based on Upper and LowerSums are easy to obtain for monotonicfunctions (always increasing or always

    decreasing). For non-monotonic functions, finding

    maximum and minimum of the function

    can be difficult and other methods can bemore attractive.

  • 7/30/2019 Numerical Integration Lecture

    11/59

    11

    Newton-Cotes Methods

    In Newton-Cote Methods, the functionis approximated by a polynomial oforder n.

    Computing the integral of a polynomialis easy.

    1

    )(...

    2

    )()()(

    ...)(

    1122

    10

    10

    n

    aba

    abaabadxxf

    dxxaxaadxxf

    nn

    n

    b

    a

    b

    a

    n

    n

    b

    a

  • 7/30/2019 Numerical Integration Lecture

    12/59

    12

    Newton-Cotes Methods

    Trapezoid Method (First Order Polynomials are used)

    Simpson 1/3 Rule (Second Order Polynomials are used)

    b

    a

    b

    a

    b

    a

    b

    a

    dxxaxaadxxf

    dxxaadxxf

    2210

    10

    )(

    )(

  • 7/30/2019 Numerical Integration Lecture

    13/59

    13

    Trapezoid Method

    Derivation-One Interval Multiple Application Rule Estimating the Error Recursive Trapezoid Method

  • 7/30/2019 Numerical Integration Lecture

    14/59

    14

    Trapezoid Method

    )()()(

    )( axab

    afbfaf

    f(x)

    ba

    2

    )()(

    2

    )()(

    )()()(

    )()()(

    )(

    )(

    2

    afbfab

    x

    ab

    afbf

    xab

    afbfaaf

    dxaxab

    afbfafI

    dxxfI

    b

    a

    b

    a

    b

    a

    b

    a

  • 7/30/2019 Numerical Integration Lecture

    15/59

    15

    Trapezoid MethodDerivation-One Interval

    2

    )()(

    )()(2

    )()()()()(

    2

    )()()()()(

    )()()()()(

    )()()()()(

    22

    2

    afbfab

    abab

    afbfabab

    afbfaaf

    x

    ab

    afbfx

    ab

    afbfaaf

    dxxab

    afbf

    ab

    afbfaafI

    dxaxab

    afbfafdxxfI

    b

    a

    b

    a

    b

    a

    b

    a

    b

    a

  • 7/30/2019 Numerical Integration Lecture

    16/59

    16

    Trapezoid Method

    )(bf

    f(x)

    ba

    )()(2 bfafab

    Area

    )(af

  • 7/30/2019 Numerical Integration Lecture

    17/59

    17

    Trapezoid MethodMultiple Application Rule

    a b

    f(x)

    3210 xxxx

    strapezoidtheof

    areastheofsum)(

    ...segmentsintodpartitione

    isb][a,intervalThe

    210

    b

    a

    n

    dxxf

    bxxxxan

    1212

    2

    )()(xx

    xfxfArea

    x

  • 7/30/2019 Numerical Integration Lecture

    18/59

    18

    Trapezoid MethodGeneral Formula and Special Case

    )()(21

    )(

    ...

    equal)ynecessaril(notsegmentsintodividedisintervaltheIf

    11

    1

    0

    210

    iiii

    n

    i

    b

    a

    n

    xfxfxxdxxf

    bxxxxa

    n

    1

    1

    0

    1

    )()()(2

    1)(

    allfor

    points)basespacedEqualiy(CaseSpecial

    n

    i

    in

    b

    a

    ii

    xfxfxfhdxxf

    ihxx

  • 7/30/2019 Numerical Integration Lecture

    19/59

    19

    Example

    Given a tabulated

    values of the velocity of

    an object.

    Obtain an estimate of

    the distance traveled in

    the interval [0,3].

    Time (s) 0.0 1.0 2.0 3.0

    Velocity (m/s) 0.0 10 12 14

    Distance = integral of the velocity

    3

    0)(Distance dttV

  • 7/30/2019 Numerical Integration Lecture

    20/59

    20

    Example 1

    Time (s) 0.0 1.0 2.0 3.0

    Velocity

    (m/s)

    0.0 10 12 14

    29)140(2

    112)(101Distance

    )()(2

    1

    )(

    1

    0

    1

    1

    1

    n

    n

    ii

    ii

    xfxfxfhT

    xxh

    MethodTrapezoid

    3,2,1,0arepointsBaselssubinterva3into

    dividedisintervalThe

  • 7/30/2019 Numerical Integration Lecture

    21/59

    21

    Error in estimating the integralTheorem

    )(''max12

    )(12

    then)(eapproximat

    tousedisMethodTrapezoidIf:Theorem

    )(widthintervalsEqual

    oncontinuousis)('':Assumption

    ],[

    2

    ''2

    a

    xfhab

    Error

    [a,b]wherefhab

    Error

    dxxf

    h

    [a,b]xf

    bax

    b

  • 7/30/2019 Numerical Integration Lecture

    22/59

    22

    Estimating the ErrorFor Trapezoid Method

    ?accuracydigitdecimal5to

    )sin(computetoneeded

    areintervalsspacedequallymanyHow

    0

    dxx

  • 7/30/2019 Numerical Integration Lecture

    23/59

    23

    Example

    intervals719

    00437.0

    )(

    00437.0106

    102

    1

    121)(''

    )sin()('');cos()(';0;

    )(''max12

    102

    1error,)sin(

    52

    52

    ],[

    2

    5

    0

    h

    abn

    hh

    hErrorxf

    xxfxxfab

    xfh

    ab

    Error

    thatsohf inddxx

    bax

  • 7/30/2019 Numerical Integration Lecture

    24/59

    24

    Example

    )()(2

    1)(),(

    ,allfor:

    )()(2

    1),(

    )(:computetomethodTrapezoidUse

    0

    1

    1

    1

    11

    1

    0

    3

    1

    n

    n

    i

    i

    ii

    iiii

    n

    i

    xfxfxfhPfT

    ixxhCaseSpecial

    xfxfxxPfTTrapezoid

    dxxf

    x 1.0 1.5 2.0 2.5 3.0

    f(x) 2.1 3.2 3.4 2.8 2.7

  • 7/30/2019 Numerical Integration Lecture

    25/59

    25

    Example

    9.5

    7.21.2218.24.32.35.0

    )()(2

    1)()( 0

    1

    1

    3

    1

    n

    n

    i

    i xfxfxfhdxxf

    x 1.0 1.5 2.0 2.5 3.0

    f(x) 2.1 3.2 3.4 2.8 2.7

  • 7/30/2019 Numerical Integration Lecture

    26/59

    ExampleUse the trapezoidal rule to estimate

    8.0

    0

    5432 400900675200252.0 dxxxxxx

    Solution

    %5.89

    1728.0

    2

    232.02.08.0

    2

    )8.0()0()08.0(

    2

    )()()(

    t

    ff

    bfafabI

  • 7/30/2019 Numerical Integration Lecture

    27/59

    ExampleUse the multiple-application trapezoidal rule for n = 2 toestimate

    8.0

    0

    5432 400900675200252.0 dxxxxxx

    Solution

    %9.34

    0688.1

    4

    232.0)456.2(22.08.0

    4

    )8.0()4.0(2)0()08.0(

    )2(2

    )()(2)()( 210

    t

    fff

    xfxfxfabI

  • 7/30/2019 Numerical Integration Lecture

    28/59

  • 7/30/2019 Numerical Integration Lecture

    29/59

    Computer Algorithms for the

    Trapezoidal Rule

  • 7/30/2019 Numerical Integration Lecture

    30/59

    30

    Recursive Trapezoid Method

    f(x)

    haa

    )()(2

    )0,0(R

    :intervaloneonbasedEstimate

    bfafab

    abh

  • 7/30/2019 Numerical Integration Lecture

    31/59

    31

    Recursive Trapezoid Method

    f(x)

    hahaa 2

    )()0,0(21

    )0,1(

    )()(2

    1)(

    2)0,1(R

    2

    :intervals2onbasedEstimate

    hafhRR

    bfafhafab

    abh

    Based on previous estimate

    Based on new point

  • 7/30/2019 Numerical Integration Lecture

    32/59

    32

    Recursive Trapezoid Method

    f(x)

    )3()()0,1(2

    1)0,2(

    )()(2

    1

    )3()2()(

    4

    )0,2(R

    4

    hafhafhRR

    bfaf

    hafhafhafab

    abh

    hahaa 42 Based on previous estimate

    Based on new points

  • 7/30/2019 Numerical Integration Lecture

    33/59

    33

    Recursive Trapezoid MethodFormulas

    n

    k

    abh

    hkafhnRnR

    bfafab

    n

    2

    )12()0,1(2

    1)0,(

    )()(2

    )0,0(R

    )1(2

    1

  • 7/30/2019 Numerical Integration Lecture

    34/59

    34

    Recursive Trapezoid Method

    )1(

    2

    2

    1

    2

    1

    3

    2

    12

    1

    1

    )12()0,1(2

    1)0,(,

    2

    ..................

    )12()0,2(

    2

    1)0,3(,

    2

    )12()0,1(2

    1)0,2(,

    2

    )12()0,0(2

    1)0,1(,

    2

    )()(2

    )0,0(R,

    n

    kn

    k

    k

    k

    hkafhnRnRab

    h

    hkafhRRab

    h

    hkafhRRab

    h

    hkafhRRab

    h

    bfafab

    abh

  • 7/30/2019 Numerical Integration Lecture

    35/59

    Example on Recursive Trapezoid

    35

    errortheestimatethenR(3,0)computingby)sin(

    :estimatetomethodTrapezoidRecursiveUse

    2/

    0

    dxx

    n h R(n,0)

    0 (b-a)=/2 (/4)[sin(0) + sin(/2)]=0.785398

    1 (b-a)/2=/4 R(0,0)/2 + (/4) sin(/4) = 0.948059

    2 (b-a)/4=/8 R(1,0)/2 + (/8)[sin(/8)+sin(3/8)] = 0.987116

    3 (b-a)/8=/16 R(2,0)/2 + (/16)[sin(/16)+sin(3/16)+sin(5/16)+sin(7/16)] = 0.996785

    Estimated Error = |R(3,0) R(2,0)| = 0.009669

  • 7/30/2019 Numerical Integration Lecture

    36/59

    36

    Advantages of Recursive Trapezoid

    Recursive Trapezoid:

    Gives the same answer as the standardTrapezoid method.

    Makes use of the available information toreduce the computation time.

    Useful if the number of iterations is not

    known in advance.

  • 7/30/2019 Numerical Integration Lecture

    37/59

    37

    Simpsons Rules

    Simpsons 1/3 Rule

    Simpsons 3/8 Rule

  • 7/30/2019 Numerical Integration Lecture

    38/59

    SIMPSONS RULES

    More accurate estimate of an integral is obtained if a high-order polynomial is used to connect the points.

    The formulas that result from taking the integrals undersuch polynomials are called Simpsons rules.

  • 7/30/2019 Numerical Integration Lecture

    39/59

    Simpsons 1/3 Rule

    This rule results when a second-order interpolatingpolynomial is used.

    2

    where)()(4)(

    3

    )())((

    ))((

    )())((

    ))(()(

    ))((

    ))((

    ,andLet

    )()(

    210

    2

    1202

    10

    1

    2101

    200

    2010

    21

    20

    2

    2

    0

    abhxfxfxf

    hI

    dxxfxxxx

    xxxx

    xfxxxx

    xxxxxf

    xxxx

    xxxxI

    xbxa

    dxxfdxxfI

    x

    x

    b

    a

    b

    a

    After integration,

  • 7/30/2019 Numerical Integration Lecture

    40/59

    Simpsons 3/8 Rule

    This rule results when a third-order interpolatingpolynomial is used.

    3

    where)()(3)(3)(8

    3

    ,yieldsThis

    )()(

    3210

    3

    abhxfxfxfxf

    hI

    dxxfdxxfI

    b

    a

    b

    a

  • 7/30/2019 Numerical Integration Lecture

    41/59

    41

    Romberg Method

    Motivation

    Derivation of Romberg Method

    Romberg Method

    Example

    When to stop?

  • 7/30/2019 Numerical Integration Lecture

    42/59

    42

    Motivation for Romberg Method

    Trapezoid formula with a sub-interval h gives anerror of the order O(h2).

    We can combine two Trapezoid estimates with

    intervals h and h/2 to get a better estimate.

  • 7/30/2019 Numerical Integration Lecture

    43/59

    43

    Romberg Method

    First column is obtained

    using Trapezoid Method

    dxf(x)ofionapproximattheimprovetocombinedare

    ...h/8h/4,h/2,h,sizeofintervalsmethodTrapezoidusingEstimates

    b

    a

    R(0,0)

    R(1,0) R(1,1)

    R(2,0) R(2,1) R(2,2)

    R(3,0) R(3,1) R(3,2) R(3,3)The other elements

    are obtained using

    the Romberg Method

  • 7/30/2019 Numerical Integration Lecture

    44/59

    44

    First ColumnRecursive Trapezoid Method

    n

    k

    abh

    hkafhnRnR

    bfafab

    n

    2

    )12()0,1(2

    1)0,(

    )()(2

    )0,0(R

    )1(2

    1

  • 7/30/2019 Numerical Integration Lecture

    45/59

    45

    Derivation of Romberg Method

    .. .)0,1()0,(43

    1)(

    2*41

    )2(.. .64

    1

    16

    1

    4

    1)0,()(

    by R(n,0)obtainedisestimateaccurateMore

    )1(...)0,1()(

    2methodTrapezoid)()0,1()(

    66

    44

    66

    44

    22

    66

    44

    22

    12

    hbhbnRnRdxxf

    giveseqeq

    eqhahahanRdxxf

    eqhahahanRdxxf

    abhwithhOnRdxxf

    b

    a

    b

    a

    b

    a

    n

    b

    a

  • 7/30/2019 Numerical Integration Lecture

    46/59

    46

    Romberg Method

    1,1)1,1()1,(414

    1),(

    )12()0,1(2

    1)0,(

    ,

    2

    )()(2

    )0,0(R

    )1(2

    1

    mnmnRmnRmnR

    hkafhnRnR

    abh

    bfafab

    m

    m

    k

    n

    n

    R(0,0)

    R(1,0) R(1,1)

    R(2,0) R(2,1) R(2,2)

    R(3,0) R(3,1) R(3,2) R(3,3)

  • 7/30/2019 Numerical Integration Lecture

    47/59

    47

    Property of Romberg Method

    )(),()(

    Theorem

    22 m

    b

    a

    hOmnRdxxf

    R(0,0)

    R(1,0) R(1,1)

    R(2,0) R(2,1) R(2,2)

    R(3,0) R(3,1) R(3,2) R(3,3)

    )()()()( 8642 hOhOhOhOError Level

  • 7/30/2019 Numerical Integration Lecture

    48/59

    48

    Example

    3

    1

    2

    1

    8

    34

    3

    1)0,0()0,1(4

    14

    1)1,1(

    1,1)1,1()1,(414

    1),(

    8

    3

    4

    1

    2

    1

    2

    1

    2

    1))(()0,0(

    2

    1)0,1(,

    2

    1

    5.010

    2

    1)()(

    2

    )0,0(,1

    Compute

    1

    1

    0

    2

    RRR

    mnformnRmnRmnR

    hafhRRh

    bfafab

    Rh

    dxx

    mm

    0.5

    3/8 1/3

  • 7/30/2019 Numerical Integration Lecture

    49/59

    49

    Example (cont.)

    3

    1

    3

    1

    3

    16

    15

    1)1,1()1,2(4

    14

    1)2,2(

    3

    1

    8

    3

    32

    114

    3

    1)0,1()0,2(4

    3

    1)1,2(

    )1,1()1,(414

    1),(

    32

    11

    16

    9

    16

    1

    4

    1

    8

    3

    2

    1))3()(()0,1(

    2

    1)0,2(,

    4

    1

    2

    2

    RRR

    RRR

    mnRmnRmnR

    hafhafhRRh

    m

    m

    0.5

    3/8 1/3

    11/32 1/3 1/3

  • 7/30/2019 Numerical Integration Lecture

    50/59

    50

    When do we stop?

    at R(4,4)STOPexample,for

    steps,ofnumbergivenaAfteror

    )1,(),( nnRnnR

    ifSTOP

  • 7/30/2019 Numerical Integration Lecture

    51/59

    51

    Gauss Quadrature

    Motivation General integration formula

  • 7/30/2019 Numerical Integration Lecture

    52/59

    52

    Motivation

    nandih

    nihcwhere

    xfcdxxf

    xfxfxfhdxxf

    i

    n

    i

    ii

    b

    a

    n

    i

    ni

    b

    a

    05.0

    1,...,2,1

    )()(

    :asexpressedbecanIt

    )()(2

    1)()(

    :MethodTrapezoid

    0

    1

    1

    0

  • 7/30/2019 Numerical Integration Lecture

    53/59

    53

    General Integration Formula

    integral?theofionapproximatgoodagivesformulaethat thsoselectwedoHow

    :Problem

    ::

    )()(

    0

    ii

    ii

    n

    i

    ii

    b

    a

    xandc

    NodesxWeightsc

    xfcdxxf

  • 7/30/2019 Numerical Integration Lecture

    54/59

    54

    Lagrange Interpolation

    b

    aii

    n

    i

    ii

    b

    a

    b

    ai

    n

    i

    i

    b

    an

    b

    a

    n

    n

    b

    an

    b

    a

    dxxcwherexfcdxxf

    dxxfxdxxPdxxf

    xxx

    xPwhere

    dxxPdxxf

    )()()(

    )()()()(

    ,...,,:nodesat the

    f(x)esinterpolatthatpolynomialais)(

    )()(

    0

    0

    10

  • 7/30/2019 Numerical Integration Lecture

    55/59

    Example

    Determine the Gauss Quadrature Formula of

    If the nodes are given as (-1, 0 , 1)

    Solution: First we need to find l0(x), l1(x), l2(x)

    Then compute:

    55

    2

    2

    )( dxxf

    2

    2

    22

    2

    2

    11

    2

    2

    00 )(,)(,)( dxxlcdxxlcdxxlc

  • 7/30/2019 Numerical Integration Lecture

    56/59

    Solution

    56

    )1(3

    8)0(

    3

    4)1(

    3

    8)(forFormulaQuadratureGaussThe

    3

    8

    2

    )1(,

    3

    4)1)(1(,

    3

    8

    2

    )1(

    2

    )1(

    )12)(02(

    )1)(0()(

    )1)(1()21)(01(

    )2)(0()(

    2)1(

    )20)(10()2)(1()(

    2

    2-

    2

    2

    2

    2

    2

    1

    2

    2

    0

    2

    1

    0

    fffdxxf

    dxxx

    cdxxxcdxxx

    c

    xx

    xxxx

    xxxxxl

    xxxxxx

    xxxxxl

    xxxxxx

    xxxxxl

  • 7/30/2019 Numerical Integration Lecture

    57/59

    Using the Gauss Quadrature Formula

    57

    answerexactsametheiswhich,3

    16)1(

    3

    8)0(

    3

    4)1(

    3

    8

    )1(3

    8)0(

    3

    4)1(

    3

    8FormulaQuadratureGaussThe

    3

    16)(foreexact valuThe

    )(Let:1Case

    222

    2

    2-

    2

    2

    2-

    2

    fff

    dxxdxxf

    xxf

  • 7/30/2019 Numerical Integration Lecture

    58/59

    Using the Gauss Quadrature Formula

    58

    answerexactsametheiswhich,0)1(3

    8)0(

    3

    4)1(

    3

    8

    )1(3

    8)0(

    3

    4)1(

    3

    8FormulaQuadratureGaussThe

    0)(foreexact valuThe

    )(Let:2Case

    333

    2

    2-

    3

    2

    2-

    3

    fff

    dxxdxxf

    xxf

  • 7/30/2019 Numerical Integration Lecture

    59/59

    59

    Improper Integrals

    1

    022

    12

    1

    1 2a

    1

    111:

    function.newtheonmethodapply theand

    )0assuming(,11)(

    followingthelikemationa transforUse

    )orislimitstheof(oneintegralsimpropereapproximat

    todirectlyusedbecannotearlierdiscussedMethods

    dt

    t

    tdx

    xExample

    abdtt

    ft

    dxxf a

    b

    b