the stormer-verlet method · numerical analysis seminar fruhj¨ ahrssemester 08 lecturers: prof. m....

14
Numerical Analysis Seminar Fr¨ uhjahrssemester 08 Lecturers: Prof. M. Torrilhon, Prof. D. Kressner The St¨ ormer-Verlet method F. Crivelli ([email protected]) May 8, 2008 Introduction During this talk I’ll introduce the St¨ ormer-Verlet method, also known by the name leap-frog method or Newton method or more extensively Newton-St¨ ormer-Verlet-leapfrog method. This method is used in order to find numerical solutions of ordinary differential equations: its various names are due to the different branchs of science in which the method is used. Carl St¨ ormed used this method for his computations of the motion of ionized particles in the earth’s magnetic field (aurora borealis) in 1907; in the context of partial differential equations of wave propagation, this method is called leap-frog method; Loup Verlet in 1967 used this method in molecular dynamics and then he discovered that Newton used this method in his Principia Mathematica in 1687. 1 Ordinary differential equations In this paragraph I’ll just remind some basis definitions of the language of ordinary differential equations. Definition 1. Let y : R -→ R x y(x) be an unknown function of x and denote by y (i) its i-th derivative. An Ordinary Differential Equation (ODE) of order n is an equation of the form F ( x, y, y ,...,y (n-1) ) = y (n) , where F : R n+1 R is a function. This leads to the definition of a solution of an ODE. Definition 2. A solution of an ODE of dimension n, F ( x, y, y ,...,y (n-1) ) = y (n) , is a function u : I R R such that u is n-times differentiable on I , F is defined for all ( x, u, u ,...,u (n-1) ) , x I , and F ( x, u, u ,...,u (n-1) ) = u (n) , x I . 1

Upload: doandang

Post on 20-Nov-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Numerical Analysis Seminar Fruhjahrssemester 08

Lecturers: Prof. M. Torrilhon, Prof. D. Kressner

The Stormer-Verlet method

F. Crivelli ([email protected])

May 8, 2008

Introduction

During this talk I’ll introduce the Stormer-Verlet method, also known by the nameleap-frog method or Newton method or more extensively Newton-Stormer-Verlet-leapfrogmethod. This method is used in order to find numerical solutions of ordinary differentialequations: its various names are due to the different branchs of science in which themethod is used. Carl Stormed used this method for his computations of the motion ofionized particles in the earth’s magnetic field (aurora borealis) in 1907; in the contextof partial differential equations of wave propagation, this method is called leap-frogmethod; Loup Verlet in 1967 used this method in molecular dynamics and then hediscovered that Newton used this method in his Principia Mathematica in 1687.

1 Ordinary differential equations

In this paragraph I’ll just remind some basis definitions of the language of ordinarydifferential equations.

Definition 1. Lety : R −→ R

x 7→ y(x)

be an unknown function of x and denote by y(i) its i-th derivative. An OrdinaryDifferential Equation (ODE) of order n is an equation of the form

F(x, y, y′, . . . , y(n−1)

)= y(n),

where F : Rn+1 → R is a function.

This leads to the definition of a solution of an ODE.

Definition 2. A solution of an ODE of dimension n, F(x, y, y′, . . . , y(n−1)

)= y(n),

is a function u : I ⊂ R → R such that u is n-times differentiable on I, F is definedfor all

(x, u, u′, . . . , u(n−1)

), x ∈ I, and F

(x, u, u′, . . . , u(n−1)

)= u(n), x ∈ I.

1

Solutions of ODE of order n usually contain n parameters, resulting from theconstants of integration. This parameters can be uniquely determined if we give aninitial condition at the ODE, i.e., for some x0 ∈ R and y

(i−1)0 ∈ R, i = 1, . . . , n, we

want the solution to satisfy the conditions

y(i)(x0) = y(i)0 , i = 0, . . . , n− 1.

We have another important

