Lecture NumericalMethodsForODE

download Lecture NumericalMethodsForODE

of 6

Transcript of Lecture NumericalMethodsForODE

  • 7/29/2019 Lecture NumericalMethodsForODE

    1/6

    Tony Yang, Ph.D.

    Department of Civil and Environmental Engineering

    University of California, Berkeley

    CE 249 Experimental methods instructural engineering

    Topic: Numerical Methods for ODE

    2

    R.L. Burden and J.D. Faires, 2001, Numerical analysis 7th

    edition, Thomson Learning. M.D. Greenberg, Advance engineering mathematics 2nd

    edition, 1998, Prentice-Hall. G.V. Berg, 1989, Elements of structural dynamics,

    Prentice-Hall. A.K. Chopra, 2001, Dynamics of structures, Prentice-Hall. J.L. Humar, 1990, Dynamics of structures, Prentice-Hall. R.W. Clough and J. Penzien, 1975, Dynamics of

    structures, McGraw-Hill. N.M. Newmark and E. Rosenblueth, 1971, Fundamentals

    of earthquake engineering, Prentice-Hall. J. Strain, 2004, MATH 228a lecture notes, University of

    California, Berkeley.

    Text

    3

    Ordinary differential equation (ODE)

    What is ODE? ODE is a function of one independent variable with

    one or more of its derivatives.

    e.g.

    Initial value problem (IVP):

    If we have the initial condition y(0) = y0, then wecan solve y(t).

    Example:

    ( ) ( ) ( )( ),y t y t f t y t =

    ( )2 0, 0y y y y= =

    ( ) ( ) ( )

    2

    1 22

    0

    3 0

    1 11

    1 1, with 01

    dyy dy dt c t c

    dt y y

    y t y y y tt c t y

    = = + = +

    = = =+ +

    4

    Initial value problem (IVP)

    Is every initial value problem has an unique solution? No. e.g.

    How do we find out if an IVP has an unique solution?

    It has to satisfy the Lipschitz condition and

    the solution must be continuous in a convex domain.

    What does these mean?

    ( ) ( )2 , 0 0y t y y= =

    ( ) ( ) 20 ory t y t t= =

    ( ) ( )

    ( ) { }

    1 2 1 2, ,

    , is continuous in D = ,

    ff t y f t y L y y L

    y

    f t y a t b y

    5

    Initial value problem (IVP)

    Example:

    => Yes there exists an unique solution to this IVP.

    If fact, the solution is

    Lets say we know there is an unique solution to the IVP,can we always have an general analytical solution?

    Yes (if the ODE is linear).

    No (if the ODE is nonlinear).

    ( ) sin ty t e=

    ( ) ( )cos ,0 1, 0 1y y t t y= =

    ( )

    ( ) { }

    cos if 1

    , is continuous in 0 1,

    ft L L

    y

    f t y t y

    = =

    6

    Initial value problem (IVP)

    Linear ODE:

    Nonlinear ODE:

    May not have a general explicit solution

    What do we do?

    => Numerical solutions.

    ( ),y f y t=

    ( )y Ay g t= +

    ( ) ( ) ( )-At 00

    =e yt A t s

    y t e g s ds+

  • 7/29/2019 Lecture NumericalMethodsForODE

    2/6

    7

    Numerical methods

    Equations of motion:

    A general solution can be expressed as

    where a, b and c are constant coefficient and R is theremainder of the expression.

    In other words, the solution at n+1 step can be alinear combination of the previous displacement,velocity and acceleration.

    my cy ky p+ + =

    1 1

    1

    n n n

    n l l l l l l

    l n k l n k l n k u a u b u c u R

    + +

    += = = = + + +

    8

    Numerical methods

    Explicit Euler method: ( )1 ,n n n nu u h f t u+ = +

    t

    y(t)

    t0 t1

    h

    u0

    t2

    u1

    t3

    h h

    u2

    u3

    ( ),y f y t=

    9

    Numerical methods

    Example:

    Explicit Euler method ( )1 ,n n n nu u h f t u+ = +

    ( )

    ( ) ( )

    2

    2

    1, 0 0.5,0 1

    1 0.5 t

    y y t y t

    y t t e

    = + =

    = +

    2.458

    2.349

    2.190

    1.992

    1.760

    1.500

    f(ti,ui)

    2.458

    1.988

    1.550

    1.152

    0.800

    0.500

    ui

    0.18272.6411.0

    0.13872.1270.8

    0.09851.6490.6

    0.06211.2140.4

    0.02930.8290.2

    0.00000.5000.0

    Erroriyiti

    10

    Numerical methods

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10.5

    1

    1.5

    2

    2.5

    3

    t

    y

    exact

    dt = 0.1

    dt = 0.2

    As dt decreases, error decreases

    => u(t) arropximate y(t)

    11

    Numerical methods

    Explicit Euler method:

    Example:

    Using explicit Euler method

    If h>0.05

    ( )1 ,n n n nu u h f t u+ = +

    ( )

    ( ) 2020 , 0 0.5

    0.5 t

    y y y

    y t e

    = =

    =

    ( ) ( )1 20 1 20n n n nu u h u h u+ = + =

    u (Numerical solution became unstable)

    12

    Numerical methods

    Check convergence of numerical methods

    Consistency: Error produced in each step is bounded. As step size -> 0, error -> 0 => the method isconsistent. We can also quantify how fast the

    error is reducing = order of accuracy. Stability:

    Check the error is bounded. Any small error in theinitial condition will not making a huge error to thefinal solution.

    Consistency + Stability = Convergence.

  • 7/29/2019 Lecture NumericalMethodsForODE

    3/6

    13

    Taylor series expansion

    General formula

    Numerical method

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

    ( ) ( )

    2

    0 0

    0 0 0

    3

    0 0

    2!

    3!

    f x x xf x f x f x x x

    f x x xHOT

    = + +

    + + +

    "

    2

    12!

    nn n n

    y hy y h y HOT+ = + + + +

    "

    14

    Consistency

    Explicit Euler method:

    => This shows the explicit Euler method is consistent.(as h->0, error ->0). In addition, the method is2nd order accurate. In other words, if the step sizeis reduced by , the error is reduced by .

    ( ) ( )( )

    2

    1

    1 1 1

    2

    2

    1

    2!

    , ,2!

    2!

    nn n n

    n n n

    nn n n n n

    nn

    y hy y h y HOT

    e y u

    y he h f t y f t u HOT

    y he HOT

    +

    + + +

    +

    = + + + +

    =

    = + + + +

    = + +

    "

    "

    "

    ( )1 ,n n n nu u h f t u+ = +

    15

    Stability

    Explicit Euler method:

    Since

    ( ) ( )( )

    ( ) ( )( )

    ( )

    ( ) ( )( )

    ( )( )

    2

    1

    1

    2

    1

    1

    1

    0

    , ,2!

    , ,

    1

    1 1 1

    1 11

    nn n n n n n

    n n n n n n n

    n n n n

    n

    n

    n

    y he e h f t y f t u HOT

    e e h f t y f t u

    e hL e hL e

    hL e hL

    hLhL e

    hL

    +

    +

    ++

    = + + + +

    + +

    + + + +

    + + + +

    + + +

    "

    #

    ( )1 ,n n n nu u h f t u+ = +

    ( ) ( )21

    1 12

    hLhL e hL hL+ = + + +"

    16

    Stability

    Explicit Euler method:

    This shows error associate with the initial condition isindependent of the step size, which means the methodis stable.

    Stability + Consistency => Convergence. This shows theexplicit Euler method is convergence with 2nd order

    accuracy.

    0

    0

    1

    1

    hLnhLn

    n

    LTLT

    ee e e

    hL

    ee e n

    TL

    +

    +

    ( )1 ,n n n nu u h f t u+ = +

    Independent of h

    17

    Stability

    Example:

    This method is 4th order accurate!

    ( )

    ( )

    ( )

    ( )

    ( )

    1 1 1

    2 3 45

    2 3 4

    5

    32 4

    4 5

    4 5 4 2

    42 6 24

    52 6 24

    4 2 23

    1

    6

    n n n n n n

    n n n n n n

    n n n n n

    n n n n n

    n

    y y y h f f

    h h hy y h y y y O h y

    h h hy y h y y y O h

    hh y y y h y h y O h

    y h O h

    + = + +

    = + + + + + +

    + + +

    + + +

    = +

    ( )1 1 14 5 4 2n n n n nu u u h f f + = + + +

    18

    Stability

    Example:

    check against

    use the proposed numerical method

    if

    the numerical method is unstable!

    ( ) 0 1y t y = =

    ( )1 1 14 5 4 2n n n n nu u u h f f + = + + +

    ( )0, 0 1y y= =

    1 15 4

    n n nu u u+ =

    ( ) ( )

    ( ) ( )

    ( ) ( )

    2

    3

    4

    5 1 4 1 1 4

    5 1 4 1 4 1 21

    5 1 4 4 1 21 1 104

    u

    u

    u

    = + =

    = + = +

    = + =

    0 11, 1u u = = +

  • 7/29/2019 Lecture NumericalMethodsForODE

    4/6

    19

    Stability

    Explicit Euler method:

    The error at n step is independent of the step size, thisshows the explicit Euler method is stable.

    In other words, the error introduced at the initial timestep should not increase by decrease the step size (=increase number of steps).

    e.g. T = 0 to 10 case A: dt = 0.1 (need 100 steps) case B: dt = 0.05 (need 200 steps) any error introduced in step 0 should not increasefrom case A to B.

    0

    1LTLTn

    ee e e n

    TL

    +

    ( )1 ,n n n nu u h f t u+ = +

    20

    Stability

    Explicit Euler method:

    Example:

    Using explicit Euler method

    If h>0.05

    If h

  • 7/29/2019 Lecture NumericalMethodsForODE

    5/6

    25

    Runge-Kutta methods

    Orders of accuracy vs. number of stages (ERK methods)

    P 4 -> S = PP = 5 -> S 6

    P = 6 -> S 7P = 7 -> S 9P = 10 -> S 17

    This is why the 4th order accurate ERK method is mostefficient.

    26

    Multi-step methods

    Adams-Bashforth 2-step explicit method

    Adams-Bashforth 3-step explicit method

    Adams-Bashforth 4-step explicit method

    ( ) ( )( ) ( )21 , 1, 1 132

    n n n n n n n

    hu u f t u f t u O h+ += + =

    ( ) ( )

    ( ) ( )

    ( )

    , 1, 1

    1

    2, 2 3, 3

    4

    1

    55 59

    24 37 9

    n n n n

    n n

    n n n n

    n

    f t u f t uhu u

    f t u f t u

    O h

    +

    +

    = + +

    =

    ( ) ( ) ( )( )

    ( )

    1 , 1, 1 2, 2

    3

    1

    23 16 512

    n n n n n n n n

    n

    hu u f t u f t u f t u

    O h

    +

    +

    = + +

    =

    27

    Multi-step methods

    Adams-Moulton 2-step implicit method

    Adams-Moulton 3-step implicit method

    Adams-Moulton 4-step implicit method

    ( ) ( ) ( )( )

    ( )

    1 1, 1 , 1, 1

    3

    1

    5 812

    n n n n n n n n

    n

    hu u f t u f t u f t u

    O h

    + + +

    +

    = + +

    =

    ( ) ( )

    ( ) ( ) ( )

    ( )

    1, 1 ,

    1

    1, 1 2, 2 3, 3

    51

    251 646

    720 264 106 19

    n n n n

    n n

    n n n n n n

    n

    f t u f t uhu u

    f t u f t u f t u

    O h

    + +

    +

    +

    + = + +

    =

    ( ) ( )

    ( ) ( )( )

    1, 1 , 4

    1 1

    1, 1 2, 2

    9 19

    24 5

    n n n n

    n n n

    n n n n

    f t u f t uhu u O h

    f t u f t u

    + +

    + +

    + = + = +

    28

    2nd order system

    Example:

    => Systems of 1st order equations.

    1

    2

    2

    2

    2 1

    2

    2

    0 1 0

    2 1

    n n

    n n

    x qlet X

    x q

    xqX

    p x xq

    X X p

    = =

    = =

    = +

    22n nq q q p + + =

    29

    Central difference method

    This method uses a finite difference approach

    Substitute to the equations of motion

    Rearrange the equation

    Initial conditions

    1 1 1 1

    2

    2and

    2

    n n n n nn n

    u u u u uu u

    h h

    + + += =

    1 2 32 2 2

    2, ,

    2 2

    m c m c mc c c k

    h h h h h= + = =

    n n n nmu cu ku p+ + =

    2

    0 0 00 1 0 0 0and

    2

    p cu ku hu u u h u u

    m

    = = +

    2 1 31

    1

    n n nn

    p c u c uu

    c

    +

    =

    30

    Central difference method

    For nonlinear system

    Stability of the central difference method

    1

    n

    h

    T