Phys102 Lecture07!08!10Fall RungeKutta 1

Embed Size (px)

Citation preview

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    1/10

    Computational Lab in Physics:Solving Differential Equations II.

    The Runge-Kutta method is an improvement on the Euler method,which gives a better approximation to the solution of the Diff. Eqn.

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    2/10

    2

    Taylor expansion: rederive Simple

    Euler method

    Simple Euler, Modified Euler, valid toO(h), can improve the accuracy.

    Method can be expressed as:

    2

    31 ( ) ' '' ( )2

    n n n n n

    h y y x h y hy y O h

    Simple Euler Method

    ' ( , )n n n y f x y

    1

    ( , )n n n n

    y y f x y

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    3/10

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    4/10

    4

    Rederive Midpoint Euler Method, Part II

    Subtract the two:

    We get rid of the 2nd Order terms!

    But, hey! We dont know yn+1/2. Approximate it using simple Euler method.

    2

    31/ 2 1/ 2 1/ 2

    ( / 2)' '' ( )

    2 2n n n n

    h h y y y y O h

    23

    1 1/ 2 1/ 2 1/ 2

    ( / 2)' '' ( )

    2 2n n n n

    h h y y y y O h

    -3

    1 1/ 2' 0 ( )

    n n n y y hy O h

    1/ 2

    1/ 2 1/ 2 1/ 2

    ' '2

    ' ( , )

    n n n

    n n n

    h y y y

    y f x y

    or

    1/ 2'ny

    1

    2 1/ 2 1/ 2

    ( , )

    ( , )

    n n

    n n

    k f x y

    k f x y

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    5/10

    5

    What we have done:

    1) Use the known derivative at xn.

    Obtained from xn and yn, define it as:

    yn = f(xn, yn) = k1

    2) Calculate the midpoint derivative.Obtained from xn+h/2, yn and yn=k1

    yn+ = yn+(h/2)* k1 , define this as:

    f(xn+h/2, yn+(h/2)* k1) = k2

    3) Propagate through the whole interval. yn+1 = yn + hk2

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    6/10

    6

    Graphically, 2nd Order Runge-Kutta:

    Calculatek1=yn=f(xn,yn)

    Esimtatek2=yn+=f(xn+h/2,yn+hk1/2)

    Propagate through.

    yn+1=yn+hk2

    yn

    yn+1/2

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    7/10

    7

    4th Order Runge-Kutta

    We can iterate again, and cancel higherand higher orders. Most commonlyused algorithm:

    1

    12

    23

    4 3

    531 2 41

    ( , )

    ,2 2

    ,2 2

    ( , )

    ( )6 3 3 6

    n n

    n n

    n n

    n n

    n n

    k f x y

    hkhk f x y

    hkhk f x y

    k f x h y hk

    kk k k y y h O h

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    8/10

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    9/10

  • 8/14/2019 Phys102 Lecture07!08!10Fall RungeKutta 1

    10/10

    10

    Homework (Due Nov 25) Use a Runge-Kutta algorithm to solve the problem of projectile

    motion with air resistance, i.e. To the 2nd Law Eq, youll havethe usual force of gravity (mg) directed down, then add aForce term F=bv (where v is the velocity). You need to calculate the motion in both the x (horizontal) and

    y(vertical) direction.

    You can take the initial conditions to be always x(0)=y(0)=0 forsimplicity. Assume ground is flat.

    The two other initial conditions you will need to specify for theproblem are the magnitude v0 and angle 0 of the initial velocityvector

    Part 1)

    Produce a graph of the trajectory (y vs x) for g=9.81, b=1, v0=30(all SI units), 0 = /4.

    Part 2) For a fixed v0, which angle gives the largest horizontal distance? Make a plot of Max Distance vs. angle to answer this. Mark on the

    plot the required angle, specifying its numerical value in radians.

    Can you guess if it should be larger or smaller than 45 degrees?