Definition 3. Let yi : R → R, i = 1, . . . , n, be unknown functions of the variable x.A first order system of differential equations of dimension n is a systemof equations of the form

y′1 = F1(x, y1, . . . , yn)y′2 = F2(x, y1, . . . , yn)...

......

y′n = Fn(x, y1, . . . , yn)

where Fi : Rn+1 → R, i = 1, . . . , n, are functions. Setting

y := (y1, . . . , yn)T , F := (F1, . . . , Fn)T ,

the system becomesy′ = F(x, y),

with y and F interpreted as vectors. This notation was introduced by Giuseppe Peanoin 1890.

Take an ODE of order n, F(x, y, y′, . . . , y(n−1)

)= y(n). If we write yi(x) :=

yi−1(x), i = 1, . . . , n, we obtain a first order system of differential equations of di-mension n

y′1 = y2

y′2 = y3...

......

y′n−1 = yn

y′n = F (x, y1, . . . , yn)

Hence, we can switch from an ODE of dimension n to a first order system of differentialequations.We look at the existence and uniqueness of solutions of a first order system ofdifferential equations of dimension n. We state this theorem without proof.

Theorem 1. Let y′ = F(x, y) be a first order system of differential equations ofdimension n with y = (y1, . . . , yn)T and F = (F1, . . . , Fn)T and initial conditionsyi(x0) = yi0, x0, yi0 ∈ R, i = 1, . . . , n. Assume that F is continuous and that Fi isLipschitz in the variables yj for all i, j = 1, . . . , n, i.e.,

| Fi(x, y1, . . . , yn)− Fi(x, y1, . . . , yn) |≤ M max1≤j≤n

| yj − yj |, ∀ i = 1, . . . , n,

where M > 0 is a positive constant. Then the first order system of differential equa-tions y′ = F(x, y) has a unique solution y1(x), . . . , yn(x) on the interval

I := {x ∈ R s.t. | x− x0 |≤ δ}for some δ > 0.

2

2 Runge-Kutta methods

We are interested in solving numerically ODE and in how different numerical methodsbehave on ODE’s, especially the Stormer-Verlet method. In order to do that, weintroduce a family of methods, called Runge-Kutta methods in honor to the Germanmathematicians Carl Runge and Martin Kutta who developed these methods. Onething should always be in the mind of the reader, looking to a numerical method forsolving an ODE: the expression of the derivative of a function g

g′(a) = limh→0

g(a + h)− g(a)

h,

because this gives an approximation of the function at the point a + h, for small h,

g(a + h) ≈ g(a) + hg′(a).

This leads to the Taylor series of g, that gives a good approximation of a function.We will now define the Runge-Kutta methods’ family and concentrate on two of themost famous methods of this type: the midpoint method and the Euler method. Wegive just the definition for an ODE of first order, since we know that if the ODE isof order greater than 1, we can always translate the ODE on to a first order systemof differential equations.

Definition 4. Let F (x, y) = y′ be an ODE with initial condition y(x0) = y0. Leth > 0 be a positive real, called step size, and s a positive integer, called number ofstages. Define xn := x0 + nh and let yn be the approximation of y(xn), n ≥ 0. Thena s-stage explicit Runge-Kutta method is of the form

yn+1 = yn + hs∑

j=1

bjkj

wherek1 = F (xn, yn)k2 = F (xn + c2h, yn + ha21k1)k3 = F (xn + c3h, yn + h(a31k1 + a32k2))...

......

ks = F (x0 + cs, yn + h(as1k1 + · · ·+ as,s−1ks−1))

and a21, a31, a32, . . . , as1, . . . , as,s−1, b1, . . . , bs, c1, . . . , cs ∈ R.

Remark:

1. A method is often denoted by Φh, with h > 0 the step size, in order to saythe yn+1 = Φh(yn). Φh is called an one-step method because we approximatey(xn+1) just by yn and not by other previous approximation (e.g. by yn andyn−1). The function Φh : R → R is called the numerical flow.

3

