Elementary Diffys
Elementary Diffys
Physics 200
Laboratory
1 of 14
2.1. PHYSICAL PROBLEMS Lecture 2
2 of 14
2.1. PHYSICAL PROBLEMS Lecture 2
Aside from linear problems, there are a variety of forces that we can consider
that are more difficult, and for which only numerical solution will provide
trajectories – consider the following two dimensional example.
Example
ŷ
B = B(r) ẑ
q, m
r = x(t) x̂ + y(t) ŷ
x̂
So we see that adding multiple dimensions can make our problem more
3 of 14
2.1. PHYSICAL PROBLEMS Lecture 2
and each particle has three components to fully determine its motion, for a
total of 3 n “degrees of freedom”.
Example
4 of 14
2.1. PHYSICAL PROBLEMS Lecture 2
Aside from the problems we have discussed already, there is a lot of ad-
ditional physics to be had from second order ODEs – in one-dimension
(either because of intrinsic interest, or because of symmetry reduction),
Schrödinger’s equation governing the quantum mechanical wave-function
ψ(x) can be written as:
~2 d2 ψ(x)
− + V (x) ψ(x) = E ψ(x) (2.10)
2 m dx2
where ~ = 1.05 × 10−34 Js (note its size), m is the mass of the particle,
V (x) is the one-dimensional potential governing the classical motion of the
particle, and E is the energy of the particle. Now the quantum mechanical
interpretation of ψ(x) is in terms of spatial probabilities. In words: “The
probability of finding a particle of mass m, moving under the influence of
V (x), within dx ofR the point x is ψ ∗ (x) ψ(x) dx.” That means, incidentally,
∞
that the integral: −∞ ψ ∗ (x) ψ(x) dx = ?.
Example
5 of 14
2.2. NONDIMENSIONALIZATION Lecture 2
In special relativity, you will learn that the kinetic energy combines with
the “rest energy” (m c2 ), to form a term replacing the kinetic energy
2
in (2.11) that looks like: qm c v2 , so that in special relativity, conserva-
1−
c2
tion of energy reads:
m c2
E=q + U (x). (2.13)
2
1 − vc2
You should check (by Taylor expansion) that this conservation statement
reduces to the usual one when v c. If we differentiate both sides of
this equation with respect to time, we get a relativistically-correct form
of Newton’s second law that reads:
3/2
ẋ2
0
m ẍ = −U 1 − 2 , (2.14)
c
and this can be used to solve problems in which particles move very
quickly (compared to c, which in its usual units is c ≈ 3 × 108 m/s – a
large number). It is also, even for simple U 0 (x), much more difficult to
solve than the usual, classical expression.
2.2 Nondimensionalization
Before we generate the method, let’s think about some actual numbers in
the equations we have set up. On a computer, the smallest number that can
be represented is called “machine epsilon”, and is generally around 10−13
(meaning thirteen digits, you can represent large exponents, like 10−400 ,
but you don’t get to specify all four hundred digits). That means you
have a finite resolution for “0”, and anything smaller than machine epsilon
6 of 14
2.2. NONDIMENSIONALIZATION Lecture 2
d2 G m1 m2 t0 U0 t20
q(s) = − 2 r = − 2 r , (2.15)
ds2 r0 q12 0 q12 0
q
and require that t0 = Ur00 , then our equation of motion becomes:
1
q 00 (s) = − 2 (2.16)
q12
and we have a procedure for re-introducing the dimensions as needed (at the
end). Notice that all quantities are now “of order one”, since q12 is initially
just 1, and therefore q 00 (s), the dimensionless acceleration, is also of order
1 at s = 0. We want a concrete, dimensionless way to talk about small
numbers, and in this case, we know that q(s) 1 is small, and q(s) 1
7 of 14
2.3. THE VERLET METHOD Lecture 2
is large. If we did not form these ratios from the start, our work would
be plagued by peanut gallery questions of the form: “Is one meter large or
small?”.
The key observation is that, in the vicinity of t, the value of x(t + ∆t) (for
small ∆t2 ) can be estimated to arbitrary accuracy by Taylor expansion:
1 1 ... 1 ....
x(t + ∆t) = x(t) + ẋ(t) ∆t + ẍ(t) ∆t2 + x (t) ∆t3 + x (t) ∆t4 + . . . ,
2 6 24
(2.17)
and similarly for x(t − ∆t) (just swap the sign of all odd ∆t terms):
1 1 ... 1 ....
x(t − ∆t) = x(t) − ẋ(t) ∆t + ẍ(t) ∆t2 − x (t) ∆t3 + x (t) ∆t4 + . . . ,
2 6 24
(2.18)
and then adding these two together gives:
1 ....
x(t + ∆t) + x(t − ∆t) = 2 x(t) + ẍ(t) ∆t2 + x (t) ∆t4 . (2.19)
12
From Newton’s second law, we know that ẍ(t) is given, that’s just F (t)/m,
so that we could write this equation (once a force has been provided) as
F (t) 2
x(t + ∆t) = 2 x(t) − x(t − ∆t) + ∆t + O(∆t4 ). (2.20)
m
Here, we use O(∆t4 ) to indicate that the next order corrective term scales
like ∆t4 . How might we use this observation? Well, suppose we had a value
for position at times t and t − ∆t, and we knew the force at time t, then
we could estimate (very well) the position at time t + ∆t. Given a pair of
starting positions, we could even chain together successive estimates.
2
Small compared to what?
8 of 14
2.3. THE VERLET METHOD Lecture 2
2.3.2 Grid
2.3.3 Method
There is a slightly subtle point, and I don’t want to make too much of it
beyond mentioning it – given some sort of starting values and a force, we
can march a sequence of xj forward in “time” (i.e. on the temporal grid),
and while we will refer to that solution as the set {xj }N j=1 , how do these
values compare to the projection of the true solution (which we don’t even
have, in most cases), which is also denoted {xj }N j=1 – this is a subtle and
tricky question, requiring careful analysis on a case-by-case basis – its answer
depends both on the force, and the type of numerical method we have in
mind. As I say, though, it is a problem for later on.
Now, given two “initial values”, x−1 and x0 , and a continuous function,
the force, F (t) (and remember, F (t) is shorthand for F (x, t)), we have the
following algorithm:
for j = 0, j ≤ N − 1, j = j + 1
F
xj+1 = 2 xj − xj−1 + mj ∆t2 (2.22)
end
This will do it, as long as we understand Fj ≡ F (xj , tj ), so that we evaluate
the force at a known value of x (remember, coming into each step of the
loop, we have access to all position approximations up to and including xj ).
9 of 14
2.3. THE VERLET METHOD Lecture 2
The only issue to work out is the initial conditions – the most typical physical
specification is x(0) and v(0), the initial position and velocity. How do we
turn this into values for x(−∆t) and x(0)? The easy one is x0 = x(0), and
for v(0), think of a grid approximation to v(0):
x0 − x−1
v0 = −→ x−1 = x0 − ∆t v0 . (2.23)
∆t
This setup will work, and we can use the equality on the left to generate
x −x
values of vj = j ∆tj−1 if our force depends on the velocity at time level
j. The initial condition is sub-optimal, since we are using a less accurate
approximation to the velocity than our approximation to the acceleration
(see (2.19)), but again, pragmatism is our guide – after all, we only make
this inaccurate approximation once3 .
2.3.4 Testing
We have a method, and we will check it against the exact solutions that we
can generate4 . But what should we do for numerical solutions that have no
corresponding x(t)? That will, presumably, be the primary utility of the
Verlet integrator – what guiding principles can we use to ensure that the
method works, and the results are physically relevant?
For conservative systems, forces derivable from a potential, one good check
is energy conservation. We construct, at each time level, the energy:
xj+1 − xj−1 2
1
Ej = m + U (xj ), (2.24)
2 2 ∆t
and we can track this quantity (which should be constant). Note that we are
using a more accurate approximation to the speed in this expression, that’s
to keep the energy value itself accurate. The gross behavior of this quantity
should be relatively constant, at the very least, bounded. If it is not, that
could be an indication that, for example, the time step is too large.
3
But don’t say I didn’t warn you. It is possible to make a more accurate initial
approximation, I’ll leave that to you.
4
To ensure that it is correctly implemented.
10 of 14
2.3. THE VERLET METHOD Lecture 2
Lab
In this lab, we will solve a few different ODEs numerically – the first problem
ensures that your solver is working correctly – check with the lab instructor
early to verify that the solver is correct. Use the spaces provided to answer any
questions, and make any relevant observations.
Problem 2.1
For the simple oscillator, take ω = 2 π 1/s, and solve ẍ = −ω 2 x with x(0) = 1,
ẋ(0) = 0. Use a time step of ∆t = 1/100 s, and plot your result together with
the correct answer for t = 0 −→ 1 s (have your instructor check this plot).
Using m = 1 kg, calculate the energy at each point, and compute the following
measure of error:
max(Ej ) − min(Ej )
∆E = (2.25)
E
where max/min(Ej ) refers to the maximum/minimum numerical value of the
energy (over a 1 s inteval), and E is the theoretical energy (compute it sepa-
rately, and write its value below)
Problem 2.2
For a particle in two dimensions, we need a Verlet solver for x and y sepa-
rately. Write one that takes a force function, and returns a list of the form
{{x1 , y1 }, {x2 , y2 }, . . . , {xN , yN }}.
11 of 14
2.3. THE VERLET METHOD Lecture 2
12 of 14
2.3. THE VERLET METHOD Lecture 2
Problem 2.3
Using the conversion between {x, y, z} and {r, θ, φ}, make a table of particle
locations placed on a sphere of radius r = 1 – use a step size of ∆θ = π/20,
and ∆φ = 2π/10. Omit the particles at θ = 0, π, and take φ = 2 π, but not
zero (otherwise, you’re putting two particles at the same location, and that’s
a Coulomb’s law no-no). Use the provided function ViewParticles to ensure
that your particles are correctly located on a sphere. How many particles are
there?
Problem 2.4
The particles in your sphere will interact electrically according to the potential:
U = 4 πq10q2r12 . Write a function Force that takes as input the list of particles
PList, and outputs a table of the three-dimensional forces felt by each particle.
Using 0 = 1, and q = 1 C for all charges, use your configuration from the
previous problem to find the force on particle number 14 (write the vector
position of particle 14 as well):
13 of 14
2.3. THE VERLET METHOD Lecture 2
Problem 2.5
Put it all together, write a Verlet routine that loops through a list of particles,
updating each one’s location – use 0 = 1, m = 1 kg, q = 1 C for all particles,
and a time step ∆t = 1/100. For output, (call it output) give a table of
position tables (so that output[[1]] returns a table of particle positions for
t = ∆t). Use the provided function ViewParticles to generate a movie of
the motion and get your lab instructor to take a look. Roughly how many time
steps does it take for the sphere’s radius to double?
14 of 14