Symplectic Notation

Motivation and Development of a First Order Symplectic Integrator
William F. Barnes
University of Massachusetts
Physics 601 – Final Project Part 1 of 2
December 2010
Abstract
Various first-order numerical techniques are employed to approximate the evolution of
the simple harmonic oscillator, comparing each scheme's performance to the behavior
predicted in Hamiltonian dynamics. We witness the breakdown of Euler’s method as
energy is artificially added to a Hamiltonian system, motivating the pursuit of a
symplectic integrator. By construction, a symplectic integrator preserves the
Hamiltonian, and is ideal for the study of systems requiring a large number of iterations.
A first order symplectic integrator has been developed for this paper and is demonstrated
on the SHO; the output of which is clearly in agreement with our analytical notions of the
system's behavior.
Following this paper, the reader should turn to the accompanying document Applications
of the First Order Symplectic Integrator (page 18). In this report, we use a two
dimensional adaptation of the first order symplectic integrator to explore various Physics
601 homework problems and examples form course lectures.
Introduction
Computer algorithms for solving differential equations by iteration have been vigorously
developed and utilized in the twentieth century. Techniques such as Euler's method (first
order) and the Runge-Kutta method (second order) have shown great success in solving
problems in computational physics. Despite their triumphs in certain problems however,
many numerical schemes are prone to manifest fallacious results when employed in
chaotic and other long-lived systems [2].
For problems in Hamiltonian mechanics, we will show how Euler’s method inherently
causes the energy of the system to accumulate an error proportional to the square of the
time step for every iteration. Over long times, the cumulative effect is an exponential
growth or decay in the magnitude of the Hamiltonian.
To avoid accumulating an error every iteration, it's natural to push the time step t as
low as possible, given the technology available. The trade-off is in total computation
time, which is inversely proportional to the time step. It follows that a perfectly accurate
numerical scheme (which takes t  0 ) would require an infinitely fast processor to
produce any results. Consequentially we must settle for a reasonably small time step.
Page 1
Given this, why in 2010 should we concern over errors induced by the time step t ,
where historically this number is approaching zero? For example, consider a simulation
where we are to find the trajectory of a pitched baseball. In this case, the order of a
suitable t may be a millionth of as second, thus the total number of iterations will be on
the order of one million. The error in the Hamiltonian will be small and predictable, and
t can be tuned to meet the demands of the investigator.
Errors caused by t cannot be made negligible in long-lived problems, as when
computing the trajectory of an asteroid over several millennium. The Hamiltonian will
veer away from it's true value as a consequence of the sheer number of iterations required
to simulate several millennium. If we take t too small, the simulation might take an
undesirably long time to finish. Moreover, the number of iterations will become too large,
and the error in the energy will become appreciable. This is a curious instance where
more computing power won’t bail us out.
The sum of these consequences clearly motivates the need for a new iterative scheme that
preserves the Hamiltonian without resorting to pushing t to it's lowest physical limit.
Such a scheme is called a symplectic integrator. A symplectic integrator is by definition a
canonical transformation [2] that brings the generalized coordinates at a given time step
into their correct form at the next time step, meanwhile preserving the form of the
Hamiltonian.
In this paper we use the SHO to demonstrate the failure of two variations of Euler's
method (called forward the backward methods), causing a violation in the conservation
of energy. When combined however, we show that the Forward Euler’s method and the
Backward Euler’s method actually do form a symplectic integrator, which we prove by
satisfying the symplectic condition.
TABLE OF CONTENTS
1. Review of Euler’s Method
2. The 1D Simple Harmonic Oscillator using Forward Euler’s Method
3. Breakdown of Euler’s Method in Hamiltonian Mechanics
4. The Backward Euler’s Method
5. Symplectic Notation
6. Motion as a Canonical Transformation
7. The Symplectic Condition
8. Construction of a Symplectic Integrator
9. Generalization of the Symplectic Scheme
Appendix: source code for 1D integrator
References
Addendum: Applications of the First Order Symplectic Integrator
Appendix: source code for 2D integrator
Page 2
3
5
7
7
9
10
11
13
15
16
17
18
29
1. Review of Euler’s Method
To set the tone of this paper, we begin with a derivation of Euler’s method from
elementary calculus and demonstrate how easily it delivers numerical solutions to a given
problem. The term “easily” means that a computer isn’t always necessary, and only a few
iterations give satisfactory convergence.
As an example, suppose we need to find a decimal value for
defining
8 . Set up the problem by
y(x)x2 8.
 
The solution satisfies y 8  0, so choose an initial guess for 8 , say, x0  2.5 . In
Figure 1 we select this point on a plot of y (x) . The tangent to the curve at x0 , indicated
by the dashed line, crosses the x-axis at some new x1 .
Figure 1. Euler’s method taking the guess of 2.5 closer to the true value of
8.
We can make a crucial observation: the new x1 is closer to 8 than the initial guess x0 .
(This feature generically holds for well behaved y (x) , so long as the initial guess is
reasonable.) We may then repeat this process, using x1 as a guess to determine x 2 , and
so on. Subsequent iterations cause x n to approach the value of 8 .
This scheme applies to a large spectrum of functions y (x) , so we want a formula that can
be applied to an arbitrary (well-behaved) problem. In the general case, the equation of the
(x
)y
'(x
x
b
0)
dashed tangent line is g
, where b can be eliminated using
g
(x
)
y
'(x
)x
b
0
0
0
. In this construction, g ( x0 ) is identically y ( x0 ) , so the equation of
the tangent line in terms of x and x0 is
Page 3
g
(
x
)