2. The term explicit refers to the fact that we compute directly the approximationyn+1 from yn, i.e., yn+1 = Φ(yn) and not that we can find yn+1 solving anequation, i.e., yn+1 = Φh(yn+1, yn). In the latter case the method is calledimplicit.

It is easy to extend the definition and the remarks in the case of a first order systemof differential equations of finite dimension.We will not discuss the convergence of a method, i.e., if the approximate solutionapproaches the exact solution when h goes to 0, in details because it will requiresome ”advanced” definitions...

Definition 5. The local error of a method is the error made by a step of the method,assuming that no error was made in earlier steps:

δh := ||y(xn + h)− yn+1|| = ||y(x0 + h)− y1|| .

A method is said to be consistent if

limh→0

δh

h= 0

and to have order p if δh = O(hp+1) as h → 0. Clearly if a method is of order p ≥ 1,it is also consistent.

A Runge-Kutta method is consistent if we have

ci =i−1∑j=1

aij, 2 ≤ i ≤ s.

2.1 The explicit Euler method

The explicit Euler method is a 1 stage Runge-Kutta method of the form

yn+1 = yn + hF (xn, yn).

This method is simplest Runge-Kutta’s method. Indeed, for small h > 0, we have

y′(x) ≈ y(x + h)− y(x)

h,

and this givesy(x + h) ≈ y(x) + hF (x, y(x)) .

Hence, this method is just the simplest approximation given by the definition ofderivative.We have that

y(x0 + h) = y(x0) + hy′(x0) +O(h2)

4

using the Taylor series of y. We know that

y′(x0) = F (x0, y) = F (x0, y0) and y(x0) = y0,

therefore

y(x0 + h)− y1 = y(x0) + hy′(x0)− y0 − hF (x0, y0) +O(h2)= y0 + hF (x0, y0)− y0 − hF (x0, y0) +O(h2)= O(h2),

so the Euler methods has order 1.

2.2 The explicit midpoint method

The midpoint method is a 2 stages Runge-Kutta method given by the formula

yn+1 = yn + hF

(xn +

h

2, yn +

h

2F (xn, yn)

).

Geometrically, the midpoint method can be viewed in the following way: assumingthat yn is the exact value of y(xn), the midpoint method gives yn+1 such that thesegment between yn and yn+1 is approximatively parallel to the tangent line at themidpoint y(xn + h/2).We look at the Taylor expansions of y(x0 + h) and F

(x0 + h

2, y0 + h

2F (x0, y0)

):

y(x0 + h) = y(x0) + hy′(x0) +h2

2y′′(x0) +O(h3)

and

F

(x0 +

h

2, y0 +

h

2F (X0, y0)

)= F (x0, y0)+

h

2Fx(x0, y0)+

h

2F (x0, y0)Fy(x0, y0)+O(h2),

where Fx, resp. Fy, denotes the partial derivative of F with respect to the variablex, resp. to the variable y. This gives

y1 = y0 + hF(x0 + h

2, y0 + h

2F (x0, y0)

)= y0 + h

(F (x0, y0) + h

2Fx(x0, y0) + h

2F (x0, y0)Fy(x0, y0) +O(h2)

)= y0 + hF (x0, y0) + h2

2Fx(x0, y0) + h2

2F (x0, y0)Fy(x0, y0) + hO(h2)

= y0 + hF (x0, y0) + h2

2Fx(x0, y0) + h2

2F (x0, y0)Fy(x0, y0) +O(h3).

On the other side, we know that y(x0) = y0 and y′(x0) = F (x0, y0). Moreover, wefind that

y′′(x0) = Fx(x0, y0) + F (x0, y0)Fy(x0, y0).

Finally, we gety(x0 + h)− y1 = O(h3),

hence, the midpoint method has order 2.

5

Figure 1: The exact solution ex of the ODE y′ = y, y(0) = 1 is the red line, in greenwe have the midpoint approximation and in blue the Euler approximation. The stepsize in the left picture is h = 1, in the right picture h = 0.25. The right picture showsthat the midpoint method converges faster than the Euler method.

