Assignment Ex04
Assignment Ex04
Before you start working on the assignments and before you hand in a solution, read the instructions below.
• You can work on these assignments in groups of up to 3 students. Note, however, that everybody has to
hand in his/her own solution.
• Please personalize your completed script main ex04 ID.py by replacing the handle “ID” by your student-
id. For redundancy, make sure to also include your name and student-id in the completed scripts that you
hand in. We therefore provided three metadata variables
__STUDENT_NAME__ = "YOUR_NAME_HERE"
__STUDENT_ID__ = "YOUR_STUDENT_ID_HERE"
__GROUP_MEMBERS__ = "YOUR_TEAM_HERE"
The computational problem that we will study in this exercise is a classical mechanics problem for which
Newtons second law, i.e. the equation of motion, reads
d2
m x = −kx(1 − αx). (1)
dt2
It describes the motion of a particle with mass m in the anharmonic potential
1 2 2
V (x) = kx 1 − αx , (2)
2 3
see Fig. 1. In Eq. (2), k > 0 is the usual suspension rate and α controls the deviation from the harmonic
oscillator potential. Note that for small displacements x, V (x) is effectively a harmonic oscillator potential. For
larger values of x, the second term in Eq. (2) adds a nonlinear perturbation to the equation of motion. The
right hand side of Eq. (1) is simply the force acting on the particle, given by
d
F (x) = − V (x). (3)
dx
Download the Python script main ex04 ID.py from folder Exercise04. Wade through the script and make
sure you understand it. Get familiar with the fragmented routines that help setting up the solver for the two
coupled ODEs in the two unknowns y (1) and y (2) , reading
d (1)
y = f (1) (t, y (1) , y (2) ), (4)
dt
d (2)
y = f (2) (t, y (1) , y (2) ). (5)
dt
In lecture 5, the rearrangement of the second order differential equation Eq. (1) in terms of two first order
equations of the form of Eqs. (4, 5) was illustrated on slide 24 for the harmonic oscillator potential (α = 0).
Here, for the case of the anharmonic
oscillator potential, the right hand side of Eq. (5) reads f (2) (t, y (1) , y (2) ) =
(1) (1) (1)
F (y ) = −ky 1 − αy /m.
1
2
Figure 1: Potential of the anharmonic oscillator defined by Eq. (2) for α = 0.5 (blue solid line) and α = 0 (green
dashed line).
(a) Activate the function main a(). Consider the limiting case of the harmonic oscillator, i.e. α = 0 in
Eqs. (1,2). Complete and test the Euler forward stepping algorithm for the set of equations (4,5) and
compare your numerical approximation of the position coordinate x(t) to the exact solution xexact (t) for
α = 0.
Hints:
(b) Activate the function main b(), still considering the limiting case α = 0. Assess the scaling behavior
of the endpoint error |x(tmax ) − xexact (tmax )| upon decreasing time increment ∆t for Euler’s forward
stepping algorithm. Which scaling behavior do you expect to find? Is this consistent with your numerical
experiments? Include a brief answer as string variable ANSWER Q1 (If you discuss your solution with one
of tutors this is not required).
(c) Activate the function main c(), still considering the limiting case α = 0. Assess the scaling behavior of
the endpoint error |x(tmax ) − xexact (tmax )| upon decreasing time increment ∆t for the predictor-corrector
method. Which scaling behavior do you expect to find in this case? Is this consistent with your numerical
experiment? Include a brief answer as string variable ANSWER Q1 (If you discuss your solution with one of
the tutors this is not required).
Hints:
(e) Activate the function main e(). This time, you will consider the general case of nonzero α for which no
exact solution is given. In absence of an exact solution, conservation laws are a valuable tool to assess the
correctness of a numerical procedure. In this regard, monitor the trend of the total energy E of the particle
as function of integration time for both numerical schemes. What do you find? Include a brief answer as
string variable ANSWER Q1 (If you discuss your solution with one of the tutors this is not required).
Hints:
– For your numerical experiments feel free to set alpha=1.
m 2
– The total energy at a given instant t in time reads E(t) = 2 v(t) + V (x(t)).