y
'(
x
)(
x

x
)

y
(
x
)
.
0
0
0
We are interested in where this line crosses the x-axis. Letting g(x1)  0 and solving for
x gives
y(x0)
x
1 x
0
y'(x0).
Since y ( x0 ) and y ' ( x0 ) are computed from the given function y (x) , the right side of
this equation is completely known and yields a decimal value which we may assign to x1 .
The above equation can be iterated using x1 as a “guess” to determine x 2 , and so on.
Generalizing to the nth step, we arrive at the famous formula for first-order Euler’s
method:
y
(x
n)
x
x
n

1
n
y
'(x
n)
2
Going back to our example of y(xn)xn 8, we have y'(xn) 2xn. The recursive
formula is therefore
x
8
n 
x
x
.
n

1
n
2
x
n
2
Beginning with the initial guess of x0  2.5 , the results of successive iterations of Euler’s
are listed in Table 1.
Table 1: Successive approximations of 8 using Euler's method.
Iteration #
xn
0
x0  2.5
1
x1  2.85
2
x
2
.8285087719
3
2
3
x
2
.8284271259
2
3
4
x
2
.8284271247
5
4
5
x
2
.8284271247
5
5
We see that numbers x 4 and x5 are indistinguishable from each other to at least 12 digits,
so x n is surely converging to some number. As it turns out, Wolfram Alpha [4] verifies
.8284271247
5happens to be the first 12 digits of 8 .
that the decimal 2
Page 4
We have witnessed Euler’s method bringing us swiftly to the answer. Only four iterations
following a rather crude guess x0  2.5 were enough to narrow the precision of x n to the
limit of a standard graphing calculator.
2. The 1D Simple Harmonic Oscillator using Forward Euler’s Method
We wish to iteratively attain q (t ) and p (t ) for the one-dimensional simple harmonic
oscillator (1D SHO). Naturally, start from the Hamiltonian and the equations of motion.
2
p
12
H
(
q
,p
) kq
,
2
m2
H p

q
 ,
p m

H
 
p
kq
.

q
Expanding the equations of motion allows us to solve for new values of q and p in
terms of old values of q and p . These are the forward Euler’s method formulae.
qn1qn pn


t
m

q
q
p

t/m
n

1
n
n
p
p
n

1
n

kq
n

t

p
p
q

t
n

1
n
nk
A new variable emerges when writing out q and p . It’s now necessary to supply the
time step t between subsequent pairs of coordinates qn , pn  and qn1, pn1. In a good
approximation scheme, the time step must be very small compared to the characteristic
order of magnitude of the coordinates. Overall accuracy is directly related to the size of
the time step in any given simulation, so it’s best to use the smallest t possible.
In order to continue, it’s up to the investigator to program a system that can iteratively
evaluate q n 1 and p n 1 , starting with initial conditions q 0 and p 0 . For the purposes of
this section, a simulation was prepared in order to demonstrate a time-evolving failure of
Euler’s method. We consider the 1D SHO problem with a unit spring constant and a unit
mass:
2
2
p
q
H
(q
,p
) 
2 2
Suppose we have initial conditions q 0  1 , p 0  0 , corresponding to a mass being
released from rest under a linear restoring force. By analytic means, we already know the
full time evolution of this problem: q and p will exhibit sinusoidal behavior, and the
system has fixed energy. In the phase plane, q and p trace out a circle.
Page 5
Armed with a preconceived notion of the oscillator’s behavior, now we check whether a
QBASIC [5] simulation employing Euler’s method computes the motion properly. (See
Appendix 1 for source code.)
Figure 2. The forward Euler’s method adding artificial energy to a 1D SHO system.
Each plot traced out in Figure 2 is alarming. The position q (t ) and momentum p (t )
curiously gain amplitude over time. Correspondingly, the p vs. q phase portrait is not a
closed circle, but an unstable spiral. These characteristics were not built into the
Hamiltonian, so we conclude that Euler’s method is delivering fallacious results.
In order to bring about the failure of Euler’s method, we chose t  0.07, a relatively
large time step. We could choose t much smaller, say 0.0001 , and Euler’s method
would indeed produce near-perfect results for this problem. Quenching the overall error
comes at the cost of longer computing time, since the total number of iterations is
inversely related to the size of the time step,
Concerning the time-accuracy tradeoff, we may try to reason that computer speeds are
nowadays sufficient to take t much much smaller than the order of magnitude of the
system variables, diminishing the concern of t -related errors in computational physics.
This is true only in short-lived systems. We will show in Section 3 that no matter how
low one tries to set t , the Hamiltonian always accumulates an error, monotonically
shifting with each time step, raising a serious problem in any simulation where a large
number of iterations are required.
Page 6
3. Breakdown of Euler’s Method in Hamiltonian Mechanics
In this section we rigorously show that the energy of the 1D SHO artificially increases
during each iteration. Begin with the Hamiltonian.

1 2
p
n

1
H
(
q
,
p
)


k
q
n

1
n

1
n

1
2
m
2
2
 
Replace q n 1 and p n 1 using the forward Euler’s method formulae,
p
n
q
q

t,
n

1
n
m
p
p
q

t.
n

1
n
nk
Cancel and combine like terms.
2
2


p

q
k

t
1
p
n
n
n
H
(
q
,
p
)


k
q


t


n

1
n

1
n
2
m
2
m



p
q
k

t
2
p
q
k