2.3 Example

We want to solve numerically, using the two methods presented above, the ODE

y′ = y, y(0) = 1.

The exact solution is ex. Fix h > 0. For the Euler method we get

yn = (1 + h)n, n ≥ 0

while for the midpoint method we get

yn =

(1 + h +

h2

2

)n

, n ≥ 0.

3 Stormer-Verlet method

In this section, the Stormer-Verlet method is presented, with some of its interestingproperties, in the special case of a second order ODE of the form

q = F (q),

where the right-hand side does not depend on q. This equation is common in physics.There are variations of the Stormer-Verlet method for a genereal second order ODE.

6

Figure 2: Stormer-Verlet method. Left: two-step formulation. Right: one-step for-mulation.

3.1 Definition

Let h > 0 be the step size. The simplest case is just the discretisation of the ODE,i.e.,

qn+1 − 2qn + qn−1 = h2F (qn).

It is a two-step method since qn+1 is computed using qn and qn−1. This formulation isnot very interesting. We know that we can transform a second order ODE into a firstorder system of differential equations of dimension 2, in order to do so, we introducethe unknown function v = q and the system becomes

v = q, v = F (q).

In physics often this type of system is closely related to the motion of a physical body.In this sense, we can see v as the velocity, q as the displacement (as functions of thetime) and F describes some kind of force acting on the physical body.We set

vn =qn+1 − qn−1

2h.

Inserting these expressions in the two-step formulation gives a one-step method Φh :(qn, vn) 7→ (qn+1, vn+1) of the form

qn+1 = qn + h(vn + h

2F (qn)

),

vn+1 = vn + h2F (qn) + h

2F (qn+1).

This formulation of the Stormer-Verlet method is more economic to implement fornumerical calculation and is also numerically more stable than the two-step formula-tion.

Recall that the flow of a first order system of differential equations y = F(x, y)of dimension n is the function ϕx : Rn → Rn which associates, for a given x, to the

7

initial condition y0 = y(x0) the corresponding solution value at x

ϕx(y0) = y(x),

where y depends on the choice of the initial value y0. Sometimes ϕx is called theexact flow, in order to avoid confusion between the flow of a first order system ofdifferential equations and the numerical flow of a method.Let us look at the order of the Stormer-Verlet method. Recall that δh = ||y(x0 + h)− y1||,where y(x) is the solution of the system

y =

(qv

)=

(v

F (q)

)= F(y).

with initial conditions v0 = v(x0), q0 = q(x0). We have

y1 =

(q1

v1

)=

(q0 + h

(v0 + h

2F (q0)

)v0 + h

2F (q0) + h

2F (q1)

)and y(x0 + h) =

(q(x0 + h)v(x0 + h)

)We have also the following Taylor expansions

q(x0 + h) = q0 + hv0 + h2

2F (q0) +O(h3),

v(x0 + h) = v0 + hF (q0) + h2

2v(x0) +O(h3),

F (q1) = F (q0) + h(v0 + h

2F (q0)

)F (q0) +O(h2).

Note that v(x0) = F (q0)v0 since v(x) = F (q(x)) gives v(x) = F (q(x)) q(x) =F (q(x)) v(x). We have

q(x0 + h)− q1 = O(h3) and v(x0 + h)− v1 = O(h3)

and this implies that the Stormer-Verlet method has order 2.

3.2 Properties

We introduce some notions.

Definition 6. Let Φh : (qn, vn) 7→ (qn+1, vn+1) be a one-step method for the firstorder system of differential equations v = q, v = F (q).

• Φh is called symmetric ifΦh = Φ−1

−h,

where Φ−1−h denotes the method Φ−h : (qn+1, vn+1) 7→ (qn, vn), i.e, we invert the

subscripts n and n + 1, as a reflection based on xn+ 12.

• the numerical flow Φh is called reversible if

Φh(q, v) = (q, v) implies Φh(q,−v) = (q,−v),

