rungekuttaformulas

2
MATH 231A Runge-Kutta Notes: for a 2-equation, 1st-order system For our (general) problem from class dx/dt = f (t,x,y), x(t 0 ) = x 0 dy/dt = g(t,x,y), y (t 0 ) = y 0 we get our approximate solution (x n , y n ) at time t n , n = 1, 2,... via the iteration of x n+1 = x n + h 6 (k n1 + 2k n2 + 2k n3 + k n4 ) y n+1 = y n + h 6 ( n1 + 2 n2 + 2 n3 + n4 ), where the formulas for each of the k’s and ’s are k n1 = f (t n ,x n , y n ) n1 = g(t n ,x n , y n ) k n2 = f (t n + h/2,x n + 1 2 hk n1 , y n + 1 2 h n1 ) n2 = g(t n + h/2,x n + 1 2 hk n1 , y n + 1 2 h n1 ) k n3 = f (t n + h/2,x n + 1 2 hk n2 , y n + 1 2 h n2 ) n3 = g(t n + h/2,x n + 1 2 hk n2 , y n + 1 2 h n2 ) k n4 = f (t n + h, x n + hk n3 , y n + h n3 ) n4 = g(t n + h, x n + hk n3 , y n + h n3 ). Note about reading Section 8.6 When you read through Section 8.6, the formulas that appear there look dierent only because, in the text, x n and k nj are treated as ve ctors. Formulas (6) and (7) on p. 456 become the same as above when we note that, in the 2-dependent-variable case, the way to translate the authors’ notation into ours is x n = (x n , y n ) and k nj = (k nj , nj ). In the Mathematica notebook that you will download (in which there is a Runge-Kutta algorithm for the two-body problem), you will see that I have written the algorithm in two dierent ways, the rst time in scalar form (i.e., like the formulas above, only applied to 4 dependent variables instead of 2), and once in vector form. Two things I would like to point out: While, at each step in the algorithm, we need to store a new 4-tuple ( x,u,y,v) describing the current state of the satellite (or, at least (x, y), which are enough to give the satellite’s positio n), the compu tatio n of the next (x n+1 ,u n+1 , y n+1 ,v n+1 ) only requires knowledge of the current (x n ,u n , y n , v n ). A statement (taken from the notebook you download) like x = x + h (  j 1 + 2 j 2 + 2 j 3 + j 4)/6; uses the old x value on the right side of the equation, and the result of this computation is then stored as x (wiping out the old x-value). The same may be said about the numbers j 1 , ...  j 4 , k 1 , ..., k 4 , ... m 1 , ... m 4 .

Upload: umsterfigo

Post on 10-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: rungeKuttaFormulas

8/8/2019 rungeKuttaFormulas

http://slidepdf.com/reader/full/rungekuttaformulas 1/2

MATH 231ARunge-Kutta Notes: for a 2-equation, 1st-order system

For our (general) problem from class

dx/dt = f (t,x,y), x(t0) = x0

dy/dt = g(t,x,y), y(t0) = y0

we get our approximate solution (xn, yn) at time tn, n = 1, 2, . . . via the iteration of 

xn+1 = xn + h6

(kn1 + 2kn2 + 2kn3 + kn4)

yn+1 = yn + h6

(n1 + 2n2 + 2n3 + n4),

where the formulas for each of the k’s and ’s are

kn1 = f (tn, xn, yn)

n1 = g(tn, xn, yn)

kn2 = f (tn + h/2, xn +1

2hkn1, yn +

1

2hn1)

n2 = g(tn + h/2, xn +1

2hkn1, yn +

1

2hn1)

kn3 = f (tn + h/2, xn +1

2hkn2, yn +

1

2hn2)

n3 = g(tn + h/2, xn +1

2hkn2, yn +

1

2hn2)

kn4 = f (tn + h, xn + hkn3, yn + hn3)

n4 = g(tn + h, xn + hkn3, yn + hn3).

Note about reading Section 8.6

When you read through Section 8.6, the formulas that appear there look different only because,

in the text, xn and knj are treated as vectors. Formulas (6) and (7) on p. 456 become the same

as above when we note that, in the 2-dependent-variable case, the way to translate the authors’

notation into ours is

xn = (xn, yn) and knj = (knj , nj).

In the Mathematica  notebook that you will download (in which there is a Runge-Kutta algorithm

for the two-body problem), you will see that I have written the algorithm in two different ways,the first time in scalar form (i.e., like the formulas above, only applied to 4 dependent variables

instead of 2), and once in vector form. Two things I would like to point out:

• While, at each step in the algorithm, we need to store a new 4-tuple (x,u,y,v) describing

the current state of the satellite (or, at least (x, y), which are enough to give the satellite’s

position), the computation of the next (xn+1, un+1, yn+1, vn+1) only requires knowledge of the

current (xn, un, yn, vn). A statement (taken from the notebook you download) like

x = x + h ∗ ( j1 + 2 ∗ j2 + 2 ∗ j3 + j4)/6;

uses the old x value on the right side of the equation, and the result of this computation isthen stored as x (wiping out the old x-value). The same may be said about the numbers j1,

. . . j4, k1, . . . , k4, . . . m1, . . . m4.

Page 2: rungeKuttaFormulas

8/8/2019 rungeKuttaFormulas

http://slidepdf.com/reader/full/rungekuttaformulas 2/2

• In Mathematica , points and vectors are considered to be roughly the same thing; both are

stored as lists, surrounded by curly brackets. The function definition (found in the vector/2nd

version of the algorithm in the notebook)

f [t , x ] := {x[[2]],−x[[1]]/(x[[1]]2 + x[[3]]2)3/2, x[[4]],−x[[3]]/(x[[1]]2 + x[[3]]2)3/2}

takes a scalar t (which it doesn’t really use) and a 4-dimensional vector x. This functions

output is also a 4-dimensional vector (note the curly brackets and the 4 separate components

lying between them).