t
p
p
1
1
1


2
n
n
n
n
n
n
H
(
q
,
p
)




kq

k

t

k
2
q

t


n

1
n

1
n
n
2
m
2
m
2
m
2
2
m
2
m


2
2
2

1
p
q
k

t
p


2
n1
n
n
H
(
q
,
p
)


kq


k

t


n

1
n

1
n
2
m
2 2
m
2
m


2
2
2
2
2


q
k
p
k
2
n
n


H
(
q
,
p
)

H
(
q
,
p
)


t

n

1
n

1
nn


m
2
2
m


 k2

H
(
q
,
p
)

H
(
q
,
p
)
1


t

n

1
n

1
n
n
m

From this statement it’s evident that the Hamiltonian actually grows exponentially.
Before being tempted to leave Euler’s method in the dust, we introduce a variation of the
procedure: the backward Euler’s method.
4. The Backward Euler’s Method
The best way to introduce the variation to Euler's method is to start with the forward
Euler’s method formulae for the 1D SHO:
Page 7
q
q
p

t/m
n

1
n
n
p
p
q

t.
n

1
n
nk
Looking back at how we developed the forward Euler's method formulae from the
equations of motion, it's reasonable to have instead chosen updated coordinates on the
right-hand side. This amounts to changing the coordinate index on the t term as
follows:
q
q
p

t/m
n

1
n
n

1
p
p
q
k

t.
n

1
n
n

1
Looking at the left-hand equation, changing the index from p n to p n 1 means that the
coordinate q is computed using the new value of momentum. Similarly the new p
depends on the new q in the right-hand equation. Solving for q n 1 and p n 1 gives us the
backward Euler’s method formulae:
q
p

t/m
n
n
q
n

1
1

(
k/m
)

t2
p
q
k

t
n
n
p
n

1
.
1

(
k/m
)

t2
In this section we employ a modified version of the previous QBASIC simulation which
uses the backward Euler’s method. The mass and the spring constant are again
dimensionless and set to unity. Initial conditions are comparable between the two
simulations.
Figure 3. Backward Euler’s method artificially reducing the energy of a 1D SHO.
Page 8
Figure 3 illustrates why this variation is called the “backward” Euler’s method. In a
totally complementary fashion, this approximation scheme monotonically dampens the
Hamiltonian. Thus the amplitudes of q and p likewise dampen, and the phase plot spirals
inward accordingly.
Right away we can suspect something about our two different simulation of the SHO: If
the forward Euler’s method causes the Hamiltonian to swell (Figure 1), and the backward
method causes the Hamiltonian to shrink, does a combination of the two methods fix the
problem altogether? That is, can we somehow stack the two Euler’s methods and get their
errors to compensate one another, thereby preserving the Hamiltonian indefinitely? The
answer is yes. To actually prove this, stronger mathematics is needed.
5. Symplectic Notation
Considering a system with n degrees of freedom, there are n pairs of generalized


(
q
,q
,...,
p
,p
,...)
coordinates, qi and pi . Construct a single column vector 
1
2
1
2
containing all 2n coordinates, such that
in  pi
 i  qi
The partial derivatives in Hamilton’s equation of motion,
i , can be expressed in vector notation:
H/pq
H H




 i qi
H
H



 p
 in
i
i  n.
i
H/qp
and
i  n.
Now, define the matrix J as square, size 2n x 2n , and awkwardly composed of zeros
and identity matrices according to the scheme
 0 I
J 
.
I 0
Some miscellaneous properties of matrix J , as detailed in Classical Mechanics by
Goldstein [1], are:
1
J J J
T
J  1
2
J  1.
Hamiltonian’s equations of motion can now be written in the compact form:

H
  J  .

Page 9
For example, a system with two coordinate variables this expands out to:
1 0
q
q
 
 20
p
1 1
  
2 0
p
1
0 1 0
p


2
0 01

p
1 .
 q
0 00
 
2 
1 0 0
 q
This matrix representation of Hamilton’s equations is called the Symplectic notation.
6. Motion as a Canonical Transformation
Let us consider systems where the Hamiltonian takes the form

2
p


H
(
q
,p
,t
) 
V
(
q
,t
)
.
2
m



The generalized coordinates q and p are functions of time, with given initial values q0

and p0 (corresponding to t  0 ).
  
qqq0,p0,t
  
ppq0,p0,t
Due to the canonical nature of the equations of motion, the above expressions may be
 
 
interpreted as a canonical transformation [2] from state q0 , p0 to state q , p . We may
write this as:


q
M
q
.
,p
(
t)
,p
0
0
The problem is reduced to finding a suitable matrix M , a size 2n x 2n Jacobian matrix.
The form of M depends on the particular Hamiltonian in consideration, and it also varies
per integration scheme. We will focus on finding such a matrix in the subsequent section.
For the moment we only describe how to use M .
Even if the Hamiltonian is simple, there is little hope of finding some general M (t ) to go
 
 
directly from q0 , p0  to q , p  . However the behavior of M for small t is attainable.
The generalized coordinates at small t can thus be computed, giving us two new points,
  
  
q
q
q
q
,p
,0

tand p
p
,p
,0

t.
1
1
0
0
1
1
0
0
Page 10


This procedure can be repeated using the new coordinates q1 and p1 as input. (The
matrix M changes predictably as a result of the first iteration.) Choosing the same small
  
 

p
q
,p
,
0

t
t
q
q
,p
,0