for all q, v and for all h.

8

Figure 3: On the right some non-symplectic methods. On the left the simplecticityof the Stormer-Verlet method.

• the method Φh is called symplectic if it satisfies

Φ′h(q, v)T

(0 1−1 0

)Φ′

h(q, v) =

(0 1−1 0

),

for all q, v, h and where Φ′h denotes the Jacobian of Φh.

For a method Φh, to be symmetric means that when we have computed an ap-proximation yn, starting with initial condition y0, if we apply the method Φ−h withinitial condition y0 = yn, after n steps we have that yn = y0. Intuitively, this meansthat if we reverse the time, we return where we started.The reversibility is a very important, because in the case of the above system the flowsatisfies the same condition and in the case of physics equations this means that in-verting the initial velocity does not change the trajectory, it just inverts the directionof the motion.The property of being symplectic is also very important, because it implies the preser-vation of the volume: if the flow of a first order system of differential equations issymplectic, we have that, for a given x, vol (ϕx (U)) = vol (U), for any open boundedset U such that the flow is defined in U . Indeed, the fact to be symplectic impliesthat |det Φ′

h(q, v)| = 1, for all q, v and h, therefore

vol (ϕx (U)) =

∫ϕx(U)

dy =

∫U|det Φ′

h(q, v)| dy0 =

∫U

dy0 = vol(U).

We can see this in the figure 3: the cats denotes a set of initial values; if a method issymplectic the cats have always the same area.Remark that the midpoint and the Euler methods haven’t any of these properties,although they can have one or more of these properties in the case of a particularsystem of differential equations.

We prove now that the Stormer-Verlet method satisfies the above conditions.

Theorem 2. The Stormer-Verlet method is symmetric.

9

Proof: We have Φ−h : (qn, vn) 7→ (qn+1, vn+1)

qn+1 = qn − h(vn − h

2F (qn)

),

vn+1 = vn − h2F (qn)− h

2F (qn+1).

Inverting n and n + 1 we get Φ−1−h : (qn+1, vn+1) 7→ (qn, vn), explicitly

qn = qn+1 − h(vn+1 − h

2F (qn+1)

),

vn = vn+1 − h2F (qn+1)− h

2F (qn).

Finallyqn+1 = qn + h

(vn+1 − h

2F (qn+1)

)= qn + h

(vn + h

2F (qn)

),

vn+1 = vn + h2F (qn) + h

2F (qn+1),

hence Φh = Φ−1−h and Φh is symmetric.

Theorem 3. The Stormer-Verlet method is reversible.

Proof: We have

Φh(q, v) = (q, v) =

(q + h

(v +

h

2F (q)

), v +

h

2F (q) +

h

2F

(q + h

(v +

h

2F (q)

)))and so

Φh(q,−v) =

q + h

(−v +

h

2F (q)

)︸ ︷︷ ︸ , −v +

h

2F (q) +

h

2F

(q + h

(−v +

h

2F (q)

))︸ ︷︷ ︸

.

α β

We get

α = q + h(v + h

2F (q)

)+ h

(−v − h

2F (q)− h

2F (q) + h

2F (q)

)= q

andβ = −v − h

2F (q)− h

2F (q) + h

2F (q)+

+ h2F

(q + h

(−v − h

2F (q)− h

2F (q) + h

2F (q)

))= −v − h

2F (q) + h

2F

(q + h

(v + h

2F (q)

)+ h

(−v − h

2F (q)

))= −v.

This gives Φh(q,−v) = (q,−v), hence Φh is reversible.

10

Theorem 4. The Stormer-Verlet method is symplectic.

Proof: Write Φh in the following way:

Φh(q, v) = (Φ1(q, v), Φ2(q, v)) .

The Jacobian Φ′h(q, v) is the matrix(

∂qΦ1(q, v) ∂vΦ1(q, v)∂qΦ2(q, v) ∂vΦ2(q, v)

).

We get

Φ′h(q, v)T

