ODE Coding

Embed Size (px)

Citation preview

  • 8/18/2019 ODE Coding

    1/8

      1

    Simulate some PhysicsPhenonmenon Apply ODE Method.

    Phạm Bá Duy Phạm Xuân Huy

    Bùi !n "#nh $% Xuân &'n(

  • 8/18/2019 ODE Coding

    2/8

      2

    )i*st de(*ee ODE+ dy/dx=f(x,y)

    Eule* method is a nume*ical method tosol,e o*dina*y di--e*ential euation /ODE0.

    1nlitial ,alue p*o2lem

    dy/dt=v(t) (3.1)t 1=to, y 1=yo.

    t 2=t 1+∆t

    y 2= ???  y 2 = y 1 + ∆t*v(t)

    3epeat this p*ocedu*e4 in (ene*al y n+1=y n+v(t n ). ∆t . 5uantity 6t is calledstepsi7e and can 2e chosen.

    "hat is Eule* method.

  • 8/18/2019 ODE Coding

    3/8

      3

    "*uncation E**o*

    $ocal t*uncation e**o* in each step isp*opo*tional to h.

    E**o* p*opa(ates th*ou(h steps o-

    computin(4 it is much 2i((e*.8ei89:M/8eo8;Bp/A=/>i?>o00

    8@-89:A  8y8 9:

      B:/

  • 8/18/2019 ODE Coding

    4/8

      4

    Eule*?*ome* method

    /t; ∆t 0:,/t0 ; ∆t *a(t)

     X(t+ ∆t ) = x(t) + ∆t *v(t+ ∆t )

     Approximate etter for o!"i##atin$ !y!tem.

  • 8/18/2019 ODE Coding

    5/8

      5

    Eule*?3icha*son method /0

  • 8/18/2019 ODE Coding

    6/8

      6

    Eule*?3icha*son Method /C0

  • 8/18/2019 ODE Coding

    7/8

      F

    ODE odin(

    Basic steps:Step 1. de-ine f(x,y).Step 2. input initial ,alue >o and yo.

    Step 3. input step si7e 6t and num2e* o- step n.

    Step 4. calculate >4 y and y+-o* i:+n

      >:>;hG

      y:y;h=-/>4y0G

      y:y;h=yGend

    Step 5. output > and y.

    Step 6. end

  • 8/18/2019 ODE Coding

    8/8

      8

      Eule* Method Matla2 ode

    IModi-ied Eule* Methods ? P*o2lem J. -unction -:Eul/>4,4t0 : G m : G >K:KG ,K:KG n : KKG dt : K.G

    > : 7e*os/n40G >/0 : >KG , : 7e*os/n40G ,/0 : KG t : 7e*os/n40G t/0 : K.KG

    -o* step:+n? ,/step;0 : ,/step0 ? dt=/>/step00G >/step;0 : >/step0 ; dt=,/step0G t/step;0 : t/step0 ; dtG end

    cl-G plot/t4>4L*0G le(end/>?/cm04,?/cmla2el /"ime /s00G yla2el /Amplitude0G title/Displacement ,s time4)ontSi7e4N0G (*idG hold onG