t
tand p
time step, we gain the points q
. Many
2
2
0
0
2
2
1
1
repetitions of this will provide precisely what we set out to find: the generalized
 
coordinates over long spans of time, starting from q0 , p0  . Up to now, this procedure is
much like our earlier employment Euler’s method.
In fact, we can write the forward and backward Euler’s method formulae in matrix


M
q
. (Observe that M varies per scheme.)
q
,p
(
t)
,p
0
0
notation according to 
q
q
p

t/m
n

1
n
n
p
p
q

t
n

1
n
nk
Forward method

q
q
p

t/mBackward
n

1
n
n

1
method
p
p
q
k

t
n

1
n
n

1

q
q
t
/
m

 1 



n

1
n







p
p

k

t 1
n

1
n




q
q
1
t
/
m





1
n

1
n







2
p
p

k

t 1
1

(
k
/
m
)

t
n

1

n




The innovative step is to lay restrictions on M . Generally, many different matrices can
transform the coordinates, as seen in the forward and backward Euler’s methods. As it
turns out, we concern over matrices M that preserve symplectic structure.
7. The Symplectic Condition
The pressing question is, what features must M possess in order canonically transform
 


qn , pn into qn1 , pn1 ? Recall the symplectic formulation of Hamilton’s equations

H
 J 

n
n ,




(
q
,q
,...,
p
,p
,...)
where the vector  was defined as 
. Suppose  n is the set of
1
2
1
2

coordinates at some arbitrary time, and  n1 represents the coordinates a short time later.
We demand that the following relations both hold:

H
 J 

n
n

and
?
H
 J 

n1
n1 .
That is, we want Hamilton’s equations of motion to retain their symplectic structure


under a transformation n n1 , hence the “?” symbol over the equality sign in the
Page 11
right-hand equation. In this regime we are preventing the artificial inflation or deflation
of the Hamiltonian from the outset.



M
q
.
q
,p
(
t)
,p
Inside the left-hand equation, replace each  n with the form 
0
0

Switchtothecondensedvectornotation,andthisreadsn1M(t).Afeweasymovesinlinearalgebraputallmatricesontherightsideoftheequation,resultingin
algebra put all matrices on the right side of the equation, resulting in
H

T 
 

J
M .
n

1 M


n

1
Evidently, the quantity M J M


transformation n n1 .
T
must equal J in order for M to perform a canonical
The relation MJM J is known as the Symplectic Condition. With this restriction on
M , we can choose numerical schemes that rule out artificial inflation or deflation of the
coordinates.
T
Let M 1 denote the matrix form in the forward Euler’s method formulae, and let M 2
represent the backward method. We can explicitly show that both variations of Euler’s
T
method fail to satisfy MJM J.
k


2
0 1


t


1

t
/
m
0
1
1

k

t






T
m
M
J
M




11 




 k

2

k

t 1

1
0

t
/
m
1









1


t
0


m






0
1
0
1





Tk
2
M
J
M

1


t



1
1





1
0

1
0
m





It’s no accident that the extra factor on the right hand side matches the factor that causes
the Hamiltonian to artificially change. For comparison, recall the following relation (from
section 3) that came as a consequence of the forward Euler’s method:
 k2

H
(
q
,
p
)

H
(
q
,
p
)
1


t

n

1
n

1
n
n
m

Similarly we perform the same check on M 2 , resulting in
0

1
0

1
 1




T


M
J
M


2
2
.




2


1
0
1
0
1

(
k
/
m
)

t






Page 12
0 1
T
T
Clearly, neither M1 J M1 nor M2 JM2 went back to the form 
.
1 0 
The forward and backward Euler’s methods are not symplectic integrators, as their
T
corresponding matrices do not satisfy MJM J.
8. Construction of a Symplectic Integrator
Following up on a previous remark, a suitable combination of the forward and backward
Euler’s methods will balance as to retain symplectic structure, thus preserving the
Hamiltonian over long times. We are now prepared to introduce the symplectic method.
Forward:
q
q
p

t/m
n

1
n
n
p
p
q

t
n

1
n
nk
Backward:
q
q
p

t/m
n

1
n
n

1
p
p
q
k

t
n

1
n
n

1
Symplectic:
q
q
p

t/m
n

1
n
n
p
p
q
k

t
n

1
n
n

1
The new variation uses q n 1 from the forward Euler’s method, and p n 1 from the
backward Euler’s method. Solving for q n 1 and p n 1 brings out the symplectic iterative
(
q
,p
)
T
(p
)
V
(
q
). See
formulae. (Note this section applies to problems of the form H
Section 9 for details on generalizing the symplectic scheme.)

q
q
p

t/m
n

1
n
n

2
p

p
1

(
k
/
m
)

t

q
k

t
n

1
n
n
The corresponding matrix representation is:
q
q
1 
t
/
m





n

1
n







2
p
p

k

t1

(
k
/
m
)

t
n

1
n




The next task is to determine if the above matrix satisfies MJM J. Without any loss
of generality, let k / m  1 to ease the algebra.
T
1

t
0
1
1


t
0
1








T
M
J
M










2
2


t
1


t

1
0

t
1


t

1
0








T
The product M J M indeed equals J on the right hand side, so the new scheme satisfies
the symplectic condition!
Page 13
We can explicitly show that the Hamiltonian will remain stable. Using elementary
calculus to expand Hamilton’s equations of motion, we have:
q 
H
p
 
p
H
q

q

q
H
(
q
,
p
)

H
(
q
,
p
)
H
n

1
n