(0 1−1 0

)Φ′

h(q, v) =

(0 ∂qΦ1∂vΦ2 − ∂vΦ1∂qΦ2

−(∂qΦ1∂vΦ2 − ∂vΦ1∂qΦ2) 0

)(q, v).

We have

∂qΦ1(q, v) = 1 + h2

2F ′(q),

∂qΦ2(q, v) = h2F ′(q) + h

2F ′ (q + h

(v + h

2F (q)

)) (1 + h2

2F ′(q)

),

∂vΦ1(q, v) = h

∂vΦ2(q, v) = 1 + h2

2F ′ (q + h

(v + h

2F (q)

)).

This gives

(∂qΦ1∂vΦ2 − ∂vΦ1∂qΦ2)(q, v) =(1 + h2

2F ′(q)

) (1 + h2

2F ′ (q + h

(v + h

2F (q)

)))−

− h(

h2F ′(q) + h

2F ′ (q + h

(v + h

2F (q)

)) (1 + h2

2F ′(q)

))= 1 + h2

2F ′(q) + h2

2F ′(q + . . .) + h4

4F ′(q)F ′(q + . . .)−

− h2

2F ′(q)− h2

2F ′(q + . . .)

(1 + h2

2F ′(q)

)= 1

and therefore Φh is symplectic.

3.3 Examples

Let us look at two example: the Kepler problem and the aurora borealis.The first example is very famous, known as Kepler problem because Johannes Kepler(1571-1630) proposed a similar formula for the celestial orbits, i.e., the equations thatdefine the displacements of two celestial bodies that interact by a force. Explicitly

q1 = − −q1

(q21 + q2

2)3/2

, q2 = − q2

(q21 + q2

2)3/2

,

11

Figure 4: Kepler problem; dashed: exact solution.

with initial condition

q1(0) = 1− e, q2(0) = 0, q1(0) = 0, q2(0) =

√1 + e

1− e

and e = 0.6. In a two-body problem, the exact solution (q1, q2) describes the orbitof a body with respect to the other body and has period 2π. Figure 4 shows thebehavior of the Stormer-Verlet method with different step-size and different numberof steps compared to the explicit midpoint method presented above. We know thatthe midpoint method has the same order of the Stormer-Verlet method, but the figureshows us that the Stormer-Verlet method approximate pretty well the exact solutionin the two cases, instead the midpoint method deteriorates rapidly when the step-sizeincreases and in both cases is less accurate than the Stormer-Verlet method. Weremark the fact that the Kepler problem was the foundation of Newton’s theory ofuniversal gravitation.The second example is the original problem that Carl Stormer tried to solve numeri-cally in 1907. Stormer tried to confirm numerically a previous conjecture, that saysthat the phenomenon known as aurora borealis (figure 5) is produced by electricalparticles emanating from the sun and moving in the earth’s magnetic field. We arenot interested in all the detailed calculations, we hope to convince the reader that us-ing the Stormer-Verlet method we obtain a solution that approaches the real behaviorof these particles as shown in the figure 6. This picture shows 125 solution curves inthe 3-dimensional space with neighboring initial values: this gives an impression ofhow an aurora borealis comes into being.

12

Figure 5: 125 solution curves using the Stormer method.

Figure 6: The aurora borealis.

13

Contents

1 Ordinary differential equations 1

2 Runge-Kutta methods 3

2.1 The explicit Euler method . . . . . . . . . . . . . . . . . . . . . . . . 4

2.2 The explicit midpoint method . . . . . . . . . . . . . . . . . . . . . . 5

2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3 Stormer-Verlet method 6

3.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

References

• Solving Ordinary Differential Equations Vol. I, E. Hairer, S.P. Nørsett, G. Wan-ner, Springer, 1993.

• Geometric numerical integration illustrated by the Stormer/Verlet method (ActaNumerica (2003) pp. 1-51), E. Hairer, C. Lubich, G. Wanner, Cambridge Uni-versity Press, 2003.

14