1
n
n
nn

t 
p
p

p
n
n

1
n

p

p
H
(
q
,
p
)

H
(
q
,
p
)
H
n
n

1 
n

1
n

1
n
n

1




t

q
q

q
n
n

1
n
Note that the p equation uses the updated momentum q n 1 , matching the theme of the
symplectic iterative formulae. Rearranging and combining Hamilton’s equations lead us
to the anticipated result.
1




q

q
p

p

H
(
q
,
p
)

H
(
q
,
p
)
n

1
n
n

1
n
n
n

1
n
n

t
1




p

p
q

q

H
(
q
,
p
)

H
(
q
,
p
)
n
n

1
n

1
n
n

1
n

1
n
n

1

t

0

H
(
q
,
p
)

H
(
q
,
p
)

H
(
q
,
p
)

H
(
q
,
p
)
n
n

1
n
n
n

1
n

1
n
n

1
H
(
q
,p
)

H
(
q
,p
)
n

1
n

1
n
n
The Hamiltonian is indeed preserved between time steps. Revisiting the 1D SHO, we
may now test the claims of this section using another variation of the original QBASIC
simulation.
Page 14
Figure 4. Symplectic integration producing realistic results for the 1D SHO.
Remarkably, the symplectic integrator produces results that perfectly match our
preconceived notion of how an ideal 1D SHO should behave. Throughout our three
simulations (forward Euler’s method, backward Euler’s method, and now symplectic),
the time step constant has remained fixed at t  0.07. Figure 4 illustrates how a crude
time constant didn’t drag solutions off track as we previously encountered.
9. Generalization of the Symplectic Scheme
Our symplectic integrator in the previous section only solves the one-dimensional simple
harmonic oscillator. To generalize this scheme to a greater range of problems, go back to
the founding equations of the symplectic iterative formulae:
qn1qn 
H


t

pn



q
q

H
/
p

t
n

1
n
n
p
p

H
n

1
n


t

q
n

1



p

p


H
/
q

t
n

1
n
n

1
No explicit integrator has been discovered that can treat a general Hamiltonian [3]. (For
the treatment of a general Hamiltonian, an implicit method must be used; we focus on
explicit methods in this study.) We are therefore limited to solving cases when the
Page 15
(
q
,p
)
T
(p
)
V
(
q
). In this case, the most general
Hamiltonian is separable via H
symplectic iterative formulae are:


q
q

T
/
p

t
n

1
n
n


p

p


V
/
q

t
n

1
n
n

1
This completes the motivation, construction, and demonstration of a first order
symplectic integrator.
We now turn to the associated document, Applications of the First Order Symplectic
Integrator.
Page 16
Appendix 1: Source code used for Figure 2, Figure 3, and Figure 4, corresponding to the
forward Euler’s method, the backward Euler’s method, and the symplectic method.
CLEAR : CLS : SCREEN 12
RANDOMIZE TIMER
PI = 3.141592653589793#
' q & p plot
x = q: y = p
y = y * .6
x = x * .6 + 180
GOSUB convert
PSET (x, y), 15
' Physical features
m = 1
k = 1
dt = .07
iterations = iterations + 1
t = TIMER
DO: LOOP UNTIL TIMER > t + .001
' Initial Conditions
q = 150 '50
p = 0
iterations = 0
' Graphing...
' Axis for q plot
y = 0: y = y * .2 + 160: GOSUB convert
LINE (0, y)-(640, y), 7
LOCATE 4, 3: PRINT "Position q(t)"
' Axis for p plot
y = 0: y = y * .2 - 160: GOSUB convert
LINE (0, y)-(640, y), 7
LOCATE 24, 3: PRINT "Momentum p(t)"
' Axis for q & p plot
LINE (320 + 180, 240 - 100)-(320 + 180,
240 + 100), 7
LINE (320 + 180 - 100, 240)-(320 + 180 +
100, 240), 7
LOCATE 8, 58: PRINT "Phase Plot"
LOCATE 10, 64: PRINT "p"
LOCATE 15, 75: PRINT "q"
LOOP UNTIL iterations = 800 OR INKEY$ =
CHR$(27)
SLEEP
'400
END
convert:
x = x + 320
y = 240 - y
RETURN
DO
qtemp = q
ptemp = p
' forward euler method
'q = qtemp + (ptemp / m) * dt
'p = ptemp - (qtemp * k) * dt
'backward euler method
'q = (qtemp + dt * ptemp) / (1 +
dt ^ 2)
'p = (ptemp - dt * qtemp) / (1 +
dt ^ 2)
'symplectic
q = qtemp + (ptemp) * dt
p = ptemp * (1 - dt ^ 2) - dt *
qtemp
' q plot
x = iterations: y = q
y = y * .2 + 160
x = x * .4 - 180
GOSUB convert
PSET (x, y), 15
' p plot
x = iterations: y = p
y = y * .2 - 160
x = x * .4 - 180
GOSUB convert
PSET (x, y), 15
Page 17
REFERENCES
[1] H. Goldstein, C. Poole, and J. Safko [2002], Classical Mechanics, third edition, San
Francisco: Addison-Wesley.
[2] R.D. Ruth, A canonical integration technique, IEEE Trans. Nuclear Science NS-30
(1983) 2669–2671.
[3] H.Yoshida, Phys.Lett. 150, 262 (1990).
[4] Wolfram | Alpha, 2010
[5] Microsoft | QBASIC, 1988
END FIRST DOCUMENT
SECOND DOCUMENT BEGINS ON NEXT PAGE
Page 18
Applications of the First Order Symplectic Integrator
(Addendum to Motivation and Development of the First Order Symplectic Integrator)
William F. Barnes
University of Massachusetts
Physics 601 – Final Project Part 2 of 2
December 2010
This addendum explores several physics problems that can be solved using a first order
symplectic integrator. Drawing from the final section of the document Motivation and
Development of the First Order Symplectic Integrator, we are concerning over cases
(
q
,p
)
T
(p
)
V
(
q
). In this regime, the most
when the Hamiltonian is separable via H
general symplectic iterative formulae are:


q
q

T
/
p

t
n

1
n
n


p

p


V
/
q

t
n

1
n
n

1
In this study we explore four problems:
(i)
(ii)
(iii)
(iv)
Particle in a 1 / r central potential
2
Particle in a 1 / r central potential
Two identical masses in a linear chain
The plane pendulum
In each case we start with the Hamiltonian, and then construct pairs of recursive relations
to compute the generalized variables.
All simulation data and graphics are generated by the QBASIC program
SYMPLEC_2D.BAS. This is a first-order two-dimensional symplectic integrator prepared
for the purpose of this paper. See Appendix 1 for the source code.
Page 19
Problem 1: Particle in a 1 / r potential
We begin with the 1 / r potential, corresponding to electrostatics, gravity, etc. Write the
Hamiltonian, taking gravity as a specific example.
2
p
GMm
H
(
r
,p
) 
2
m r
2
p

p
p
GMm
GMm
x
y
H
(
x
,
y
,
p
,
p
)



xy
22
2
m
r 2
m
x

y
2 2
Taking our Hamiltonian and applying the formulae for q n 1 and p n 1 lead to:
 

y 
y

t
p /m
x
x
x

tp
m
n/
n

1
n
n

1
y
n
n
x
x
n

 2x
p

p


t
GMm
n

1
n
3
/
2
2
x

y
n
n
y
y
n

 2y
p

p


t
GMm
n

1
n
3
/
2
2
x

y
n
n




The corresponding QBASIC statements are:
q1
q2
p1
p2
=
=
=
=
q1temp
q2temp
p1temp
p2temp
+
+
-
dt
dt
dt
dt
*
*
*
*
(p1temp / m2)
(p2temp / m2)
g * m1 * m2 * (q1 / ((q1 ^ 2 + q2 ^ 2) ^ (3 / 2)))
g * m1 * m2 * (q2 / ((q1 ^ 2 + q2 ^ 2) ^ (3 / 2)))
To test the simulation and to illustrate the relevant features we consider the trivial case
where initial conditions are set precisely to yield uniform circular motion.
Page 20
Figure 1. Particle in a 1 / r potential, circular orbit.
Figure 1 displays a collage of well-anticipated results for uniform circular motion.
Positions q1 (t ) and q 2 (t ) (representing x and y), and their corresponding momenta p1 (t )
and p 2 (t ) , are sinusoidal and out of phase by  / 2 . The phase plots pi (t ) vs. qi (t )
overlay each other as circles in the phase portrait (upper right), and the 2-space position
graph q 2 (t ) vs. q1 (t ) (lower right) also traces out a circle.
In the second run we consider a more arbitrary set of initial conditions, giving the output
in Figure 2. Judging from the position and momentum graphs, and even the phase plot,
it’s difficult to visualize the motion of the particle. Luckily, the position plot (lower right)
yields a familiar sight: an elliptical orbit characteristic of the 1 / r potential.
Page 21
Figure 2. Particle in a 1 / r potential, elliptical orbit.
2
Problem 2: Particle in a 1 / r potential
2
This time we look at the 1 / r potential. Let’s take a modified theory of Newtonian
2
gravity where the r dependence is now 1 / r . The corresponding Hamiltonian is
2
p
GMm
H
(
r
,p
)  2
2
m r
2
2
p

p
GMm
x
y
H
(
x
,
y
,
p
,
p
)


.
x y
2 2
2
mx

y
In this regime we begin with the peculiar initial condition that appears to yield uniform
circular motion, yet becomes unstable after about two periods. See Figure 3.
Page 22
2
Figure 3. Particle in a 1 / r potential, unstable orbit.
2
The motion of the particle is not surprising, as circular orbits are allowed in 1 / r
potential, but they are unstable flat points in the effective potential.
Problem 3: Two identical masses in a linear chain
Figure 4. Identical masses in a linear chain.
(Image altered from Wikipedia 2010.)
This problem is common in undergraduate and graduate mechanics courses. The
Hamiltonian in the case of identical masses is
Page 23
 

1
1
22
2
22


H
(
q
,
q
,
p
,
p
)

m
p

p

k
q

q

q

q
.
1
2
1
2
1
2
1
2
1
2
2
2
In order to avoid excessive use of subscripts, let:
q 2  q~
q1  q
p1  p
p2  ~
p
The corresponding symplectic transformation is:

q
q

tp
m
n

1
n
n
~
~




p

p

k

t
2
q

p
m

t

q

p
m

t
n

1
n
n
n
n
n
~
~
~

q
q

t
q
m
n

1
n
n
~
~
~




p

p

k

t
2
q

p
m

t

q

p
m

t
n

1 n
n n
n n
By analytic techniques, we know that this system has two normal modes:
q
1

 
 k 
 t


C
cos

1
1




~


q
1

 
 m 
q
1

 
 3
k 
 t


C
cos

2
2




~
 

q

1

 
 m 
For simplicity, let k / m  1.
We will look at two cases:
(i)
(ii)
Initial conditions are set so that the system expresses mode 2 only. This is the
higher energy mode, so we expect that each mass always move in a direction
opposing the other. The amplitude of the momentum plots is a factor of 3
greater than that of the positions. See Figure 5.
The left mass is displaced 5 units ( q(0)  5 ) and the system is released from rest.
The corresponding phase portrait traces out quasi-periodic curves, where the
position plot traces a Lissajous figure. See Figure 6.
Page 24
Figure 5. Second normal mode in linear chain system.
Page 25
Figure 6. Initial displacement problem in linear chain system.
Problem 4: The plane pendulum
Our study of the one-dimensional simple harmonic oscillator in the parent paper
Motivation and Development of the First Order Symplectic Integrator is a limiting case
of the more general oscillator called the plane pendulum (see Figure 7, Figure 8).
Figure 7. The plane pendulum.
Page 26
Figure 8. Phase portrait of the plane pendulum.
This is a one-dimensional problem in the sense that the only dynamical variable is the
angle at which the pendulum arm makes with the vertical, but as usual in Hamiltonian
dynamics, we separate the generalized coordinate q from its associated momentum p .
The rod is considered massless with a point object of mass m at its end. The Hamiltonian
is
2
p


H
(
q
,p
)
 2
mgL
cos
q
.
2
mL
The corresponding symplectic transformation is

t
p

p
sin(
q
)
n

1
n
n
.
mgL

t
q
q
n

1
n 2 p
n
mL
In this problem, we examine two near-critical scenarios:
(i)
The mass begins at its lowest point with some initial velocity p 2 (0) , which is
chosen so that the arm almost reaches the upright position, but has too little
energy to complete a revolution. The arm then falls back down the way it came,
and this motion continues indefinitely. See Figure 9.
We note that a symplectic technique here is not only pleasant but it is necessary. Using a
non-symplectic method (even of high order), the pendulum would erroneously gain or
lose energy over many iterations, ultimately breaking the periodicity the motion.
(ii)
The pendulum is given just enough energy to make a full revolution; the arm
will continue to spin around with the angular variable ever increasing. See Figure
10.
Page 27
Figure 9. Plane pendulum with energy just under critical limit.
Page 28
Figure 10. Plane pendulum with energy just over critical limit.
Page 29
Appendix 1: Source code for the two-dimensional symplectic integrator.
CLEAR : CLS : SCREEN 12: COLOR 15
RANDOMIZE TIMER
pi = 3.141592653589793#
systemdrag = 10
problem = 3
'index of problems
'1 particle in r^-1 central potential
'2 particle in r^-2 central potential
'3 equal masses in a linear chain
'4 plane pendulum
'Physical features
m = 1
m1 = 1
m2 = 1
L = 1
L1 = 1
L2 = 1
k = 1
g = 1
c = 1
E = .05
B = 2
'Computation and Graphing...
dt = .001
scalesmall = 1 * dt
scalebig = 1
'initial conditions
SELECT CASE problem
CASE 1
'q10 = 1: p10 = 0: q20 = 0: p20 = 1: scalebig = 20: scalesmall = dt * 10 'circular case A
'q10 = 1: p10 = -.2: q20 = 0: p20 = 1: scalebig = 20: scalesmall = dt * 10 'perturbed
case B
q10 = 1: p10 = .5: q20 = 0: p20 = 1.15: scalebig = 10: scalesmall = dt * 5 'arbitrary
case C
'q10 = .5: p10 = 1: q20 = -.5: p20 = 1: scalebig = 20: scalesmall = dt * 7 'symmetric
case CX
CASE 2
q10 = 1: p10 = 0: q20 = 0: p20 = 1.22437: scalebig = 20: scalesmall = dt * 10 'usnstable
circle case A
CASE 3
'q10 = 0: p10 = 5: q20 = 0: p20 = 5: scalebig = 4: scalesmall = 10 * dt 'symmetric mode
case A
'q10 = 5: p10 = 0: q20 = -5: p20 = 0: scalebig = 4: scalesmall = 10 * dt 'antisymm case B
q10 = 5: p10 = 0: q20 = 0: p20 = 0: scalebig = 5: scalesmall = 10 * dt 'displaced case C
CASE 4
q20 = 0: p20 = .5: scalebig = 5: scalesmall = 5 * dt 'case F1
q20 = 0: p20 = 1: scalebig = 5: scalesmall = 5 * dt 'case F2
q20 = 0: p20 = 1.75: scalebig = 5: scalesmall = 5 * dt 'case F3
q20 = 0: p20 = 1.999: scalebig = 5: scalesmall = 5 * dt 'case A
q20 = 0: p20 = 2.001: scalebig = 10: scalesmall = 5 * dt 'case B
CASE 5
END SELECT
'pre-loop conditions
q1 = q10: p1 = p10
q2 = q20: p2 = p20
iterations = 0
totaltime = 0
GOSUB drawaxes
DO
q1temp = q1: p1temp = p1
Page 30
q2temp = q2: p2temp = p2
'start of integration schemes
SELECT CASE problem
CASE 1
'particle in r^-1 central potential
q1 = q1temp + dt * (p1temp / m2)
q2 = q2temp + dt * (p2temp / m2)
p1 = p1temp - dt * g * m1 * m2 * (q1 / ((q1 ^ 2 + q2 ^ 2) ^ (3 / 2)))
p2 = p2temp - dt * g * m1 * m2 * (q2 / ((q1 ^ 2 + q2 ^ 2) ^ (3 / 2)))
CASE 2
'particle in r^-2 central potential
q1 = q1temp + dt * (p1temp / m2)
q2 = q2temp + dt * (p2temp / m2)
p1 = p1temp - dt * g * m1 * m2 * ((3 / 2) * q1 / ((q1 ^ 2 + q2 ^ 2) ^ (5 / 2)))
p2 = p2temp - dt * g * m1 * m2 * ((3 / 2) * q2 / ((q1 ^ 2 + q2 ^ 2) ^ (5 / 2)))
CASE 3
'FW 4.2: 2 equal masses in a linear chain
q1 = q1temp + m * (p1temp) * dt
p1 = p1temp - dt * k * (2 * (q1temp + m * (p1temp) * dt) - (q2temp + m * (p2temp)
* dt))
q2 = q2temp + m * (p2temp) * dt
p2 = p2temp - dt * k * (2 * (q2temp + m * (p2temp) * dt) - (q1temp + m * (p1temp)
* dt))
CASE 4
'plane pendulum
q1 = 0
p1 = 0
q2 = q2temp + dt * (1 / (m * L ^ 2)) * (p2temp)
p2 = p2temp - dt * (m * g * L) * (SIN(q2))
END SELECT
'end of integration schemes
'q1 plot
x = iterations: y = q1
y = y * scalebig + 160
x = x * scalesmall - 180
GOSUB convert
IF x <= 320 + 120 THEN PSET (x, y), 14 ELSE GOTO ending
'p1 plot
x = iterations: y = p1
y = y * scalebig + 60
x = x * scalesmall - 180
GOSUB convert
IF x < 320 + 120 THEN PSET (x, y), 14
'q2 plot
x = iterations: y = q2
y = y * scalebig - 60
x = x * scalesmall - 180
GOSUB convert
IF x < 320 + 120 THEN PSET (x, y), 4
'p2 plot
x = iterations: y = p2
y = y * scalebig - 160
x = x * scalesmall - 180
GOSUB convert
IF x < 320 + 120 THEN PSET (x, y), 4
'phase portrait
x = q1: y = p1
y = y * (2 * scalebig) + 100
x = x * (2 * scalebig) + 190
Page 31
IF SQR((x - 190) ^ 2) < 100 AND SQR((y - 100) ^ 2) < 100 THEN
GOSUB convert
PSET (x, y), 14
END IF
x = q2: y = p2
y = y * (2 * scalebig) + 100
x = x * (2 * scalebig) + 190
IF SQR((x - 190) ^ 2) < 100 AND SQR((y - 100) ^ 2) < 100 THEN
GOSUB convert
PSET (x, y), 4
END IF
'position portrait
x = q1: y = q2
y = y * (2 * scalebig) - 100
x = x * (2 * scalebig) + 190
IF SQR((x - 190) ^ 2) < 100 AND SQR((y + 100) ^ 2) < 100 THEN
GOSUB convert
PSET (x, y), 9
END IF
FOR x = 1 TO systemdrag: NEXT
iterations = iterations + 1
totaltime = totaltime + dt
LOOP UNTIL INKEY$ = CHR$(27)
ending:
SLEEP
END
convert:
x = x + 320
y = 240 - y
RETURN
drawaxes:
'Axis for q1 plot
COLOR 15
LOCATE 2, 3: PRINT "Generalized"
LOCATE 3, 3: PRINT "Coordinates"
y = 0: y = y * .2 + 160: GOSUB convert
LINE (140, y)-(400, y), 8
COLOR 15: LOCATE 5, 3: PRINT "Position q1(t)"
COLOR 7: LOCATE 6, 3: PRINT "q1(0) ="; q10
'Axis for p1 plot
y = 0: y = y * .2 + 60: GOSUB convert
LINE (140, y)-(400, y), 8
COLOR 15: LOCATE 11, 3: PRINT "Momentum p1(t)"
COLOR 7: LOCATE 12, 3: PRINT "p1(0) ="; p10
'Axis for q2 plot
y = 0: y = y * .2 - 60: GOSUB convert
LINE (140, y)-(400, y), 8
COLOR 15: LOCATE 18, 3: PRINT "Position q2(t)"
COLOR 7: LOCATE 19, 3: PRINT "q2(0) ="; q20
'Axis for p2 plot
y = 0: y = y * .2 - 160: GOSUB convert
LINE (140, y)-(400, y), 8
COLOR 15: LOCATE 25, 3: PRINT "Momentum p2(t)"
COLOR 7: LOCATE 26, 3: PRINT "p2(0) ="; p20
'Axes for q & p plots
COLOR 15
LOCATE 2, 60: PRINT "Phase and"
LOCATE 3, 58: PRINT "Position Plots"
LINE (320 + 190, 240 - 80 - 100)-(320 + 190,
LINE (320 + 190 - 100, 240 - 100)-(320 + 190
LOCATE 4, 66: PRINT "p"
LOCATE 10, 76: PRINT "q"
LINE (320 + 190, 240 + 80 + 100)-(320 + 190,
LINE (320 + 190 - 100, 240 + 100)-(320 + 190
240 + 80 - 100), 7
+ 100, 240 - 100), 7
240 - 80 + 100), 7
+ 100, 240 + 100), 7
Page 32
LOCATE 17, 66: PRINT "q2"
LOCATE 23, 75: PRINT "q1"
RETURN
Page 33