Comp Physics With Worked Examples
Comp Physics With Worked Examples
Computational Physics
Also of Interest
Computational Physics. Mit Beispielen in Fortran und Matlab
Michael Bestehorn, 2016
ISBN 978-3-11-037288-5, e-ISBN (PDF) 978-3-11-037303-5,
e-ISBN (EPUB) 978-3-11-037304-2
Computational Sciences
Ponnadurai Ramasami (Ed.), 2017
ISBN 978-3-11-046536-5, e-ISBN (PDF) 978-3-11-046721-5,
e-ISBN (EPUB) 978-3-11-046548-8
Michael Bestehorn
Computational
Physics
|
With Worked Out Examples in FORTRAN® and MATLAB®
Physics and Astronomy Classification Scheme 2010
05.10.Ln, 05.45.-a, 05.65.+b, 07.05.Mh, 44.05.+e, 45.10.-b, 47.11.-j, 47.85.-g
Author
Prof. Dr. Michael Bestehorn
BTU Cottbus-Senftenberg
Dept. of Statistical Physics and Nonlinear Dynamics
Erich-Weinert-Str. 1
03046 Cottbus
Germany
bestehorn@b-tu.de
ISBN 978-3-11-051513-8
e-ISBN (PDF) 978-3-11-051514-5
e-ISBN (EPUB) 978-3-11-051521-3
www.degruyter.com
Contents
1 Introduction | 1
1.1 Goal, contents, and outline | 1
1.2 The environment required for program development | 4
1.2.1 Operating system | 4
1.2.2 Software packages | 5
1.2.3 Graphics | 5
1.2.4 Program development and a simple script | 6
1.3 A first example – the logistic map | 7
1.3.1 Map | 7
1.3.2 FORTRAN | 8
1.3.3 Problems | 11
2 Nonlinear maps | 12
2.1 Frenkel–Kotorova model | 12
2.1.1 Classical formulation | 12
2.1.2 Equilibrium solutions | 13
2.1.3 The standard map | 13
2.1.4 Problems | 14
2.2 Chaos and Lyapunov exponents | 15
2.2.1 Stability, butterfly effect, and chaos | 15
2.2.2 Lyapunov exponent of the logistic map | 16
2.2.3 Lyapunov exponents for multidimensional maps | 17
2.3 Affine maps and fractals | 20
2.3.1 Sierpinski triangle | 22
2.3.2 About ferns and other plants | 23
2.3.3 Problems | 24
2.4 Fractal dimension | 25
2.4.1 Box-counting | 25
2.4.2 Application: Sierpinski triangle | 26
2.4.3 Problem | 27
2.5 Neural networks | 27
2.5.1 Perceptron | 28
2.5.2 Self-organized maps: Kohonen’s model | 34
2.5.3 Problems | 39
3 Dynamical systems | 40
3.1 Quasilinear differential equations | 40
3.1.1 Example: logistic map and logistic ODE | 41
3.1.2 Problems | 42
VI | Contents
Index | 317
1 Introduction
1.1 Goal, contents, and outline
The present text tries to show, by means of examples coming from different corners
of physics, how physical and mathematical questions can be answered using a com-
puter. Nowadays, theoretical physicists are mainly concerned with two subjects: one
is the devising of models, normally in the form of differential equations, ordinary or
partial, while the other one is their approximate solution, normally with the help of
larger or smaller computers. In a certain way, computational physics can be seen as
the link between theory and experiment. The often involved equations need a numeri-
cal treatment, usually in connection with certain simplifications and approximations.
Once the code is written, the experimental part begins. A computer on which, for in-
stance, a turbulent pipe flow is simulated, can to some extent be regarded as a test
station with easy access to output values such as flow rates, velocities, temperatures,
and also to input parameters like material constants or geometric boundary condi-
tions.
Problems from classical mechanics normally rely on ordinary differential equa-
tions, while those of electrodynamics, quantum mechanics, continuum mechanics,
or hydrodynamics are formulated by partial differential equations, which are often
nonlinear.
This is neither a numeric book, nor a tutorial for a special computer language for
which we refer to the literature [1]. On the other hand, most of the discussed algorithms
are realized in FORTRAN. FORTRAN is an acronym composed of FORmula TRANslator.
This already indicates that it is more appropriate and convenient for solving problems
originating from theoretical physics or applied mathematics, like managing complex
numbers or solving differential equations.
During the past 10 years, the software package MATLAB has enjoyed more and
more popularity in research as well as in teaching [2]. The notion is formed as another
acronym from MATrix LABoratory. Thus MATLAB shows its strengths in the interac-
tive treatment of problems resulting from vector or matrix calculus, but other prob-
lems related to differential equations can also be tackled. Programming is similar to
FORTRAN and for beginners, many things are easier to implement and to handle. In
addition, MATLAB captivates with its comfortable and convenient graphic output fea-
tures.
MATLAB is devised as a standalone system. It runs under Windows and Linux. No
additional text editor, compiler, or software libraries are needed. However, contrary
to FORTRAN, a MATLAB code once written is not compiled to an effective machine
code but rather interpreted line by line. Processes may thus become incredibly slow.
MATLAB may have some advantages in program development and testing, but if in the
end a fast and effective code is desired (which should usually be the case), a compiler
https://doi.org/10.1515/9783110515145-001
2 | 1 Introduction
–2
–2 0 2
Fig. 1.1: Time evolution of low-dimensional systems from Chapter 4. Left: two-planet problem with
gravitational interaction. The orbit of the inner planet (red) is unstable and the planet is thrown out
of the system. Right: deterministic chaos for the driven pendulum, Poincaré section.
1.1 Goal, contents, and outline | 3
0.8
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1
Fig. 1.2: Numerical solutions of field equations, see Chapter 7. Left: time-dependent Schrödinger
equation, probability density, and center of mass of an electron in a constant magnetic field.
Right: Hydrodynamic vortex for the driven cavity.
central role. For three dimensions and more (or better: degrees of freedom), chaotic
behavior becomes possible, if not the rule. Large parts of Chapters 2-4 are dedicated
to the so-called deterministic chaos.
Starting with Chapter 5 high-dimensional (or infinite-dimensional) systems come
into the focus, normally described by field theories in the form of partial differential
equations. These can be linear as is very often seen in quantum mechanics or electro-
dynamics, but also nonlinear as in hydrodynamics (Figure 1.2) or in diffusion-driven
macroscopic pattern formation (Figure 1.3). Caused by nonlinearities, patterns may
emerge on most diverse spatio-temporal scales, the dynamics becoming chaotic or
turbulent (Figure 1.4).
Fig. 1.5: Monte Carlo simulation of a gas comprised of 1000 particles with hardcore rejection and
long range attraction from Chapter 8. Temperature decreases from left to right, and a phase transi-
tion in a condensed state can be detected.
Another chapter is devoted to Monte Carlo methods. Here, randomness plays a key
role in the determination of equilibrium states. Using Monte Carlo simulations, phase
transitions can be studied without resorting to differential equations (Figure 1.5). The
application on the Ising model of spatially arranged spins is a prominent example.
We shall discuss programs mainly written in FORTRAN, but also in MATLAB. MATLAB
is conceived as its own environment, where codes can be written, developed, and
run without leaving the MATLAB application. The operating system of the perform-
ing computer plays a minor role, so Windows can be used as well. On the other hand,
writing and developing FORTRAN codes is quite different. One needs a compiler, a
1.2 The environment required for program development | 5
text editor, and a convenient file system. For more ambitious applications, software
libraries like LAPACK should be at hand. Also a graphic library is important to have
at least the possibility to plot results in a pleasant and appealing way. If one wants
to have all these possibilities preferably free of charge, the only possibility is to do it
under Linux.
Thus, we assume the reader has a Linux operating system running where GNU
FORTRAN 95 is installed, together with the important libraries. A certain code written
with a text editor, e.g., emacs or xemacs, can be compiled via
$ gfortran program.f
$ ./a.out
This of course is the most simple case where no further libraries are involved.
Besides a compiler, e.g., gfortran from GNU, we shall need external routines to solve
standard problems, mainly from the LAPACK-Library (Linear Algebra PACKage).
LAPACK can be also installed for free via the internet [4]. If the source code resorts to
LAPACK routines, one should use the compiler options -l and -L:
The option -L/. . . points to the path where the following library is located on the com-
puter.
1.2.3 Graphics
For graphic output we employ the package PGPLOT [5]. All figures in this first chapter
and most of the book are generated with PGPLOT. Of course the reader can use other
packages if available, but PGPLOT provides all necessary basic tools and is also free of
charge. The compiler options for a source that relies both on LAPACK and GNUPLOT
should look like this:
In (1), an ASCII file is generated using a text editor. This file is the source and usually
has the extension .f, say, name.f. The editor is invoked, e.g., emacs by
$ emacs name.f
After finishing the first round of editing the source file, compiling and possible linking
with libraries (2) can be achieved by a script file
Let us call the script containing the above line ’make_f95’. Before executing the file, it
must receive the attribute executable, which is done by
$ ./make_f95 name
initializes the variable $1 with name. Further options (optimization, etc.) of the
FORTRAN compiler can be found in the built-in manual by
$ man gfortran
The option -o transfers the name in $1 to the created binary executable, instead of
calling it a.out (default).
(3) If the compiler passes without error messages, one finds in the working directory
a binary file, here name, that can simply be executed with
$ ./name
1.3 A first example – the logistic map | 7
1.3.1 Map
To inspire the reader a bit, we conclude this chapter with a numerically very simple
example. We study the map
which is known as the logistic map. In this way we can also demonstrate the usage of
the graphic package PGPLOT.
The recursion rule (1.1) can be considered a simple model of the temporal evolu-
tion of a certain population if x n denotes the population density at time (in the year)
n. The term ax n alone leads to an exponential increase if a > 1, otherwise leading to
the extinction of the species. For a > 1, the nonlinearity −ax2n restricts the growth due
to lack of resources (limited foods) and leads to a saturation. The constraint 0 ≤ a ≤ 4
originates from the condition 0 ≤ x n ≤ 1 for all x n . Depending on a, we have one or
two stationary solutions, namely
(1) (2)
xs = 0 for all a, xs = 1 − 1/a for 1<a≤4, (1.2)
a<1, a>3.
8 | 1 Introduction
The first one is excluded by (1.2). What happens for a > 3? The computer solutions
introduced below show a periodic behavior, (Figure 1.6)
or
xp1 = f(f(xp1 )) , xp2 = f(f(xp2 )) .
Applying again a linear stability analysis shows that the periodic solution becomes
unstable for a > 1 + √6 and a more complex periodic cycle where x n alters now be-
tween four values arises (Problems).
1.3.2 FORTRAN
Numerically we can study the logistic map with the following code
PROGRAM logist
REAL*8 :: a,x,amin,amax ! double precision (8 bytes)
C region for a
amin=2.8; amax=4.
c initialize graphics (pgplot)
CALL INIT(SNGL(amin),SNGL(amax),0.,1.,7.,1.,1)
itmax=200 ! number of iterations for each a
ivor=1000 ! number of hidden iterations before plotting
tiny=1.E-6 ! initial value for x
da=(amax-amin)/1000. ! step width for a
c loop for 1000 a values
DO a=amin,amax,da
C logistic map
x=tiny; ic=0 ! x0
DO it=1,itmax+ivor
x=a*x*(1.-x)
IF(it > ivor) THEN
c after pre-iter. plot a pixel at (a,x) with color ic
ic=MOD(ic,15)+1; CALL PGSCI(ic)
CALL PGPT(1,SNGL(a),SNGL(x),-1)
ENDIF
ENDDO
ENDDO
1.3 A first example – the logistic map | 9
1
x
0.8
0.6
0.4
0.2
Fig. 1.6: Logistic map, period doublings, and
a (2)
chaos. The stationary solution xs (bold) be-
0
3 3.5 4 comes unstable for a > 3.
Compiling and executing creates a figure like Figure 1.6 on the screen.
The subroutine init comprises PGPLOT calls for initializing the graphic screen. It
is described in more detail in Appendix B.
A quick glance at the program shows that the implicit type declarations of
FORTRAN have been utilized. That means it is not necessary to declare variables
in the header of each routine if they are real or integer scalar quantities. Each variable
beginning with a letter from a to h and then from o to z is defined real (single preci-
sion) as default, while all variables beginning with i to n are integers (4 bytes). On
the other hand you can often read in FORTRAN guides (normally written by mathe-
maticians or computer scientists) sentences like we advise strongly against using type
conventions in FORTRAN. Of course the usage of default declarations seems to be a bit
10 | 1 Introduction
sloppy but it saves a lot of typing and going back and forth while writing a program.
Those who do not like this way can put the statement
IMPLICIT NONE
in the first line of each routine and switch off the implicit declarations (there are also
compiler options that effect the same). However, each variable has to then be defined
explicitly.
1.3.2.1 MATLAB
The same code can be written in MATLAB. The syntax is very similar to FORTRAN
but easier to write. The graphics calls are different. A code that produces the same
Figure 1.6 is shown here:
clear;
amin=2.8; amax=4.0;
itmax=200; ivor=1000; tiny=1.e-6;y=zeros(1,imax);xx=zeros(1,imax);
da=(amax-amin)/1000;
for a=2.8:da:4.0
x=tiny;
for i=1:itmax+ivor;
x=a*x*(1-x);
if i>ivor
y(i-ivor)=x; xx(i-ivor)=a; % to save CPU time it is essential to
end % store the x-values for each a and
end % then plot them all together
plot(xx,y,'.');
end
However, execution time in MATLAB is normally much longer than in a compiler lan-
guage. To demonstrate this, we remove all graphic output and compare the two codes,
first in MATLAB:
clear; t=cputime;
itmax=100000000; ivor=itmax; y=zeros(1,imax);
a=3.95; x=0.01;
for i=1:ivor+itmax
x=a*x*(1-x);
if i>ivor
y(i-ivor)=x;
end
end
cputime-t % prints the CPU time used
Bibliography | 11
then in FORTRAN
REAL*8 :: a,x,y(100000000)
common y ! outwit the FORTRAN optimizer!
itmax=100000000; ivor=itmax
a=3.95; x=0.01
DO it=1,itmax+ivor
x=a*x*(1.-x)
IF(it.gt.ivor) THEN
y(it-ivor)=x
ENDIF
ENDDO
CALL CPU_TIME(s)
WRITE(6,*) s
END
Both codes are running on an HP ProDesk 400 G3 MT, the MATLAB code under
Windows 7 Professional, the FORTRAN code under Linux using GNU-FORTRAN 95.
MATLAB needs about 3 seconds for the 20×106 iterations. If the optimizer in FORTRAN
is turned off (-O0), FORTRAN takes 0.95 seconds. On the first optimization level (-O1),
we get 0.65 seconds, using the second up to the fourth we find 0.6 seconds. Starting
with -O2, it is necessary to outflank the FORTRAN optimizer and to write the y-array
into a dummy COMMON-block. Otherwise gfortran would recognize the computed
quantities inside the iteration loop are not used further and would just skip the loop
completely.
1.3.3 Problems
And to code: Change the code for the logistic map to scale up certain regions in the
x-a plane. The regions could be defined using the mouse cursor.
Bibliography
[1] S. J. Chapman, FORTRAN 95/2003 for Scientists and Engineers, McGraw Hill Book Co. (2007).
[2] Matlab – Mathworks, http://mathworks.com/products/matlab/
[3] Maplesoft – Mathworks, http://www.maplesoft.com/solutions/education/
[4] LAPACK – Linear Algebra PACKage – Netlib, www.netlib.org/lapack/
[5] T. J. Pearson, Guide to the graphics package PGPLOT, Caltech, USA:
http://www.astro.caltech.edu/~tjp/pgplot/old_manual.ps.gz
2 Nonlinear maps
In this chapter we continue with recursion formulas where, starting from an initial
(set of) number(s), all subsequent values of one (ore more) variable(s) follow in a
unique and deterministic way.
As a simple model of a solid body in an externally given, periodic potential V(x) with
we examine a one-dimensional chain of N mass points, each with mass m. The mass
points are connected with chains having the spring rate D = 1 and the equilibrium
length zero (Figure 2.1). They are located at x n and have the momentum p n . The Hamil-
ton function reads:
N
p2n 1
H(x n , p n ) = ∑ [ + V(x n ) + (x n − x n−1 )2 ] . (2.2)
n=1
2m 2
To state the dynamic problem one may write up the canonical equations
∂H ∂H
ṗ n = − , ẋ n = (2.3)
∂x n ∂p n
V(x)
y2 y3 D D
x1 x2 x3 xN x
https://doi.org/10.1515/9783110515145-002
2.1 Frenkel–Kotorova model | 13
We shall come back in detail to problems like (2.3) in the next chapters. Here we con-
centrate only on steady configurations of the chain where ṗ n = 0, ẋ n = 0, p n = 0.
From (2.3) follows the equilibrium condition
∂H
=0 (2.4)
∂x n
or
V (x n ) + (x n − x n−1 ) − (x n+1 − x n ) = 0 , (2.5)
where the prime denotes the derivative. We define the reciprocal density at location x n
y n ≡ x n − x n−1 (2.6)
y n+1 = y n + V (x n )
(2.7)
x n+1 = x n + y n+1 = x n + y n + V (x n ) .
From a certain initial pair (x0 , y0 ) the whole series (x n , y n ) is uniquely determined.
Of course nothing is said about the stability of these solutions. At this stage we only
know that they are at equilibrium where the net force on each mass point vanishes.
Due to (2.4), the potential energy has an extremum, but this might be a maximum as
well.
K
V(x) = cos(2πx) (2.8)
(2π)2
PROGRAM circle_map
REAL*8 :: x,y,pi2,vor
CHARACTER*1 :: c
INTEGER :: pgcurs
pi2=4.*ASIN(1.D0) ! 2*Pi
amp=1. ! value of K
imax=10000 ! number of iterations for each initial value
CALL INIT(0.,1.,0.,0.5,10.,0.5,1)
ncol=15 ! use 15 colors
DO
k=pgcurs(x0,y0,c) ! mouse query
x=x0; y=y0 ! initial values
ic=mod(ic,ncol)+1; CALL PGSCI(ic)
DO i=1,imax
y=y-amp/pi2*SIN(pi2*x); x=x+y ! circle map
xp=MOD(x,1.); yp=MOD(y,1.) ! plot modulo 1
CALL PGPNTS(1,xp,yp,-1,1)
ENDDO
if(ICHAR(c).eq.32) EXIT
ENDDO
CALL PGEND
END
For each initial value, 10 000 points are plotted. The initial pair is determined using
the mouse. The map is periodic in y → y ± m, x → x ± m with integers m, m and is
symmetric with respect to the origin. Therefore it is sufficient to take the initial values
from the region
0 ≤ x ≤ 1 , 0 ≤ y ≤ 1/2 .
Two fixed points x n+1 = x n , y n+1 = y n exist. At x, y = 0 we have a center, and x = 1/2,
y = 0 is called saddle point (see Chapter 3). Figure 2.2 shows several series for K = 1.
2.1.4 Problems
1. Examine (2.9) for different K. For K = 0 you will not need your computer.
2. Plot the chain length for fixed x0 as a function of y0 . Try different values for x0 .
2.2 Chaos and Lyapunov exponents | 15
As already known from the discussion of the logistic map in Section 1.3, there exist
regular (periodic or quasiperiodic) and chaotic regimes if the control parameters or, at
least for the Standard map, the initial conditions are changed. Instead of only looking
qualitatively at the patterns of the iteration maps, we shall now derive a more quanti-
tative measure for chaos.
Let us turn again to the logistic map (1.1). Prevenient to the chaotic regime exists a
cascade of period doublings where the relative distance of doubling or bifurcation
points decreases with increasing a. The first few bifurcation points can be computed
analytically, but the effort required increases quickly. Therefore it is desirable to find
a quantity that reflects the stability of a series for any arbitrary a.
Butterfly effect: What do we mean by stability? A descriptive definition of chaos is
given by the development of some tiny disturbances of variables and/or parameters:
if an (infinitesimally) small cause, namely a perturbation of i.e., the initial value
y0 = x0 + ϵ
after a certain time (here: number of iterations) is amplified to a finite and measur-
able outcome, a completely different series y n may result. Then the series starting
16 | 2 Nonlinear maps
at x0 is called unstable. A butterfly flaps its wings and perturbs the atmosphere very
slightly. Provided sufficiently unstable weather conditions, this ‘butterfly effect’ may
completely change the further development of the weather after a certain amount of
time.
Thus we are looking for a criterion that describes the divergence of two initially in-
finitesimally close series x n and y n if n ≫ 1. Let us start the first iteration with x0 .
Then we have for x n
x n = f(f(f(. . .f(x0 ) . . . ))) ≡ f (n) (x0 ) , (2.10)
where f (n) denotes the nth iterate of f . In parallel, a second series y1 , y2 . . .y n is com-
puted for a closely nearby initial value x0 + ϵ, |ϵ| ≪ 1 and reads
To see if the two series are receding from each other, we compute their distance at each
n and find with ϵ → 0
f (n) (x0 + ϵ) − f (n) (x0 )
d n = |x n − y n | = ϵ = lim ϵ d f (n) (x) .
ϵ→0
(2.12)
ϵ dx x0
If we assume that this distance increases (unstable) or decreases (stable) exponen-
tially with n,
d n = d0 eλn = |ϵ| eλn , (2.13)
the series is unstable if λ > 0, stable if λ < 0. With (2.12) we obtain from (2.13)
1 d (n)
λ = lim ln f (x) , (2.14)
n→∞ n dx x0
where λ is called the Lyapunov exponent¹. For the evaluation of (2.14) the chain rule
must be applied
d (n)
f (x) = d x f(x0 )d x f(x1 ). . .d x f(x n )
dx x0
leading finally to
1 n d
λ = lim ∑ ln f(x) . (2.15)
n→∞ n dx x=x k
k=0
This relation is easy to code. Of course it is not possible to take infinite n, one should
choose a sufficiently large n, say 1000, to find a convergent result. Based on the code
logist from Chapter 1, the program could look like this:
chaos
periodic windows
Fig. 2.3: Lyapunov exponent of the logistic map. The chaotic regime commences at about a ≈ 3.55
and λ > 0. Inside the chaotic regime, periodic windows of different size persist.
PROGRAM lyapunov
REAL*8 :: a,x,flyap
....
DO it=1,itmax+ivor ! iteration loop
x=a*x*(1.-x) ! Logistic map
IF(it.GT.ivor.AND.ABS(x-.5).GT.1.E-30)
* fly=fly+LOG(ABS(a*(1.-2.*x))) ! sum for Lyap. exp.
ENDDO
flyap=flyap/FLOAT(itmax) ! Lyapunov exponent
.... plot flyap as function of a ...
Figure 2.3 shows the Lyapunov exponent over the control parameter a. One finds neg-
ative λ for the fixed points and for the periodic series, they are stable. But in the chaotic
regions, the Lyapunov exponent turns out to be positive. At the bifurcation points
a = a k , λ vanishes, since the 2k−1 -periodic cycle gets unstable at a k and gives way
to the 2k -periodic solution, which then becomes stable from a > a k through a = a k+1 .
results. Knowing the N eigenvalues σ i we may finally compute the N Lyapunov expo-
nents
1
λ i = lim ln σ i . (2.16)
n→∞ n
The Jacobi matrix of the nth iterate can be written as a product of the simple Jacobi
matrices:
L (n) (x⃗ 0 ) = L(x⃗ n ) L(x⃗ n−1 ) . . . L(x⃗ 0 ) . (2.17)
1 − K cos(2πx) 1
L(x)⃗ = ( ) , x⃗ = (x, y)
−K cos(2πx) 1
det L = 1
Case (i) belongs to an unstable series (saddle point, see Chapter 3), case (ii) denotes a
stable one (center).
How can we compute the Lyapunov exponents in practice? To achieve a conver-
gent outcome, one should do at least a few thousand iterations and the product (2.17)
will accordingly include as many matrix multiplications. In the chaotic regime where
the series diverge, an overflow error is unavoidable due to the exponential growth with
n. On the other hand, the relation (2.17) is linear in x⃗ 0 and L can be normalized after
each iteration. If we choose the maximum norm
1
L(̄ x⃗ i ) = L(x⃗ i ) with s i = max(|L jk (x⃗ i )|) ,
si jk
2.2 Chaos and Lyapunov exponents | 19
the product
(n)
L̄ (x⃗ 0 ) = L(̄ x⃗ n ) L(̄ x⃗ n−1 ) . . . L(̄ x⃗ 0 ) (2.18)
will not diverge anymore but differs from (2.17) in a possibly rather large factor
n
s = ∏ si .
i=0
The eigenvalues will then differ in the same factor and instead of (2.16) we obtain
n
1 1
λ i = lim (ln σ̄ i + ln s) = lim (ln σ̄ i + ∑ ln s k ) . (2.19)
n→∞ n n→∞ n
k
All we have to do is to sum up ln s k during the iteration which will not lead to an
overflow due to the logarithm. The code section computing λ in connection with the
program circle_map could look like this:
REAL*8 :: x,y,bs,s,sp,det,amp,fm1(2,2)
complex xl1,xl2
....
x=x0; y=y0 ! init. values for iteration
fm1=fm(pi2*x,amp) ! Jacobi matrix, defined as function below
bs=MAXVAL(ABS(fm1)) ! maximum norm
fm1=fm1/bs ! normalization
s=LOG(bs) ! norm to s
DO i=1,imax ! iteration loop
y=y-amp/pi2*SIN(pi2*x)
x=x+y
c recursive matrix multiplication
fm1=MATMUL(fm(pi2*x,amp),fm1)
bs=MAXVAL(ABS(fm1))
fm1=fm1/bs
s=s+LOG(bs)
ENDDO
c compute eigenvalues of fm1
det=(fm1(1,1)*fm1(2,2)-fm1(1,2)*fm1(2,1))
sp=fm1(1,1)+fm1(2,2)
xl1=(log(.5*(sp+csqrt(cmplx(sp**2-4.*det,0.))))+s)
xl2=(log(.5*(sp-csqrt(cmplx(sp**2-4.*det,0.))))+s)
.. plot result
20 | 2 Nonlinear maps
c Jacobi matrix
CONTAINS ! makes function fm visible in MAIN
FUNCTION fm(x,amp)
REAL*8 :: fm(2,2),x,amp
fm(1,1)=1.-amp*COS(x)
fm(1,2)=1.
fm(2,1)=-amp*COS(x)
fm(2,2)=1.
END FUNCTION fm
END
If this section is integrated into a double loop over the initial values x0 , y0 , we can
scan the whole plane with a certain resolution. The largest Lyapunov exponent, i.e.,
the maximum of the real parts of xl1, xl2 are then stored in a two-dimensional array and
finally contour lines or a colored bitmap can be plotted. This can be done using the
routine image, which is based on the PGPLOT routine PGPIXL and explained in detail
in Appendix B. The colors can be initialized using the routine ccircl (Appendix B):
Figure 2.4 shows the color-coded largest Lyapunov exponent for three different values
of K with a resolution of 500 × 500. Blue regions correspond to a regular, nonchaotic
series, and all other colors reveal a positive Lyapunov exponent and denote chaotic
behavior. The complete code can be found on the book’s website [2].
translation: q⃗ = q⃗ + a⃗
rotation: q⃗ = L R q⃗
scaling and shear: q⃗ = L S q⃗ .
q⃗ = (x, y) ,
cos θ − sin θ
LR = ( )
sin θ cos θ
2.3 Affine maps and fractals | 21
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.5
0.4
A = Det(L S ) A = s x s y A .
q⃗ n+1 = L R L S q⃗ n + a⃗ , (2.21)
CALL RANDOM_NUMBER(x)
we activate the random number generator. If x is a scalar it contains after the call an
equally distributed random number in the interval
0≤x<1
(for more details on random numbers see Section 8.1.1). A possible construction rule
for the Sierpinski triangle reads [3]:
1. Define a triangle by its corners (a1 , b 1 ), (a2 , b 2 ), (a3 , b 3 ).
2. Choose an arbitrary (random) point inside the triangle.
3. Choose an arbitrary (random) number i = 1, 2, 3 (equally distributed).
4. Place a point in the middle of (x, y) and (a i , b i ).
5. Go to 3 and take the point computed in 4 as the new point (x, y).
self-similar, as each arbitrarily chosen subtriangle has the same shape. The plane is
almost empty, and each triangle has infinitely many holes on all length scales (if the
numbers of iterations would be infinite). This property is called a fractal.
At least down to a certain length scale, many objects encountered in nature show a
fractal structure (we refer to the book of B. Mandelbrot, The Fractal Geometry of Na-
ture, [4]). The English mathematician Michael Barnsley proposed in 1985 a map to
construct ferns, and since then these objects have been called Barnsley ferns [5]. Also
here, randomness plays a crucial role. The map reads
where
0 0 −0.139 0.263
L1 = ( ) , L2 = ( ) ,
0 0.27 0.246 0.224
(2.24)
0.17 −0.215 0.781 0.034
L3 = ( ) , L4 = ( )
0.222 0.176 −0.032 0.739
and
0.5 0.57 0.408 0.1075
a⃗ 1 = ( ), a⃗ 2 = ( ), a⃗ 3 = ( ), a⃗ 4 = ( ).
0 −0.036 0.0893 0.27
The selection of i is random between 1 and 4, not equally distributed but with the
probability
P(i) = (0.02, 0.15, 0.13, 0.7) .
24 | 2 Nonlinear maps
Fig. 2.6: Left: Barnsley fern after (2.24), right: a fractal tree, created with (2.25).
The result after 30.000 iterations is shown in Figure 2.6 on the left. Another iteration
rule creates a tree, as shown in Figure 2.6 on the right. Here we take
and
0 0 0 0 0 0
a⃗ 1 = ( ) , a⃗ 2 = ( ) , a⃗ 3 = ( ) , a⃗ 4 = ( ) , a⃗ 5 = ( ) , a⃗ 6 = ( ) .
0 1 0.6 1.1 1 0.7
2.3.3 Problems
Fig. 2.7: Box-counting method. To compute the (fractal) dimension of an object, one counts the
squares needed to cover it completely. If the side length of the squares is halved one needs about
twice as much if the object is a line and has a dimension of 1.
2.4.1 Box-counting
Based on the Euclidean concept of dimension (point = 0, line = 1, plane = 2, etc.) we can
assign a fractal dimension to a fractal object. We shall use the so-called box-counting
method. Let the object whose dimension should be computed lay on the unit square
E, e.g., a line as in the example of Figure 2.7. We divide E into N × N equal squares
with side length L = 1/N. For a given L let M be the number of squares visited by the
object. If L is halved (the number of total squares in E is quadrupled) we should find
about 2M instead of M. Thus we have the relation
M ∼ L−1 (2.26)
if the object was a line. When, on the other hand, the object is an assembly of a certain
number K of points, we shall always find M = K if L is small enough, therefore
M = const. (2.27)
If the object were to finally be two-dimensional, i.e., a part of the plane, M would be
proportional to the number of squares, or
M ∼ L−2 . (2.28)
We can combine all three cases as
M ∼ L−d , (2.29)
where d is the dimension of the object.
26 | 2 Nonlinear maps
To show how the method works we take the Sierpinski gasket. A marker array ibox is
defined whose element ibox(i,j) is set to one if at least one point on the map falls into
the corresponding square:
PROGRAM fractal_dimension
REAL, DIMENSION(3) :: a,b
INTEGER, DIMENSION(1024,1024) :: ibox
Thereafter, log(M) is plotted over − log L (log-log scale) and the slope is determined
that corresponds to the fractal dimension d f according to (2.29):
log M
df = − . (2.30)
log L
This time the program does not use graphic output directly but writes the data on a
file ‘fd.dat’. The file can then be inspected (Figure 2.8) using gnuplot for instance via
2.5 Neural networks | 27
Then the slope can be determined at a convenient position where the curve is more
or less straight. If we take, e.g., points 3 and 8 to construct the slope triangle, we find
d f ≈ 1.585. The value of the fractal dimension can also be computed analytically
using another construction for the Sierpinski gasket, see [3]. One then obtains
2.4.3 Problem
Determine the fractal dimension of the fern and the tree of Figure 2.6 numerically.
2.5.1 Perceptron
The human brain is built of about 80 billion neurons that are linked among each other
with more than 1014 contacts, or synapses. These connections are dynamic and can
be intensified or attenuated, depending on their usage. This time dependent adaption
process is considered the key to learning. The perceptron is a very simple system re-
alizing this concept. It possesses an input layer of N neurons S1 . . . S N which are not
connected to each other. One processing layer, namely the adjustable weighted con-
nections (synapses) w j , links the input neurons to a single output neuron (Figure 2.9).
Each neuron has two states, active (S j = 1) or passive (S j = −1).
The coupling of the input layer to the output neuron is given by the simple relation
N
S o = sign (∑ w j S j ) (2.31)
j
where
{1 for x ≥ 0
sign(x) = {
−1 for x < 0
{
is the slightly modified sign function. The strength of the connections is described by
the synaptic weights w j . If w j < 0, the connection is inhibitive; otherwise it is activat-
ing. During the learning process, the values of the w j are changed accordingly.
(n)
The network learns the assignment x j → y(n) by dynamically changing the synaptic
weights w i . For the optimal case, as many pairs as possible out of (2.32) should fulfill
the relation (2.31):
N
! (n)
y(n) = sign (∑ w j x j ) . (2.33)
j
In 1949, D. Hebb² formulated what is nowadays called Hebb’s learning rule or Hebbian
learning, which says that the synaptic weights are adjusted to the activity of the input
and output neurons they do connect. Let ∆w i denote the modification of w i at each
learning step, then Hebb’s rule can be written up as
1 (n) (n)
∆w j = y xj . (2.34)
N
If there was only one pair (M = 1) to learn and initially all w j = 0, we find after one
step w j = N1 y x j . Inserting this into (2.33) yields
1 N 2
y = sign (y ∑ x ) = sign(y) ,
N j j
which is fulfilled for all y = ±1. In practice, the network should learn of course more
than just one pair. Then one has to modify the rule (2.34): each pair changes the
weights only if it is not yet learned correctly (Rosenblatt rule³):
(n) (n)
{ 1 y(n) x j if y(n) (∑Nj w j x j ) ≤ 0
∆w j = { N (2.35)
0 otherwise .
{
In the ideal case when all pairs have been learned correctly, the algorithm stops by
itself. However, as we shall see below, the capability to learn depends on the in-
put/output pairs (2.32), and the complete learning of all pairs is rather an exception.
But let us first continue with an example.
The main program is then a simple loop over the repeated learning of integers as long
as a stop-bit (here istop) is set:
The array ie contains the value of the input neurons, ia those of the outputs (here only
one). For K, the natural numbers 1, 2, 3, . . . , N are successively offered. The routine
learn sets the stop-bit if imax numbers are recognized correctly one after the other
without changing w. The subroutines read in detail:
2.5 Neural networks | 31
SUBROUTINE inout(ie,ia,n,m,k)
INTEGER :: ie(n),ia(m)
c provides input/output pairs
ie=-1
ie(k)=1 ! input layer
ia(1)=iprim(k) ! output neuron
END
The integer-function iprim(k) returns +1 if k is prime, otherwise −1. We leave the cod-
ing of iprim to the reader.
SUBROUTINE eval(ie,ia,w,n,m)
INTEGER :: ie(n),ia(m)
REAL :: w(n,m)
DO j=1,m
s=SUM(w(1:n,j)*FLOAT(ie))
ia(j)=SIGN(1,FLOOR(s))
ENDDO
END
This is the coding of formula (2.31). The subroutine learn finally realizes Rosenblatt’s
rule (2.35):
SUBROUTINE learn(ie,ia,ial,w,n,m,istop,imax)
INTEGER :: ie(n),ia(m),ial(m)
REAL :: w(n,m)
c modify weights according to Rosenblatt
istop=0
ll=ll+1
DO j=1,m
IF(ia(j).NE.ial(j)) THEN
ll=0
w(1:n,j)=w(1:n,j)+float(ial(j)*ie)/FLOAT(n)
ENDIF
ENDDO
IF(ll.EQ.imax) istop=1 ! set stop-bit
END
If the computed result ia differs from the one that should be learned, ial, the weights
are adjusted accordingly. The stop-bit istop is set if imax numbers are learned correctly
in a row. In Figure 2.10 we show the learning steps needed as a function of N for dif-
ferent initializations of the weights w i .
32 | 2 Nonlinear maps
1e+07
8e+06
w = random
6e+06 w=1
K1
4e+06
2e+06
w = −1 Fig. 2.10: The number K1 of the learning steps
0 needed depends strongly on the number of
0 200 400 600 800 1000 neurons N of the input layer, but also on the
N initialization of the synaptic weights w i .
Now the output neuron becomes active if the sum of its inputs exceeds the threshold
value ϑ, which can be different for each neuron. To indicate the threshold, we write
its value in the respective output neuron. To train the perceptron as a ‘normal’ binary
computer it should at least be able to learn the basic logic functions NOT, AND, OR, and
XOR. Taking an appropriate value for ϑ, this is possible for the first three functions,
but not for XOR (Figure 2.11), as already proven by M. Minsky⁴ in the 60s. The truth
table of an XOR gate looks like
S1 S2 So
−1 −1 −1
1 1 −1
−1 1 1
1 −1 1
0 1/2 −1/2
NOT AND OR
Fig. 2.11: The logic functions NOT, AND, and OR can be realized by an SLP.
w1 a1 + w2 a1 < ϑ
w1 a2 + w2 a2 < ϑ
(2.37)
w1 a1 + w2 a2 > ϑ
w1 a2 + w2 a1 > ϑ .
w2 (a1 − a2 ) < 0 ,
w2 (a2 − a1 ) < 0 ,
S2 S2 S2
S1 S1 S1
AND OR XOR
Fig. 2.12: For AND and OR the input states assigned to the same output state can be separated by a
straight line; for XOR this is impossible.
Unfortunately most of the problems are not linearly separable, at least for larger N.
A solution can be the extension to more than one processing layer (multilayer percep-
tron), for which we refer to the literature.
w ij , i = 1...N , j = 1...M
34 | 2 Nonlinear maps
ie=-1
IF(k.ne.0) ie(k)=1
The related output is the binary image of K, which can be obtained in FORTRAN using
the BTEST statement:
ie=-1
DO j=0,m-1
IF(BTEST(k,j)) ie(m-j)=1
ENDDO
(the most significant bit is ie(1)). The complete listing is provided in [2]. Figure 2.14
shows the synaptic connections for N = 15, M = 4 when finally all numbers 1. . . 15
have been learned after 80 learning cycles (w ij = 1 initialized). Negative (inhibitive)
connections are drawn dashed.
Since there exist no horizontal connections within each layer of the perceptron, the
spatial arrangement of the neurons plays no role. But the brain works differently: sim-
2.5 Neural networks | 35
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Fig. 2.14: The SLP as a decimal to binary converter. Inhibiting connections w < 0 are shown dashed.
In the output layer the most significant bit is on the left-hand side.
ilar stimuli are processed in nearby regions of the cortex. This constitutes the basic
idea of the self-organized maps developed by the Finnish engineer Teuvo Kohonen
in 1982.
I
r⃗ = ( )
J
with (I, J) = (0, 0). . .(M − 1, N − 1) (Figure 2.15). Each neuron is connected with an
input layer consisting of L neurons by synapses with the weights
wℓr ⃗ , ℓ = 1...L
(the upper index ℓ denotes the neurons of the input layer). The Kohonen algorithm
modifies Hebb’s learning rule in the following way:
1. Initializing. Take an appropriate initial value for the weights wℓr ⃗ , e.g., randomly
distributed or all zero or ±1.
2. Input signals. The signals or patterns to learn are offered as vℓ , either one by one
or in a random sequence.
3. BMU. Identify the Best Matching Unit (BMU). The BMU is the neuron that has the
smallest (euclidean) distance to the learning signal. If
L L
∑(vℓ − wℓr ⃗ )2 ≤ ∑(vℓ − wℓr ⃗ )2 for all r⃗ , (2.39)
ℓ ℓ
J
I Fig. 2.15: 25 neurons arranged in a quadratic processing layer.
4. Dynamics. During the adjustment step all synaptic weights are adapted accord-
ing to
∆wℓr ⃗ = ϵ h(d) (vℓ − wℓr ⃗ ) , with d ≡ |r ⃗ − r ⃗ | (2.40)
for all r.⃗ Except for the new function h(d) this is exactly Hebb’s rule (2.34). The
function h(d) is unimodal and has its maximum at d = 0. It could be for instance
a Gaussian of width σ
h(d) = exp(−d2 /2σ 2 ) . (2.41)
Note that in this step not only the BMU is changed but also the neurons lying in
its neighborhood.
5. Refinement. To refine the spatial structure, σ is decreased after each learning
step.
6. If σ ≥ σ min go to 2.
7. The algorithm stops when only the BMU is changed.
where
(ℓ)
0 ≤ wr⃗ ≤ 1 .
The code that implements the Kohonen algorithm can be found in [2] (the array R is
assigned to w(1) , G to w(2) and B to w(3) using an EQUIVALENCE statement).
Figure 2.16 shows color maps formed by a layer of 15 × 15 neurons after learning
100, 500, and 3000 randomly generated RGB patterns. For a monotonically decreasing
2.5 Neural networks | 37
in addition we put ϵ = 0.03. It turns out that the completely random color pattern from
the beginning is eventually organized in such a way that similar colors are assigned
to neurons located close to each other.
pointing at a certain location in 2D real space, e.g., of a road map. If one passes the
neurons one after the other, the adjoint locations (x i , y i ) constitute a certain path on
the road map. If we offer certain given points (places) to the Kohonen algorithm as
learning inputs, the path will be matched closer and closer to these points.
This leads us to the famous Traveling Salesman Problem (TSP). The task of the
TSP is to find the shortest connection between K given places on a road map with the
constraint that each place is only touched once. It turns out that there exist 12 (K − 1)!
different closed paths to fulfill this condition. But which is the shortest? Of course one
could try all paths, but the computational effort increases exponentially with K. Even
for a rather small number of places the largest computers would be overcharged.
To apply Kohonen’s method for an approximate solution, we take 30 prescribed
locations, for instance, randomly chosen positions on a map; see the red points in Fig-
ure 2.17. In each learning step we select randomly one of these locations as the input
38 | 2 Nonlinear maps
Fig. 2.17: Two approximate solutions of the TSP computed with Kohonen’s algorithm based on
a chain of 40 neurons (black dots). A certain number of places, here 30 (red dots), should be
connected by the shortest path. Shown is the situation after 20 (top right), 80 (bottom left),
and 2000 (bottom right) learning steps. In the beginning, the chain is initialized on a circle with
radius R = 0.15 (solid lines) and R = 0.5 (dashed). The path length after 2000 steps is 4.176 (solid)
and 4.304 (dashed).
and adjust the synaptic weights according to (2.40). Also in Figure 2.17 we show the
states of the network after 20, 80, and 2000 learning steps for two different initial val-
ues of the weight vectors w⃗ i . The solid lines correspond to initial values on a circle
with radius R = 0.15, the dashed ones with R = 0.5. After 2000 steps all places are
passed by the paths. For the parameters we use ϵ = 0.8 and
Considering the figure, it is evident that different initial configurations lead to at least
slightly different solutions. But only one path can be the shortest and Kohonen’s algo-
rithm can solve the TSP only approximately.
2.5.3 Problems
Bibliography
[1] J. Argyris, G. Faust, M. Haase and R. Friedrich, An Exploration of Dynamical Systems and Chaos,
Springer (2015).
[2] FORTRAN codes at http://www.degruyter.com/books/978-3-11-051513-8
[3] W. Kinzel and G. Reents, Physics by Computer, Springer (1997).
[4] B. Mandelbrot, The Fractal Geometry of Nature, Freeman and Co. New York (1983).
[5] M. F. Barnsley, Fractals Everywhere, Dover Pub. (2012).
[6] H. Ritter, T. Martinetz and K. Schulten, Neural Computation and Self-Organizing Maps: An Intro-
duction, Addison–Wesley Pub. (1992).
3 Dynamical systems
The foundation of physical theories is normally based on differential equations. In
field theories like quantum mechanics, electrodynamics, or hydrodynamics, one is
confronted with (a system of) partial differential equations
F k [r,⃗ t, Ψ i (r,⃗ t), ∂ t Ψ i (r,⃗ t), ∂ tt Ψ i (r,⃗ t), . . . , ∂ x n Ψ i (r,⃗ t), ∂ x n x m Ψ i (r,⃗ t) . . . , ] = 0 , (3.1)
while in Newton’s classical mechanics ordinary differential equations
G k [x i (t), d t x i (t), d2tt x i (t), . . . ] = 0 (3.2)
are the focus of attention. Systems of the form (3.1) can be expanded into a certain
basis for further numerical analysis, according to
N
Ψ i (r,⃗ t) = ∑ a ik (t) ϕ ik (r)⃗ (3.3)
k
and are thereby converted to the form (3.2). We postpone the treatment of partial dif-
ferential equations to Chapters 6 and 7 and commence here with problems of the kind
of (3.2).
Let t be the independent variable, for instance, time. To begin with, we restrict the
treatment to one dependent variable, say x and search for the function x(t). In classi-
cal mechanics this corresponds to a one-dimensional motion. Quasilinear differential
equations are linear in the highest occurring derivative. Then, (3.2) can be written as
x(N) = f (t, x, x(1) , x(2) , . . . .x(N−1) ) (3.4)
with
dk x
x = x(t) , . x(k) ≡
dt k
Equation (3.4) is equivalent to a system of N first order ordinary differential equations
(ODEs), obtained by the substitution
x1 = x , x k+1 = x(k) , k = 1...N −1
as
d t x1 = x2
d t x2 = x3
.. (3.5)
.
d t x N−1 = x N
d t x N = f(t, x1 , x2 , . . .x N ) ,
https://doi.org/10.1515/9783110515145-003
3.1 Quasilinear differential equations | 41
⃗ + m∆t)
x(t
for m integer. It is clear that in addition to the function f ⃗ we need initial values
⃗ 0 ) = x⃗ 0 .
x(t (3.8)
Formally, the dynamical system (3.6) maps the vector x(t ⃗ 0 ) uniquely onto the vector
⃗ 1 ). This can be also expressed by the help of the time-evolution operator U:⃗
x(t
x(t ⃗ 1 , t0 )[x(t
⃗ 1 ) = U(t ⃗ 0 )] . (3.9)
Equations (3.6,3.8) define an initial value problem, and (3.7) provides a first numerical
approximation scheme for its solution, the so-called Euler-forward method or explicit
Euler method.
In context with the logistic map from Chapter 1 we examine the first order ODE (logistic
ODE)
dx
= (a − 1)x − ax2 , (3.10)
dt
defining the behavior of x(t) for any given x(0) = x0 (one-dimensional initial value
problem). An exact solution can be found by the separation of variables
a−1
x(t) = , (3.11)
a + c e(1−a)t
42 | 3 Dynamical systems
where the integration constant c = (a − ax0 − 1)/x0 is determined by the initial con-
dition. As t → ∞ one obtains the asymptotic solutions
{0 if a<1
xs = { (3.12)
1 − 1/a if a>1
{
which coincide with the fixed points of the logistic map. How is the ODE (3.10) linked
to the logistic map (1.1)? Following (3.7) we express dx/dt by the differential quotient
dx x(t + ∆t) − x(t)
≈ (3.13)
dt ∆t
which becomes exact for ∆t → 0. Inserting (3.13) on the left-hand side of (3.10) one
finds after a short calculation
1 1
x n+1 = ax n ∆t (1 − (1 − ) − x n ) . (3.14)
a ∆t
Here, x n denotes the x values at the time n∆t, or x n = x(n∆t). If we put now ∆t = 1,
Equation (3.14) becomes equivalent to (1.1). In other words, the discretized form of the
ODE (3.10) corresponds mathematically to the logistic map. This explains the similar
‘temporal’ development up to a < 3, i.e., the asymptotic approach to xs and the correct
asymptotic solutions. What cannot be explained are the further bifurcations of the
solutions of the logistic map for a > 3 and their chaotic behavior for even larger a. All
this is of course not included in the solution (3.11).
How can we explain the much richer dynamic behavior of the discretized form
(3.14)? To get an answer we have to look at the stability of (3.14). A stationary solution
(fixed point) of (3.14) reads xs = 1 − 1/a. If we put
x(t) = xs + u(t)
and linearize with respect to u, we can show that for ∆t = 1 the fixed point xs be-
comes numerically unstable as soon as a > 3. Coming from the logistic ODE, all the
bifurcations through the chaotic sequences originate from a too-large time step during
discretization (see Problems) and vanish with a smaller ∆t. However, then (3.14) is no
longer equivalent to the logistic map.
3.1.2 Problems
With a pencil, show that (3.14) becomes numerically unstable if ∆t > 2/(a − 1).
And to code:
1. Plot the function (3.11) using PGPLOT for different initial conditions and different
values of a.
2. Examine the map (3.14) as a numerical solution of the ODE (3.10) for different time
steps ∆t and different a.
3.2 Fixed points and instabilities | 43
We continue with the N-dimensional dynamical system (3.6) with a given initial con-
dition. For the time being we concentrate on autonomous systems, i.e., the right-hand
sides of (3.15) do not depend explicitly on t:
dx i
= f i (x1 . . .x N ) , i = 1...N . (3.15)
dt
For an autonomous system, fixed points as a stationary solution of (3.15) may exist.
They can be found by solving the algebraic system
(0) (0)
0 = f i (x1 . . .x N ) , i = 1...N . (3.16)
We note that for somewhat involved nonlinear f i , solutions of (3.16) are normally only
accessible numerically, even for small N.
3.2.2 Stability
(0)
If a fixed point x i is known, the behavior of the system in its neighborhood is of inter-
est. How do small deviations evolve? Are they amplified or do they fade away in time?
If the deviations stay small or decay, the fixed point is called stable; if they depart ex-
ponentially, we have an unstable fixed point. If N > 1, the disturbed trajectories may
in addition oscillate around the fixed point. This is called oscillatory or Hopf bifurca-
tion¹.
If one restricts to infinitesimal deviations u i (t) from the fixed point
(0)
x i (t) = x i + u i (t) , (3.17)
one may linearize (3.15) with respect to u. This is called linear stability analysis. Insert-
ing (3.17) into (3.15) yields after linearization the system
N
du i
= ∑ L ij u j (3.18)
dt j
Due to (3.20), the real parts of the N eigenvalues λ k characterize the stability of the
(0)
fixed point x i .
Let the eigenvalues be ordered according to Re(λ1 ) ≥ Re(λ2 ) ≥ . . . ≥ Re(λ N ).
We distinguish between the four cases:
(i) All λ k have a negative real part: the fixed point is stable.
(ii) Re(λ1 ) > 0, and Im(λ1 ) = 0; the fixed point is monotonically unstable.
(iii) Re(λ1 ) > 0, and Im(λ1 ) ≠ 0; the fixed point is oscillatory (Hopf) unstable.
(iv) Re(λ1 ) = 0, critical point, center if Im(λ1 ) ≠ 0; the fixed point is marginally stable.
(i) is also named node or stable focus if Im(λ1 ) ≠ 0, (ii) is called saddle point, and (iii)
is an unstable focus.
3.2.3 Trajectories
Two distinct trajectories in N-dimensional state space cannot intersect, nor can a
single trajectory cross itself.
If the circulation (or curl) of f ⃗ vanishes everywhere, a potential function U exists with
∂U(x1 , . . .x N )
fi = − .
∂x i
Then one has
∂2 U
Q(x)⃗ = − ∑
i ∂x2i
and
∂2 U
L ij = − .
∂x j ∂x i
As a consequence, the Jacobi matrix is symmetric and has only real eigenvalues, ex-
cluding the existence of oscillatory instabilities. On the other hand one easily shows
with
N
dU ∂U dx i
=∑ = −|f ⃗|2 ≤ 0
dt i
∂x i dt
d t x = f(x) .
If the solution is bounded, due to the No-Intersection Theorem, every temporal devel-
opment must eventually end in a stable fixed point:
A potential of
U(x) = − ∫ dx f(x)
always exists, which must have at least one minimum at xs because of (3.24).
2 Henri Poincaré, French physicist and mathematician, 1854–1912; Otto Bendixson, Swedish mathe-
matician, 1861–1935.
46 | 3 Dynamical systems
q2 q2 q2
q1 q1 q1
q2 q2 q2
q1 q1 q1
Re λi < 0 Re λi = 0 Re λi > 0
Fig. 3.1: Fixed points and their neighborhood in two-dimensional state space, from left to right, top
row: λ i real valued, stable node, saddle point, unstable node. Bottom row: λ i complex valued, stable
focus, center, unstable focus.
If in two-dimensional state space the trajectories are confined to a finite size region
(i.e., do not go to infinity), they either end on a stable fixed point or approach a stable
limit cycle as t → ∞.
A limit cycle is a periodic solution in state space, that is, a closed trajectory x⃗ lc with
x⃗ lc (t) = x⃗ lc (t + T) where T denotes the period.
Near any fixed point, the local behavior of the trajectories is restricted in two di-
mensions to only a few qualitatively different possibilities, shown in Figure 3.1.
and the trajectories remain in a bounded region. For r < 1, it follows from
that the region is limited for μ < 0. Without solving the ODEs (3.25) explicitly we obtain
the following scenario:
If μ < 0, all trajectories starting somewhere inside the circle x21 (0) + x22 (0) < 1 end
at the stable fixed point (focus or node) x1 = x2 = 0.
If μ > 0, the fixed point becomes unstable. Since all trajectories remain in a
bounded region in state phase and no other (stable) fixed point exists, the Poincaré–
Bendixson Theorem applies: for t → ∞ all trajectories approach asymptotically a limit
cycle circuiting the unstable fixed point.
In the preceding paragraph we saw that in the bounded two-dimensional state space
only regular behavior is possible. All trajectories asymptotically either reach fixed
points or limit cycles. This changes for N = 3. A new object comes into play, the so-
called strange attractor. It can be thought as a certain trajectory having both attractive
and repelling character. The first strange attractor was discovered by E. Lorenz³ as a
numerical solution of a system of nonlinear ODEs [1].
the latter two existing only if δ ≥ 0. We wish to examine their stability and begin with
the fixed point (i). The Jacobi matrix reads
−α α 0
L = (δ + 1 −1 0) (3.27)
0 0 −β
1+α 1
λ12 = − ± √(1 + α)2 + 4αδ , λ3 = −β .
2 2
For δ < 0 all λ have a negative real part and the fixed point is a stable node or a stable
focus. At δ ≥ 0 the fixed point turns into a saddle node with one unstable and two
stable directions (or manifolds, that is the eigenvectors of (3.27)). For (ii) (δ > 0), the
Jacobi matrix reads
−α α 0
L=( 1 −1 ∓√βδ) (3.28)
±√βδ ±√βδ −β
Since all the coefficients of (3.29) are positive, real eigenvalues may only occur with
λ < 0. Evaluation of (3.29) for certain fixed parameters (α = 10, β = 8/3) shows that
for δ larger than ≈ 0.35 the spectrum has the form λ1 = λ∗2 ϵ C, λ3 < 0. The real parts
3.2 Fixed points and instabilities | 49
α(α + β + 3) 451
δ > δc = −1= ≈ 23.7 .
α−β−1 19
Then the two stable focus nodes (ii) turn into unstable saddle foci having a two-
dimensional unstable and a one-dimensional stable manifold. The two fixed points
become oscillatory unstable with the Hopf frequency (δ = δ c )
2αβ(α + 1)
ω c = Im λ1 = √ ≈ 9.62
α−β−1
and finally the Lorenz attractor emerges, an almost two-dimensional object in state
space; see Figure 3.2.
A peculiarity of (3.26) is its constant source strength
Q L = −α − 1 − β < 0 ,
the Lorenz equations are dissipative in the complete state space. From (3.23) it follows
that the size of each arbitrary volume element ∆V0 exponentially decays in time
∆V(t) = ∆V0 eQ L t .
In many problems formulated in classical mechanics the forces are derived from a
potential
V(q1 , . . .q N )
where q1 . . . .q N are the (generalized) positions. To achieve a complete description,
the momenta p1 . . .p N need to be known. The Hamilton⁴ function, or for short, the
Hamiltonian
N p2
H(q i , p i ) = ∑ i + V(q i ) (3.30)
i
2m
coincides with the total mechanical energy of the system and is a constant of motion.
The canonical equations are equivalent to Newton’s equations of motion and can be
formulated as [2]
∂H
dt qi =
∂p i
(3.31)
∂H
dt pi = − . i = 1...N .
∂q i
Since we have two sets of variables, each of them with N variables, the motion de-
scribed by (3.31) has 2N degrees of freedom. However, this is the mathematical defi-
nition of a degree of freedom. In mechanics, each pair of conjugated variables q i , p i
corresponds to one degree of freedom, halving their total number. To exclude further
confusion we adopt the notion mechanical degree of freedom for the number of pairs
of variables (here N), degree of freedom for the number of first order ODEs in (3.31)
(here 2N).
The system (3.31) has the form of (3.15) but, due to the special form of f ⃗,
N
∂2 H ∂2 H
Q = ∇ ⋅ f⃗ = ∑ [ − ]=0
i
∂q i ∂p i ∂p i ∂q i
applies. The size of volume elements is constant in time, and the dynamics in (3.31) is
called conservative.
If one wishes to know the time dependence of some variable A(q i , p i , t) one must
use the chain rule according to
N N
dA ∂A ∂A dq i ∂A dp i ∂A ∂H ∂A ∂H
− = ∑( + ) = ∑( − ) = {A, H}
dt ∂t i
∂q i dt ∂p i dt i
∂q i ∂p i ∂p i ∂q i
The structure created by the flow (3.31) has symplectic geometry [2]. Normally this
geometry is destroyed when (3.31) is integrated numerically. Then a nonvanishing
source strength is generated and constants of motion, especially the total energy, are
no longer conserved. So-called symplectic methods have been developed to avoid
such problems. Here we can only give a short overview, see also [3]. For the sake of
simplicity we restrict ourselves to a two-dimensional phase space corresponding to
one mechanical degree of freedom, that is H = H(p, q) and
∂H ∂H
dt q = , dt p = − . (3.32)
∂p ∂q
We abbreviate x⃗ = (q, p) and write (3.32) as
⃗ x]⃗
d t x⃗ = H[ (3.33)
with the (in general nonlinear) operator
⃗ x]⃗ = ( ∂H/∂p| x⃗ ) .
H[
− ∂H/∂q| x⃗
A remark on the notation: writing H[ ⃗ x]⃗ indicates that H⃗ acts on x,⃗ and the result of
the operation is a vector of the same dimension. Successive operations of H⃗ are then
denoted by H[ ⃗ H[.
⃗ . . x]⃗ . . . ]. It is convenient to omit the brackets and write H⃗ x⃗ instead
⃗ x].
of H[ ⃗ In the same manner we write products of different operators, e.g.,
with
H(p, q) = T(p) + V(q) .
Thus the Hamiltonian should be separable into a momentum-dependent kinetic part
and into a space-dependent potential part. Each part operator
where the coefficients a k , b k can be chosen arbitrarily but must fulfill the constraints
n n
∑ ak = 1 , ∑ bk = 1 . (3.39)
k k
Since both operators (3.36) are symplectic, this holds for the product (3.38) as well.
Taking certain a k , b k , we may then generate methods having a given order in the time
step, where all of them conserve the symplectic geometry of the Hamiltonian flow.
The relation (3.38) is strongly simplified if we take
T⃗ T⃗ x⃗ = 0 , V⃗ V⃗ x⃗ = 0
into account. The Taylor expansion stops after the second term
1
U⃗ T = exp(∆t T)⃗ = 1 + ∆t T⃗ + ∆t2 T⃗ T⃗ + . . . = 1 + ∆t T⃗ ,
2
which also holds for U⃗ V . Then we can substitute
U⃗ T = 1 + ∆t T⃗ , U⃗ V = 1 + ∆t V⃗
in (3.38).
3.3 Hamiltonian systems | 53
Let us state the scheme in the lowest order n = 1. Due to (3.39) a1 = b 1 = 1 and
with (3.38) we obtain
x(t ⃗
⃗ + ∆t) = U(∆t) ⃗ = (1 + ∆t T)⃗ (1 + ∆t V)⃗ x(t)
x(t) ⃗ + O(∆t2 ) .
qn 0 (p n − ∆t ∂V
∂q (q n )) /m)
=( ) + ∆t ( ∂V ) + ∆t (
pn − ∂q (q n ) 0
qn p n+1 /m
=( ) + ∆t ( ∂V ) . (3.40)
pn − ∂q (q n )
Thus, the iteration formula for one time step for p and q read
∂V
p n+1 = p n − (q n ) ∆t
∂q (3.41)
p n+1
q n+1 = qn + ∆t .
m
The one-step scheme (3.41) is analogous to the two-step scheme
∆t2 ∂V
q n+1 = 2q n − q n−1 − (q n ) , (3.42)
m ∂q
which can easily be shown by eliminating p n . The scheme (3.42) is also known as the
Verlet algorithm. It can be derived alternatively from Newton’s second law discretizing
the second time derivative by
d2 q q n+1 − 2q n + q n−1
→ .
dt2 ∆t2
A particular scheme of the 3rd order is generated from (3.38), taking
a1 = a2 = 1/2 , b1 = 1 , b2 = 0 ,
and
⃗
U(t) = U⃗ T (∆t/2) U⃗ V (∆t) U⃗ T (∆t/2) + O(∆t3 ) .
Without going into detail we quote the iteration rule
∂V
p n+1/2 = p n − (q n ) ∆t/2
∂q
p n+1/2
q n+1 = qn + ∆t (3.43)
m
∂V
p n+1 = p n+1/2 − (q n+1 ) ∆t/2
∂q
which is similar to the ‘Leapfrog’ version of Verlet’s algorithm where space and mo-
mentum variables are evaluated at ∆t/2 differing times.
54 | 3 Dynamical systems
–1
–2
–2 –1 0 1 2
Fig. 3.3: Potential V(q 1 , q 2 ) of the Hénon–Heiles model. Inside the triangle around the ori-
gin the motion of the star is bounded if its total energy is less than 1/6. Solid lines: V =
1/6, 1/12, 1/24, 1/48, 1/96, dashed: V = 1/3, 2/3, 1.
3.3 Hamiltonian systems | 55
Fig. 3.4: Comparison between the Euler and the symplectic method, both of the same order ∆t 2 . Left
frame: r = √ q 21 + q 22 over t; right frame: difference of the total energies.
56 | 3 Dynamical systems
For larger values of E and/or for different initial conditions, the trajectories can be-
come more involved, and chaotic regions may appear. The trajectories can be visual-
ized in a comfortable way with the Poincaré section method. To this end, one places an
(N−1)-dimensional hyperplane, the Poincaré plane, somewhere in the N-dimensional
phase space and marks the points of intersection of a trajectory for many revolutions.
Periodic motion is then correlated to single isolated points on the plane, quasiperiodic
behavior to curves, and chaotic regions to fractal objects having a dimension between
one and two on the Poincaré plane.
(n)
Let ξ i , i = 1 . . . N − 1 be the coordinates of the nth intersection with the plane.
(n)
Then from each set ξ i the values for the next intersection point follows uniquely.
Instead of a system of N ODEs, one finds the relation
which is nothing other than an (N − 1)-dimensional map, called a Poincaré map. How-
ever, computing f ⃗ in (3.48) requires solving the ODEs of the full system.
Bibliography
[1] E. N. Lorenz, Deterministic nonperiodic flow, J. Atmos. Sci. 20, 130 (1963).
[2] J. V. José and E. J. Saletan, Classical Dynamics, Cambridge Univ. Press (1998).
[3] J. M. Thijssen, Computational Physics, Cambridge Univ. Press (2007).
[4] M. Hénon and C. Heiles, The applicability of the third integral of motion: Some numerical experi-
ments, Astrophys. J. 69 (1964).
[5] FORTRAN codes at http://www.degruyter.com/books/978-3-11-051513-8
Bibliography | 57
0.5
0.5
0 0
–0.5
–0.5
–1 –0.5 0 0.5 1 –0.5 0 0.5
0.5
0.5
0 0
–0.5
–0.5
–1 –0.5 0 0.5 1 –0.5 0 0.5
0.5
0.5
0 0
–0.5
–0.5
–1 –0.5 0 0.5 1 –0.5 0 0.5
Fig. 3.5: Poincaré plane (left), trajectories in position space (right) for E = 0.12, and several initial
conditions. Dashed: Bounded area defined by the total energy.
4 Ordinary differential equations I,
initial value problems
4.1 Newton’s mechanics
The present chapter mainly deals with problems arising from classical mechanics. We
shall further investigate ordinary differential equations (ODEs) having the form
The highest derivative occurring is now of the second order, normally in time. From
here on we denote the first time derivative of x by x,̇ the second by x.̈
The second law of Newton provides equations of motion for N mass points at the po-
sitions r ⃗i (t), i = 1. . .N
with the force F⃗ i acting on the mass point i. The necessary initial conditions are nor-
mally given by positions and velocities at t = t0
F⃗ i = F⃗ i (r ⃗j , r ̇⃗j )
F⃗ i = F⃗ i (r ⃗j )
with
∂V(r1⃗ . . . r ⃗N )
F⃗ i (r ⃗j ) = − ,
∂ r i⃗
the system (4.1) is denoted as conservative. In this case, the total energy
1
E= ∑ m i (r ̇⃗i )2 + V(r1⃗ . . . r ⃗N ) (4.3)
2 i
https://doi.org/10.1515/9783110515145-004
4.1 Newton’s mechanics | 59
We commence our elaboration with the equation of motion of the damped one-
dimensional mathematical pendulum:
realized for instance by a bar pendulum with a massless bar. Here, ℓ is the bar length,
α > 0 the damping rate and φ denotes the displacement angle from the vertical. The
equivalent first-order system for the two variables φ(t) and ω(t) reads
φ̇ = ω
(4.5)
ω̇ = −α ω − Ω20 sin φ
φ(0) = φ0 , ω(0) = ω0 .
1 2
φ̇ − Ω20 cos φ = E0 − R(t) (4.6)
2
with the integration constant E0 and a monotonically growing function
R(t) = α ∫ dt φ̇ 2 .
The expression on the left-hand side of (4.6) can be identified with the total mechan-
ical energy E/mℓ2 of the system, R corresponds to the energy dissipated by friction
and transformed to heat:
R(t) = E0 − E(t) .
R(t → ∞) = E0 + Ω20
has been converted to heat and the pendulum has come to rest, independently of its
initial conditions. As long as E > E c with E c = Ω20 , the mass point passes through the
upper unstable rest position (rotation), and if E < E c one observes oscillations around
the lower rest position, also called libration.
60 | 4 Ordinary differential equations I
E = E0
and the pendulum, once moving, never comes to rest. Depending on E0 the motion
persists either as oscillation or rotation. For E0 = E c the motion is an infinitely long
approach to the upper rest position. If the initial condition is also chosen with the
upper rest position, the trajectory in phase space (φ-ω-plane) consists of a closed loop
with initial and end points at the very same fixed point, also called a homoclinic orbit
or separatrix.
Next we try to solve the system (4.5) numerically using the Euler method. Introducing
the discrete variables φ n = φ(n∆t), ω n = ω(n∆t), and the time step ∆t, the iteration
rule reads
φ n+1 = φ n + ω n ∆t
(4.7)
ω n+1 = ω n − (α ω n + Ω20 sin φ n ) ∆t .
Figure 4.1 shows phase space and energy over t for different α and different time steps.
For α = 0 (Figure 4.1 top) we expect a constant energy, which is obviously not the case.
Moreover, all trajectories should be closed (periodic motion) instead of spiraling out-
wards. The simple Euler forward method produces an artificial negative(!) damping,
the energy increases as well as the amplitude. After a certain time the separatrix is
crossed and the oscillations turn into rotations. This behavior is qualitatively inde-
pendent of ∆t. Figure 4.1 shows the damped case in the middle; the result looks more
realistic. The trajectories spiral inwards and the energy reaches the value −Ω20 asymp-
totically. In contrary the behavior shown in Figure 4.1 bottom is again ruled by numer-
ical artifacts. For larger time steps (∆t = 0.15) again a kind of ‘negative damping’ is
obtained and the energy increases again.
Let us draw some preliminary conclusions:
– The results for α = 0 are all wrong (negative numerical ‘damping’).
– For α > 0 we find qualitatively correct results for small ∆t.
– Also for the damped case the energy grows continuously and the trajectories get
off of the stable (!) fixed point if ∆t is chosen too large.
As we have already remarked in Section 3.1 the time step of the Euler method is
bounded from above by the demand for numerical stability. We start with the general
4.2 Numerical methods of the lowest order | 61
6
2
0
2
–2
0
0.9
2
0.92
0.94
0
0.96
–2 –0.98
–1
–2 0 2 0 100 200 300
2
0
–0.5
–2
–1
–2 0 2 0 100 200 300
Fig. 4.1: Trajectories in phase space (left) and total energy over t for the damped pendulum
(Ω0 = 1), computed using Euler’s method. Top α = 0, ∆t = 0.05, middle: α = 0.1, ∆t = 0.05,
bottom: α = 0.1, ∆t = 0.15. The behaviors shown in the top and the bottom frames do not even
qualitatively correspond to reality but are rather a product of numerical errors and instability.
62 | 4 Ordinary differential equations I
autonomous system
̇⃗ = f ⃗(x(t))
x(t) ⃗ . (4.8)
The Euler method provides the discretization
x(t ⃗ + f ⃗(x(t))∆t
⃗ + ∆t) = x(t) ⃗ + O(∆t2 ) . (4.9)
Let x⃗ (0) be a stable fixed point f ⃗(x⃗ (0) ) = 0. Then we may linearize (4.9) with x(t)
⃗ =
(0)
x⃗ + u(t) ⃗ for small deviations u⃗ around this fixed point:
⃗ + ∆t) = u(t)
u(t ⃗ ∆t
⃗ + L ⋅ u(t) (4.10)
Due to the stability of x⃗ (0) , the eigenvalues of L must all have a nonpositive real part.
We write (4.10) as
u(t ⃗
⃗ + ∆t) = Q Ex ⋅ u(t) (4.12)
with
QEx = 1 + ∆t L .
To reflect the behavior close to a stable fixed point, the deviations u⃗ should not grow
while iterating (4.12). Thus the spectral radius of Q Ex must be less or equal to one:
ρ(Q Ex ) ≤ 1 . (4.13)
0 1
L=( ) .
−Ω20 −α
For the sake of simplicity we exclude here the overdamped case and assume α < 2Ω0 .
Then the spectral radius of Q Ex turns out to be
ρ = √1 − α ∆t + ∆t2 Ω20
∆t ≤ α ,
which is only fulfilled for the solutions of the middle row in Figure 4.1. For the un-
damped case α = 0 the Euler method is unstable for arbitrarily small steps ∆t.
4.2 Numerical methods of the lowest order | 63
Since the dependent variables at time t+ ∆t occur explicitly on the left-hand side of the
iteration rule, the Euler forward method belongs to the group of explicit integration
schemes. For an implicit method instead of (4.9) one finds the rule
x(t ⃗ + f ⃗(x(t
⃗ + ∆t) = x(t) ⃗ + ∆t))∆t + O(∆t2 ) . (4.14)
To compute the variables at the next iteration step, one must first solve (4.14) for
⃗ + ∆t). This is only possible in a unique way for a linear function f ⃗,
x(t
f ⃗(x)⃗ = A ⋅ x⃗ ,
0.4
E
Δt = 0.01
0.2
Δt = 0.03
Δt = 0.1
0
0 50 100 150 200 250 300
t
Fig. 4.2: Harmonic oscillator, implicit first-order scheme, α = 0. Although closed trajectories and
a constant energy are expected, the method computes a damped solution. The artificial numerical
damping goes with ∆t. Despite being stable for arbitrary time steps, the implicit method is still not
very accurate.
64 | 4 Ordinary differential equations I
which is less than one for all ∆t, even if α = 0. Thus the implicit method for the lin-
earized pendulum (that is the harmonic oscillator) is unconditionally stable and there-
fore much more suitable than the explicit scheme. On the other hand, the numerical
truncation error is still of order ∆t2 and this time generates a positive damping, lead-
ing to decaying oscillations in time even if α = 0, Figure 4.2.
The Euler method converges slowly and provides inaccurate and partially nonphys-
ical results. Mainly for conservative systems this may lead to a qualitatively wrong
behavior of the solutions. To increase the accuracy, higher order methods have been
developed where the truncation error is of order ∆t3 or even better. In the following we
introduce two higher order methods. Both are explicit and belong to the Runge–Kutta
class.
dx
= f(t, x) , (4.16)
dt
which is generalized later to n dimensions. We integrate (4.16) over t
t+∆t t+∆t
dx
∫ dt = x(t + ∆t) − x(t) = ∫ dt f(t , x(t )) (4.17)
dt
t t
the Euler method results. Taking the more accurate trapezoidal rule
t+∆t
∆t
∫ dt f(t , x) ≈ (f(t, x(t)) + f (t + ∆t, x(t + ∆t))) ,
2
t
4.3 Higher order methods | 65
4.3.1.1 Accuracy
To which order of ∆t is the truncation error in Heun’s method? We write (4.20) as (for
the sake of simplicity we assume f(x) instead of f(t, x))
∆t
x(t + ∆t) − x(t) = (f(x(t)) + f (x(t) + f(x(t)) ∆t))
2
and expand the left-hand side with respect to ∆t
dx 1 d2 x 2 1 d3 x 3
L.H.S. = ∆t+ ∆t + ∆t + . . .
dt 2 dt2 6 dt3
1 df 1 d2 f df 2
= f∆t + f∆t2 + (f 2 2 + f ( ) ) ∆t3 + . . . ,
2 dx 6 dx dx
the right-hand side with respect to f∆t:
∆t df 1 d2 f 2 2
R.H.S. = (2f + f∆t + f ∆t ) + . . . ,
2 dx 2 dx2
where . . . denote terms of the order ∆t4 . Both sides coincide up to the order ∆t2 , that is,
the truncation error is of the order ∆t3 and thus one order smaller than that of Euler’s
method.
⃗ + ∆t) = Q H ⋅ x(t)
x(t ⃗
with
1 2 2
Q H = 1 + ∆t L + ∆t L
2
66 | 4 Ordinary differential equations I
and the Jacobi matrix L as in (4.11). Again, numerical stability is given by the restriction
ρ(Q H ) ≤ 1, which eventually leads to
1
ρ = max 1 + ∆tλ i + ∆t2 λ2i ≤ 1 ,
i 2
where λ i are the eigenvalues of L. For the example of the harmonic oscillator with
α 1
λ12 = − ± i√4Ω20 − α 2
2 2
wie obtain the stability limit:
1 2 1 1
−α + α ∆t − αΩ20 ∆t2 + Ω40 ∆t3 = 0 .
2 2 4
This provides an upper time step which is for α > 0, larger than that for Euler’s method
(Figure 4.3, ∆t c ≈ 1.4). However, for the undamped case α = 0, Heun’s method is still
unstable for all ∆t.
Taking the symplectic method from Chapter 3, one iteration step for the harmonic
oscillator can be formulated according to (3.41):
φ φ
( ) = Qs ( )
ω n+1 ω n
er
Heu
Eul
Eul
sympl.
n
tta
tta
Heu
Runge–Ku
Runge–Ku
ρ
ρ
sym
pl.
Δt Δt
Fig. 4.3: Spectral radii over ∆t for the harmonic oscillator, Ω0 = 1, left: damped, α = 1/2,
right: undamped, α = 0. Especially for the undamped case the symplectic method discussed in
Chapter 3 is superior to any other, even higher-order method.
4.3 Higher order methods | 67
The stability is given by the spectral radius of Q s . As long as both eigenvalues are
complex one finds
ρ(Q s ) = √| Det Q s | = √|1 − α∆t| .
For the special (Hamiltonian) case of the undamped oscillator α = 0, one obtains the
pleasant result ρ = 1, and the symplectic method should be stable for ∆t < 2/α. How-
ever, for ∆t ≥ (−α + √α 2 + 4Ω20 )/2Ω20 the complex conjugate pair of eigenvalues of Q s
becomes real valued and the spectral radius quickly exceeds one; compare Figure 4.3.
Despite this restriction and especially for a weak damping (α ≪ Ω), the symplectic
method is much better suited than other methods.
4.3.2 Problems
1. For the Crank–Nicolson method, the right-hand side of the ODEs is written as a
linear combination of explicit and implicit terms. Let y(x) be the solution of
dy(x)
= f(y(x))
dx
̃
and y(x) ̃ 0 ) = y(x0 ),
the numerically obtained approximation. Starting with y(x
the Crank–Nicolson scheme provides
̃ 0 + ∆x) − y(x
y(x ̃ 0) 1
= [f(y(x ̃ 0 + ∆x))] .
̃ 0 )) + f(y(x (4.22)
∆x 2
Show that the numerical error after one time step reads
Taking a higher order algorithm increases both step size and accuracy. Even higher
order methods are possible, however, the numerical effort would also increase. For
Heun’s method one has to evaluate f at two different function values for each itera-
tion step. To reduce the algorithm to practice one should always find a compromise
between accuracy and effort.
An algorithm that has stood the test of time is the already in 1895 developed
Runge–Kutta method (RK). RK exists in different orders; normally the fourth order
scheme (which we shall abbreviate by RK4) is taken. For the sake of simplicity we
explain the principle at a method of the second order.
Let x = x(t) be the desired solution of the ODE
ẋ = f(t, x(t)) .
68 | 4 Ordinary differential equations I
We expand x at t + ∆t/2
∆t 1 ∆t 2
x(t) = x(t + ∆t/2) − ̇ + ∆t/2) + ( ) x(t
x(t ̈ + ∆t/2) + O(∆t3 )
2 2 2
∆t 1 ∆t 2
x(t + ∆t) = x(t + ∆t/2) + x(t ̈ + ∆t/2) + O(∆t3 )
̇ + ∆t/2) + ( ) x(t
2 2 2
and subtract the two equations
̇ + ∆t/2) + O(∆t3 ) .
x(t + ∆t) = x(t) + ∆t x(t
It results in an iteration scheme of the order of ∆t2 . Similar to Heun’s method one
must know ẋ = f for a time later than t to compute the right-hand side. Again this is
accomplished by the Euler method
̇ + ∆t/2) = f (t + ∆t/2, x(t + ∆t/2)) = f (t + ∆t/2, x(t) + ∆t/2 f(t, x(t))) + O(∆t2 )
x(t
k 1 = ∆t f(t, x(t))
k 2 = ∆t f(t + ∆t/2, x(t) + k 1 /2) (4.23)
x(t + ∆t) = x(t) + k 2 .
Thus an explicit scheme of order ∆t2 is constructed where f must be evaluated twice at
each step. Although it looks different, the scheme (4.23) is similar to Heun’s method
(4.20) up to the order ∆t3 , which can be shown by expanding (4.23) with respect to
∆t/2 at t and t + ∆t.
In the same manner the fourth order RK scheme is derived:
k 1 = ∆t f(t, x(t))
k 2 = ∆t f(t + ∆t/2, x(t) + k 1 /2)
k 3 = ∆t f(t + ∆t/2, x(t) + k 2 /2) (4.24)
k 4 = ∆t f(t + ∆t, x(t) + k 3 )
1
x(t + ∆t) = x(t) + (k 1 + 2 k 2 + 2 k 3 + k 4 ) ,
6
and is easily coded in FORTRAN95:
SUBROUTINE rk4(x,t,n,dt,eq)
C integrates the ODE system defined in eq from t to t+dt
C x dependent variables x(n)
C t independent variable
C n number of dependent var.
C dt time step
4.3 Higher order methods | 69
The error for RK4 is of the order ∆t5 and the restriction for the step size originates now
from the stability condition (the detailed computation is left for the reader)
1 4 4
1 1
ρ = max 1 + ∆tλ i + ∆t2 λ2i + ∆t3 λ3i + ∆t λ i < 1 . (4.25)
i 2 6 24
An evaluation of ρ is also shown in Figure 4.3. As expected, the stability region is much
larger than those of the other schemes having a lower order.
PROGRAM pendulum_rk4
REAL, DIMENSION(2) :: y ! variables phi, omega
...
y=(/2.,0./) ! initial values for phi and omega
t=0.; dt=0.01
DO WHILE(t.LT.tend) ! time iteration loop begins
t=t+dt
CALL rk4(y,t,2,dt,pendulum_deq) ! compute one time step with rk4
...
ENDDO
...
If the subroutine rk4 has been placed in the program library (see Appendix B), only
the subroutine pendulum_deq has to be specified in the file below the main section
(MAIN), here pendulum_rk4. This can be done even inside MAIN using the CONTAINS
statement. Then the parameters, here omega and alpha, are global and also defined in
the subroutine. Moreover, MAIN recognizes pendulum_deq as the name of a subrou-
tine and transfers it accordingly to rk4.
70 | 4 Ordinary differential equations I
0
2
0.2
–0.4
0
–0.6
–2 –0.8
–1
–2 0 2 0 100 200 300
0.5
2
–0.5
–2
–1
–2 0 2 0 100 200 300
Fig. 4.4: The undamped mathematical pendulum (α = 0) with RK4. For a time step too large, numer-
ical friction distorts the result (top, ∆t = 1), for ∆t = 0.1 (bottom) the energy is conserved well for
many periods (Ω0 = 1, T = 2π).
...
CONTAINS
SUBROUTINE pendulum_deq(rhside,y,t)
REAL, DIMENSION(2) :: rhside,y
rhside(1)=y(2)
rhside(2)=-alpha*y(2)-omega**2*SIN(y(1))
END SUBROUTINE pendulum_deq
The other, more traditional ‘FORTRAN77-like’ way is to avoid the CONTAINS statement
and the sometimes confusing use of global variables by defining pendulum_deq by an
4.3 Higher order methods | 71
EXTERNAL statement in MAIN. The parameter transfer to the subroutine defining the
right-hand sides of the ODEs can then be realized by a COMMON block.
d(∆t1 ) ∆t1 5
=( ) .
d(∆t2 ) ∆t2
This can be solved for ∆t2 :
d(∆t2 ) 1/5
∆t2 = ∆t1 ( ) .
d(∆t1 )
Now we compute one iteration with a certain fixed ∆t1 and require d(∆t2 ) = ϵ as the
desired accuracy. Then the step width to achieve this accuracy reads
1/5
ϵ
∆t2 = ∆t1 ( ) .
d(∆t1 )
In practice the method is more robust if the exponents are taken variably, depending
whether ∆t increases or decreases:
p
ϵ
∆t2 = ∆t1 ( )
d(∆t1 )
and
{1/5 if d<ϵ
p={ .
1/4 if d≥ϵ
{
72 | 4 Ordinary differential equations I
0.3
0.2
4.3.3.3 Problems
The two coupled rate equations
ṅ 1 = α 1 n1 − α 2 n1 n2
(4.26)
ṅ 2 = −β 1 n2 + β 2 n1 n2 , αi , βi > 0 ,
were proposed by Lotka (1920) and Volterra (1931) to model the interaction between a
prey n1 (t) and a predator n2 (t) population. They are nowadays known as the Lotka–
Volterra model and constitute the most simple predator-prey system.
1. Explain the terms on the right-hand sides of (4.26). Show that performing a proper
scaling of time, n1 and n2 , (4.26) can be cast into the form
ṅ̃ 1 = a ñ 1 − ñ 1 ñ 2
(4.27)
ñ̇ 2 = −ñ 2 + ñ 1 ñ 2 , a>0
The basic subject of classical celestial mechanics is the computation of the trajectories
of point masses (planets or stars) interacting with Newton’s law of gravity. Only the
most simple situation of two bodies in an otherwise empty universe can be solved
exactly. This situation is known as the two-body or Kepler problem. Its solutions are
the well-known ellipses, parabolas, or hyperbolas.
Two bodies (point masses) with mass m i are located at r i⃗ (t). Between both bodies a
force according to Newton’s law of gravity is assumed. The equations of motion read
r1⃗ − r2⃗
r1̈⃗ = −G m2
|r1⃗ − r2⃗ |3
(4.29)
r2⃗ − r1⃗ m1 ̈
r2⃗̈ = −G m1 = − r1⃗
|r2⃗ − r1⃗ |3 m2
with Newton’s gravity constant G ≈ 6.67 ⋅ 10−11 m3 /(kg s2 ). Introducing relative co-
ordinates η⃗ = r1⃗ − r2⃗ , the six mechanical degrees of freedom can be reduced to three
(this is a consequence of the conservation of the total momentum)
η⃗
η̈⃗ = −G M 3 (4.30)
η
with the total mass M = m1 + m2 . Taking the center of mass as the origin of the coor-
dinate system, one has the relations
m2 m1
r1⃗ = η⃗ , r2⃗ = − η⃗ . (4.31)
M M
Due to the central forces the total angular momentum is conserved and the motion
can be further restricted to a plane, leaving only two mechanical degrees of freedom.
Without loss of generality, we can study the 2D problem with η⃗ = (x, y). After appro-
̃
priate scaling |η| = |η|(GM) 1/3 one obtains the two ODEs of second order without any
further parameters
x
ẍ = − 3
r (4.32)
y
ÿ = − 3
r
√
where r = x + y . The total energy measured in multiples of GM 2/3 reads
2 2
1 2 1
E= (ẋ + ẏ 2 ) − (4.33)
2 r
and represents another constant of motion. Together with the constant angular mo-
mentum
L = x ẏ − y ẋ (4.34)
74 | 4 Ordinary differential equations I
the number of dynamical degrees of freedom in (4.32) is further reduced from four to
two. But this excludes chaotic behavior and one expects at least for bounded solutions
either fixed points or periodic solutions¹. Fixed points with a finite E do not exist for
the Kepler problem and the periodic solutions correspond to the closed orbits of the
planets.
An obvious solution of (4.32) is a circular orbit with radius R,
x = R cos(ωt) , y = R sin(ωt) .
SUBROUTINE kepler_deq(rhside,y,t)
REAL, DIMENSION(4) :: rhside,y
r32=(y(1)**2+y(3)**2)**(3/2.)
rhside(1)=y(2)
rhside(2)=-y(1)/r32
rhside(3)=y(4)
rhside(4)=-y(3)/r32
END
x(0) = R , y(0) = 0 , ̇
x(0) =0, ̇
y(0) = L/R ,
one finds a circular orbit for L = L0 = √R with radius R, otherwise ellipses, or for even
larger L, hyperbolas. For L < L0 , the initial point coincides with the aphelion (this is
the largest distance from the planet to the sun), and for L > L0 , with the perihelion of
the ellipse. For E, (4.33) is evaluated as
L2 1
E= − ,
2R2 R
i.e., if L > √2R one has E > 0 and no bounded solutions exist anymore. The two
bodies are free and move on hyperbolas around their common center of mass.
In general there is now friction in the celestial mechanics of mass points. Then
it may become crucial how numerical friction will modify the results. How far is the
energy (4.33) conserved? To shed light on this issue we show in Figure 4.6 the value
of E after 10 000 revolutions as a function of ∆t for a circular orbit with R = 1, L = 1,
1 However, this applies only for the 1/r-potential, see the remarks in Section 4.4.2.
4.4 RK4 applications: celestial mechanics | 75
Fig. 4.6: Deviation of the total energy of a planet revolving on a circular orbit (R = 1, L = 1) from the
exact value E = −1/2 after 10 000 periods, plotted over the time step ∆t. Although only of the order
∆t 2 , the symplectic algorithm is superior to the fourth order Runge–Kutta method for larger ∆t.
SUBROUTINE symplect(y,dt)
C symplectic integrator for one time step
REAL, DIMENSION(4) :: y
r32=(y(1)**2+y(3)**2)**(3/2.) ! denominator
y(2)=y(2)-y(1)/r32*dt
y(4)=y(4)-y(3)/r32*dt
y(1)=y(1)+y(2)*dt
y(3)=y(3)+y(4)*dt
END
As it can be seen also from Figure 4.6, the symplectic method is not always preferable.
For a larger time step it conserves the energy better, but for smaller time steps the
accuracy of RK4 is much higher.
76 | 4 Ordinary differential equations I
0.5
–0.5
For E < 0 all orbits are closed. This is a special property of the 1/r-potential and any
tiny deviation
1
V(r) = − (1+ϵ) , |ϵ| ≪ 1
r
leads to nonclosed, quasiperiodic trajectories whose perihelion turns slowly around
the central mass (Figure 4.7). For ϵ ≠ 0 the only closed orbit is the circle (for a more
detailed discussion see Problems, Section 4.4.5).
Previously we argued that the motion is reduced due to the conservation laws on a
plane with two dynamical degrees of freedom. But how then can crossing trajectories
emerge as depicted in Figure 4.7? Apparently there exist two possible paths after each
crossing point. This is a consequence of the not unique relation ẋ = x(x,
̇ y), ẏ = y(x,
̇ y).
If we eliminate for instance ẏ with the help of (4.34) from the energy law (4.33) we find
̇ y) having two different solutions.
a quadratic equation for x(x,
Things are getting much more involved if the system is extended to more than one
planet circling the central star. Analytic solutions of the equations of motions can be
found only by perturbation theory and for very special cases.
In 1887 the King of Sweden Oscar II asked the question ‘is our solar system sta-
ble?’ and offered a prize of 2500 crowns for the answer. Even nowadays this question
is not definitely decided. On the one hand, in 1890 Henri Poincaré could find a kind
of counter-evidence. He mathematically showed that already for the three-body prob-
lem, i.e., a planet close to a double star, no regular orbits can exist. On the other hand,
the French astronomer Jacques Laskar computed numerically in 1989 the orbits of the
4.4 RK4 applications: celestial mechanics | 77
four inner planets, and in 1994, of all planets in our solar system for the next 25 bil-
lion years and found that the trajectories are ‘weakly chaotic,’ but collisions between
the planets are rather unlikely in the next 200 million years [1, 2]. A further indication
to the instability of certain orbit radii is the distribution of asteroids between Mars
and Jupiter. One observes the so-called Kirkwood gaps occurring at orbit radii having
a period of revolution TA as a rational of the period of Jupiter:
TJ
TA = , n = 2, 7/3, 5/2, 3, . . . . (4.36)
n
Resonances occur along those orbits, which pull out the asteroids located close to
these radii in a short time (at least on the astronomic scale); see also left frame of
Figure 1.1.
The interaction of three celestial bodies can be examined numerically. Based on
(4.29) we consider the extended ODE system
Again the number of degrees of freedom can be reduced due to the conservation of the
total momentum. Taking the center of mass as the origin of the coordinate system, we
may eliminate for instance r3⃗ :
Here, α i = m i /m3 denote the dimensionless mass ratios. Scaling the time according
to
Gm3 1/2
τ=t( 3 )
ℓ
where ℓ is a length to be determined later, one finds the dimensionless system
with r3⃗ from (4.38). The energies of the three bodies in units of ℓ/Gm23 read
1 αi αk
Ei = α i (r ̇⃗i )2 + ∑ V ik , V ik = − , (4.40)
2 k=i̸
| r ⃗ i − r ⃗k |
78 | 4 Ordinary differential equations I
constitutes again a constant of motion and can be used as a control value for any nu-
merical integration. In addition, the three components of the total angular momentum
L⃗ = ∑ m i (r ⃗i × r ̇⃗i )
i
10 –0.0022
–0.0024
–0.0026
1
–0.0028
–0.0030
|ri (t)|
0.1 –0.0032
Ei
–0.0034
–0.0036
0.01
–0.0038
–0.0040
0.001 –0.0042
500 1000 1500 2000 2500 500 1000 1500 2000 2500
t t
Fig. 4.8: The three-body problem and numerical solutions for α 1 = α 2 = 0.001. Left: the distances
|r i | from the origin; right: the energies E 1 , E 2 from (4.40). The two lighter bodies (red, green) circuit
the heavy one (blue) on weakly distorted circular orbits.
1000 0
100 –0.005
10
–0.01
|ri (t)|
1
Ei
–0.015
0.1
0.01 –0.02
0.001 –0.025
500 1000 1500 2000 2500 500 1000 1500 2000 2500
t t
Fig. 4.9: Same as Figure 4.8, but for α 1 = 0.015, α 2 = 0.025. Now the evolution seems much
more chaotic. At t ≈ 100 the at first inner planet (green) moves outwards. It continues absorbing
energy from the other two bodies and reaches even larger orbits. Eventually it may escape from the
influence of the two other masses (E 2 ≈ 0, t > 1400). Then the two remaining bodies form a stable
periodic Kepler system.
To arrive from (4.37) at the so-called reduced three-body problem, the following ap-
proximations are in order:
– All masses move in the same plane (2D).
– One of the three masses is light enough (a small planet, an asteroid, or a space
ship) not to influence the motion of the two other ones. Let us assume m1 ≪
m2 , m3 . Then m1 is called the test body (TB).
– The two heavy bodies (named main bodies, e.g., sun and Jupiter or a double star)
move in circles around their common center of mass with the angular frequency ω.
Lengths and time are scaled to their distance and period so that |r2⃗ − r3⃗ | = 1 and
ω = 1.
80 | 4 Ordinary differential equations I
cos t cos t
r2⃗ (t) = −μ ( ) , r3⃗ (t) = (1 − μ) ( ) . (4.43)
sin t sin t
For the test body m1 , the equation of motion has the form
ẍ = 2 ẏ − ∂ x V
(4.45)
ÿ = −2 ẋ − ∂ y V
and
r = √x2 + y2 ,
between the TB and the two main bodies. In the corotating system the main bodies
rest on the x-axis:
r2⃗ = (−μ, 0) , r3⃗ = (1 − μ, 0) ,
4.4 RK4 applications: celestial mechanics | 81
Fig. 4.10: Forbidden regions (gray) for μ = 1/4 and E = −2.0, −1.8, −1.7, −1.55 (from left to right).
For E ≥ −3/2 − μ(μ − 1) ≈ −1.406 the test body has access to the complete plane.
their common center of mass coincides with the origin. As can be shown easily, the
total energy
1
E = (ẋ 2 + ẏ 2 ) + V(x, y) (4.47)
2
is conserved and determined by the initial conditions. Since the kinetic energy cannot
be negative, the TB can only be located in regions where
E − V(x, y) ≥ 0 ,
∂x V = ∂y V = 0 .
Three of the Lagrangian points lay on the x-axis (Figure 4.11), their x-values can only
be computed numerically (see Problems). They are unstable for all μ. Of more interest
are the two other fixed points y ≠ 0, the so-called Trojans. They turn out to be
L4
L3 L1 L2
and form an equilateral triangle with the two main bodies with side length one. Lin-
earizing (4.45) around (4.48)
x = x4,5 + x̄ , y = y4,5 + ȳ
1 1 23 1 1 23
− √ <μ< + √ .
2 2 27 2 2 27
For all other values of μ the Trojans are stable (purely imaginary λ).
The potential values V1 . . . V5 assigned to the five Lagrangian points constitute
important energies separating qualitatively different solution behavior. Let us assume
μ < 1/2, i.e., the heavier main body is on the negative x-axis. Then we have (see also
Figure 4.10):
– E ≤ V1 : Depending on initial conditions, the TB circuits one of the two main bod-
ies.
– V1 < E ≤ V2 : The allowed region opens between the main bodies, the TB can
move on orbits enclosing both main bodies.
– V2 < E ≤ V3 : The allowed region opens on the right-hand side and the TB can
separate arbitrarily far from the main bodies (escape-trajectories).
– V3 < E ≤ V4,5 : The allowed region also opens on the left-hand side.
– V4,5 ≤ E: The forbidden region has vanished completely.
s = √r2 r3 .
4.4 RK4 applications: celestial mechanics | 83
If the TB comes close to one of the two main bodies we find s ≪ 0. The scaling
1
dτ = dt , u = s2 ẋ , v = s2 ẏ (4.51)
s3
leads after some computations, to the system
d τ x = s2 u
d τ y = s2 v
s2 (4.52)
d τ u = 2s3 v − s4 ∂ x V − Fx
2
s2
d τ v = −2s3 u − s4 ∂ y V − F y
2
with
F x = (r22 + r23 ) ((x + μ)u 2 + yuv) − r22 u 2
(4.53)
F y = (r22 + r23 ) ((x + μ)uv + yv2 ) − r22 uv .
All denominators from (4.45, 4.46) have been removed. However, for large distances
r, s ≫ 1, the regularization (4.51) results in diverging velocities u, v. To get rid of this
difficulty, we switch for s > 1 to the scaling:
1 1
dτ = dt , u= ẋ , v= ẏ
s s
and obtain
dτ x = s u
dτ y = s v
1 1 (4.54)
dτ u = 2 v − ∂x V − 3 Fx
s 2s
1 1
d τ v = −2 u − ∂ y V − 3 F y .
s 2s
The system (4.52,4.54) can be coded using RK4. Even better suited is RK4 with adaptive
time step, see Section 4.3.3.2. The accuracy can also be controlled dynamically taking
ϵ = ϵ0 s .
Then the relative accuracy ϵ/r remains approximately constant. For the complete pro-
gram we refer to the website [3].
Figure 4.12 shows numerically computed orbits for μ = 1/4 and several values
of E. The Lagrangian points are located at
Fig. 4.12: Trajectories for μ = 1/4 and E = −2.0 (top row), E = −1.8 (second row), E = −1.75 (third
and fourth row), E = −1.55 (bottom row).
4.4 RK4 applications: celestial mechanics | 85
For all solutions we fixed ϵ0 = 0.001, leading to a dynamical time step between 10−5
and 10−2 . For E < V1 the orbits are normally periodic or quasiperiodic. If E > V1 , the
trajectories soon become chaotic. For even higher energies most of the orbits leave the
region close to the main bodies and escape to infinity. On the other hand, even here,
bounded orbits exist (last row on the left).
As can be seen in the figure, depending on the initial conditions, one obtains for
the same values of μ and E completely different trajectories. For any given E we may
scan the allowed region for x(t = 0), y(t = 0) and integrate the equations from t = 0 up
to a certain given (long) time t = t e . Then the resulting trajectory is evaluated accord-
ing to its behavior and the initial point x(t = 0), y(t = 0) is colored accordingly. Two
such orbit-type diagrams are shown in Figure 4.13, again for μ = 1/4 and E = −1.8;
E = −1.75. The absolute value of the initial velocity follows from the energy equa-
tion (4.47), its direction chosen perpendicularly² to r1⃗ . At t e = 1000 we distinguish
between
– White: escape trajectory. The trajectory leaves the area r < 4 within t < t e .
– Red: orbit around main body at −μ. Bounded up to t = t e .
– Green: orbit around main body at 1 − μ. Bounded up to t = t e .
– Blue: orbit around both main bodies. Bounded up to t = t e .
The boundaries between different regions look at least for E = −1.75 fractal, a hint
toward chaotic orbits. At this energy value, orbits only enclosing the heavier main
body are rather uncommon.
Fig. 4.13: Scan through the allowed region of initial conditions with a resolution of 400 x 400 dots,
μ = 1/4, E = −1.8 (left), and E = −1.75 (right). The different colors correspond to the different types
of the trajectories (see text).
2 The direction is an additional parameter in the form of an initial value. For other directions, one
obtains other diagrams.
86 | 4 Ordinary differential equations I
4.4.5 Problems
During the past five decades, direct numerical simulations of microscopic many-
particle systems became more and more a focus of interest. In this way material
parameters or even phase transitions can be computed based on ‘first principles.’
However, in statistical physics, ‘many’ means some 1023 particles, a number that will
remain always beyond numerical realization. The first papers in the field [4] clearly
dealt with fewer than 1000 particles, whereas nowadays handling some 100 million
is feasible.
Most MD systems are based on the laws of classical mechanics. In the simplest case,
one considers N equal particles (mass points) interacting with two-body forces. The
force is often described by the Lennard-Jones potential³
σ 12 σ 6
V(r) = 4ϵ (( ) − ( ) ) (4.56)
r r
where r is the distance of the two interacting particles. The parameters ϵ and σ de-
pend on the material to be simulated and take, e.g., for the inert gas Argon, the values
ϵ/k B = 120 K, σ = 3.4 Å (k B = 1.381 ⋅ 10−23 J/K, Boltzmann’s constant). Again we
shall restrict ourselves to a plane problem with two spatial dimensions. Although this
seems not very realistic for a gas or a solid, the codes will be shorter and execute much
faster. The method does not differ from the three-dimensional treatment and we can
leave a 3D extension to the reader.
Applying a scaling to nondimensional variables
r = σ r̃ , t = σ √m/ϵ t ̃ ,
where
f(r) = 2r−14 − r−8 (4.58)
and must be conserved if no external forces are present. Here we denote the total ki-
netic internal energy by
1 N
Ek = ∑ ( r ̇⃗i ) ,
2
(4.61)
2 i
For the majority of MD simulations, periodic boundary conditions are assumed. The
integration domain with periodic length L is thought to be repeated in each space di-
rection infinitely many times. Each particle is not only interacting with every other one
in L but also with the ones in the periodic copies. In this way a much larger system is
simulated. Wall effects, however, cannot be studied since the system is in fact infinite.
88 | 4 Ordinary differential equations I
A much more simple way is to take rigid, impermeable, and perfectly reflecting
walls around the integration domain. If while integrating a particle position x i , y i out-
side of the domain turns out, say on the right-hand side x i > L, the particle is to be
reflected. Then its new position and x-velocity are simply set to
x i → 2L − x i , ẋ i → −ẋ i .
The same can be done for y and correspondingly for the walls at x = 0, y = 0. The parti-
cles interact with the walls in the form of elastic collisions where energy and absolute
value of momentum are conserved.
The macroscopic state variables of a closed many-particle system are the internal en-
ergy E, the volume V (in 2D V = L2 ), and the number of particles N. All three quantities
are constants of motion and can be adjusted by the system and the initial conditions,
respectively. Using the notions of statistical mechanics, such a system is called a mem-
ber of the microcanonical ensemble. Each member is represented by a point in the
4N-dimensional state space, the Γ-space. When time goes on, these points travel on
trajectories in a 4N − 1-dimensional hyperplane
E(x1 , y1 . . .x N , y N , u 1 , v1 . . .u N , v N ) = const.
√Ts /T,
fulfilling (4.63). Here, Ts denotes the prescribed nominal temperature of the heat bath.
4.5 Molecular dynamics (MD) | 89
Here we shall only briefly describe the algorithm; a detailed and commented listing
can be found in [3]. To integrate (4.57) with (4.65) a symplectic scheme is recom-
mended. Introducing the particle velocities (u, v) = (x,̇ y),
̇ a system of 4N first-order
ODEs is obtained having the form:
N
u̇ i = 24 ∑ f(r ij ) (x i − x j ) − γ(T) u i
j=i̸
ẋ i = u i
(4.66)
N
v̇ i = 24 ∑ f(r ij ) (y i − y j ) − γ(T) v i
j=i̸
ẏ i = v i ,
which after time discretization can be brought into the symplectic scheme (see Sec-
tion 3.3.2)
N
(n+1) (n) (n) (n) (n) (n)
ui = ui + [24 ∑ f (r ij ) (x i − x j ) − γ(T) u i ] ∆t
[ j=i̸ ]
(n+1) (n) (n+1)
xi = xi + ui ∆t
(4.67)
N
(n+1) (n) (n) (n) (n) (n)
vi = vi + [24 ∑ f (r ij ) (y i − y j ) − γ(T) v i ] ∆t
[ j=i̸ ]
(n+1) (n) (n+1)
yi = yi + vi ∆t .
4.5.4.1 Optimization
To find the forces acting on a certain particle (called reference particle in the follow-
ing) one must sum over all N − 1 pair forces caused by the other particles. This corre-
sponds to N(N − 1) evaluations of the pair potential at each time step. The program
90 | 4 Ordinary differential equations I
can be vastly optimized if only those particles located within a certain distance r m to
the reference particle are taken into account. The Lennard-Jones potential decreases
with 1/r6 , thus it should be sufficient to take say r m = 4r0 . Then U(r m ) ≈ −0.0005 can
safely be neglected against U(r0 ) = −1. To restrict the pair sum on the neighbors laying
in a sphere (or disc in 2D) with radius r m , one must know the ambient particles for the
reference particle, demanding a certain bookkeeping during the dynamical process.
This can be achieved most easily with a two-dimensional array NB. Let the particles
be numbered with k = 1 . . . N (ordinal number). Then the first index of NB is assigned
to the ordinal number of the reference particle, say k, while the second one lists the
neighbors. There, NB(k, 1) is equal to the number of neighbors of the reference par-
ticle k. If we have, for instance, NB(k, 1) = 5, particle number k has five neighbors
inside r m , whose ordinal numbers are stored in NB(k, 2) through NB(k, 6). Since the
particle positions change continuously, the neighborhood array must be updated, tak-
ing an additional computational effort. However, depending on the maximal particle
speed this update is not necessary after each single time step. In practice it proves to
be sufficient to recompute NB after, say, 20–30 steps.
4.5.5 Evaluation
⟨r2 ⟩ = D t .
4.5 Molecular dynamics (MD) | 91
Fig. 4.14: Configurations of 1600 particles and different temperatures, each after t = 200.
Fig. 4.16: Scaled pair correlation function for several temperatures, solid: T = 0.12, dash-dotted:
T = 0.44, dashed: T = 1.25.
where Θ denotes the step function, and g(r) can be computed as:
1
g(r) 2πr∆r = n(r) . (4.70)
N(N − 1)
To find n(r), one needs a histogram. To this end, the particles n(r) laying on the ring
are counted and stored for several discrete values of r i = i∆r at a certain time. To
avoid fluctuations, one averages (4.69) over a certain time interval (time average =
ensemble average). Figure 4.16 shows the (scaled) pair correlation functions for the
three different temperatures from Figure 4.14. Clearly visible is the transition from a
far order (solid state) to a near order (liquid) and finally to a pure repulsion (gaseous)
if temperature is increased.
dE
cv = (4.71)
dT
4.5 Molecular dynamics (MD) | 93
Fig. 4.17: Internal energy E p over T , averaged over a time interval ∆t = 100. When close to a phase
transition, E p varies strongly. Simulation with N = 1600.
with the total energy E as (4.60). There are different ways to compute cv from MD sim-
ulations. For a canonical ensemble one finds
1
cv = Var(E)
kb T2
with the variance Var(E) = ⟨E2 ⟩ − ⟨E⟩2 and ⟨. . . ⟩ as the ensemble or time average.
However, for the computations described above, E is a conserved quantity and thus
Var(E) = 0. If, on the other hand, one substitutes in (4.60) Ek = NT, (4.71) yields
dEp
cv = N +. (4.72)
dT
Ep (T) can be easily gained from an MD simulation. The dependence of Ep on T is
shown in Figure 4.17. The strong increase around T ≈ 0.45 indicates a phase tran-
sition. Indeed, cv should diverge in the thermodynamic limit at a phase transition.
Another method to compute cv was developed by Lebowitz et al. [6]. There, one
needs only the variance of the kinetic energy (4.61) and gets:
N
cv = Var(E k )
. (4.73)
1− NT 2
Figure 4.18 shows cv after (4.73) from the same simulation as used for Figure 4.17. The
data is rather noisy. A maximum can nevertheless be clearly recognized at T ≈ 0.45,
as well as the correct asymptotic behavior of cv .
For small T the equipartition theorem provides E = 2NT (two degrees of freedom
from translation and another two from oscillation around rest position) and therefore
cv = 2N. For a large T one expects ‘almost free’ particles (perfect gas) with cv = N.
94 | 4 Ordinary differential equations I
10000
8000
6000
cv
4000
2N
2000
N
0
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
T
Fig. 4.18: Specific heat from (4.73). For T → 0 one expects c v = 2N (elastic solid), for T → ∞ c v = N
(perfect gas). Simulation with N = 1600.
4.5.6 Problems
1. Thermalization
A method to keep the temperature of a many-particle system constant at Ts is to intro-
duce friction terms into the equation of motion as done in (4.66):
where
Ts
γ(T, Ts ) = γ0 (1 − ) .
T
For the interaction-free case F⃗ i = 0, derive from (4.74) a first-order ODE for T(t). Solve
this equation and show that T approaches Ts exponentially in time with exp(−2γ0 t).
2. 2D-equilibrium configurations
An (infinitely extended) 2D-many-particle system at equilibrium forms a periodic lat-
tice. Consider the two configurations: square and hexagonal (Figure 4.19).
Let the two-particle interaction be given by a Lennard-Jones potential as in (4.59).
Compute the equilibrium distances r S and r H and consider
(i) Only nearest neighbors (blue),
(ii) Also next nearest neighbors (red),
(iii) Also next-next nearest neighbors (green).
4.6 Chaos
As it already discussed in Chapter 3 but in even more pronounced examples in the two
previous sections of the present chapter, chaotic behavior is more the rule than the
exception if the phase space possesses enough dimensions. Chaotic trajectories may
appear both in conservative (Section 3.3, 4.4.3, 4.4.4) and in dissipative systems (Sec-
tion 3.2.7, 4.5). For Hamiltonian systems, initial conditions normally play a decisive
role. For closely neighbored initial values, qualitatively different behaviors very often
emerge, such as periodic, quasiperiodic, or chaotic; see for instance Figure 4.13. For
a dissipative system, typically the initial conditions play a minor role and are ‘forgot-
ten’ after a certain, by friction effects defined, relaxation time (there are exceptions:
a trajectory starting, e.g., close to a stable fixed point or limit cycle, will stay close
and stationary or periodic behavior will persist. However, this does not exclude more
involved or even chaotic behavior for trajectories starting in another region of state
space).
dy i
= f i (y1 , y2 , . . . y N ) , y i (0) = a i , i = 1...N , (4.75)
dt
where friction is included (dissipative systems, no energy conservation). Let us begin
with the harmonically driven nonlinear mathematical pendulum in 2D phase space
ẏ 1 = y2
ẏ 2 = −α y2 − Ω20 sin y1 + A cos y3 (4.77)
ẏ 3 = ω .
SUBROUTINE pendulum_deq(rhside,y,t)
REAL, DIMENSION(3) :: rhside,y
COMMON /PARAM/ alpha,omega0,a,omega
rhside(1)=y(2)
rhside(2)=-alpha*y(2)-omega0**2*SIN(y(1))+a*COS(y(3))
rhside(3)=omega
END
Clearly the last equation in (4.77) can be immediately integrated and one may just as
well (and with less effort) work with the nonautonomous original system:
rhside(1)=y(2)
rhside(2)=-alpha*y(2)-omega0**2*SIN(y(1))+a*COS(omega*t)
However, the following considerations are valid only for autonomous systems and we
shall resort to (4.77).
4 4
2 2
0 0
–2 –2
–4 –4
–2 0 2 –2 0 2
Fig. 4.20: Chaos for the driven pendulum. Left: phase space, y 2 over y 1 ; right: Poincaré section,
intersection points with the planes y 3 = 3π/2 + 2nπ. A = 1, ω = 0.8, Ω0 = 1, α = 0.1.
4.6 Chaos | 97
Fig. 4.21: Near a separatrix, tiny effects due to the driving force may turn into qualitatively different
behavior. Solid: without external driving; dashed: possible trajectories with external force.
In the left frame of Figure 4.20 a chaotic trajectory is shown in phase space (y1 , y2 ).
The existence of a separatrix of the nondriven system is an important though not nec-
essary ingredient for the emergence of chaos. If the trajectory comes close to the sepa-
ratrix, a suitable phase and amplitude of the driving force can push the phase point to
the other side of the separatrix, and the motion then changes qualitatively, here from
oscillation to rotation (Figure 4.21).
0.1
–0.1
–0.2
–0.3
0.9 1 1.1 1.2 1.3 1.4
2.5
1.5
0.5
0
0.9 1 1.1 1.2 1.3 1.4
Fig. 4.22: Top: the two nontrivial Lyapunov exponents for the driven pendulum with friction. Param-
eters same as in Figure 4.20. Bottom: bifurcation diagram for the driven pendulum, ordinate: |y 1 | at
ωt = 3π/2 + 2nπ, abscissa: A.
Let y⃗ (0) (t) be a numerically determined solution of (4.75). We ask for its stability by
performing a linear stability analysis:
Contrary to the linearization around a fixed point, the Jacobi matrix depends now on
time
⃗
d u(t)
= L(t) u(t) ⃗ (4.78)
dt
with
∂f i
L ij (t) =
∂y j y⃗ (0) (t)
.
Due to the linear character of (4.78) one may assume that for large times, exponential
behavior emerges
⃗
|u(t)| ∼ h(t)e σt , t → ∞
with a bounded h(t). Then the sign of σ
1
σ = lim ⃗
ln |u(t)| (4.79)
t→∞ t
4.6 Chaos | 99
classifies the stability of y⃗ (0) . For σ > 0 arbitrarily small deviations will grow expo-
nentially over the course of time, the trajectory is unstable, and chaotic behavior is
encountered. The σ defined as (4.79) is called the largest Lyapunov exponent.
How can we compute σ? One nearby possibility is to integrate (4.78) numerically
and evaluate (4.79) for large t. However, due to the exponential increase of |u|⃗ for a
positive σ this is not practical since a numerical overflow would soon occur.
u(t) ⃗
⃗ = Q(t, 0) u(0) . (4.80)
⃗
As a matter of fact, u(t), ⃗
and therefore σ, depends on u(0). Thus one finds as many
different Lyapunov exponents as the number of possible linearly independent initial
conditions, namely N, the dimension of the state space. Often it is sufficient to know
the largest σ because it distinguishes between chaotic and regular dynamics. Since
u(t) ⃗
⃗ = Q(t, t − ∆T) Q(t − ∆T, t − 2∆T) . . .Q(∆T, 0) u(0) .
we obtain
u⃗ k = Q k Q k−1 . . .Q1 u⃗ 0 (4.81)
where k = t/∆T. Taking a small enough ∆T avoids an overflow at a single step
u⃗ k = Q k u⃗ k−1 .
Q1 û 0 = d0 d1 Q k Q k−1 . . . ⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟
u⃗ k = d0 Q k Q k−1 . . . Q 2 ⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟ Q2 û 1 = d0 d1 . . .d k û k .
= û 1 d1 = û 2 d2
d1
d4
d2
û1
d0
û0 û4
û2 û3
d3 y(0) (t)
t = Tv t = Tv + ΔT t = Tv + 2ΔT t = Tv + 3ΔT
Fig. 4.23: Numerical computation of the largest Lyapunov exponent. After a constant time interval
the absolute value of the deviation d k is determined. Then the deviation is normalized to one with-
out changing its direction.
1 k
σk = ∑ ln dℓ (4.83)
k∆T ℓ=0
and with k ≫ 1
1
∆σ = σ k+1 − σ k ≈ ln d k+1 .
k∆T
4.6 Chaos | 101
Obviously, ∆σ ∼ 1/k converges with k → ∞. The sum in (4.82) can be truncated if the
error |∆σ| reaches a fixed lower bound. Alternatively the relative error
∆σ
< ϵrel
σ k
can be used as a truncation criterion.
An N-dimensional system possesses N Lyapunov exponents, also called Lya-
punov spectra. The above described method provides the largest one. This is easy to
understand if we decompose the deviation u(t) ⃗ for t → ∞ in the base v̂ k , built by the
̂
N different u 0 :
⃗ = c1 v̂ 1 eσ1 t + . . .c N v̂ N eσ N t ,
u(t)
where σ k denotes now the ordered Lyapunov spectrum according to
σ1 ≥ σ2 ⋅ ⋅ ⋅ ≥ σ N .
The constants c k are determined by the initial value u(0).⃗ As time goes on u⃗ will orient
parallel to v̂ 1 , independently from the initial conditions. However, if c1 would exactly
vanish one would expect u⃗ parallel to v̂2 , etc. In this way one could at least in principle
obtain the complete spectrum, what, however, cannot work in practice. Numerically
there is always a tiny component in the direction v⃗ 1 that increases exponentially fast
and dominates the deviations after a certain time ∼ 1/σ 1 . We shall see below how the
complete spectrum can be found anyway. But first let us prove an important theorem.
4.6.3.2 Theorem: one Lyapunov exponent vanishes for all trajectories that do not
terminate at a fixed point
We further assume bounded systems with
⃗
|y(t)| ≤ D1 , ̇⃗
|y(t)| = |f ⃗(y(t))|
⃗ ≤ D2 , Di > 0
and show the simple proof of the theorem. Differentiating (4.75) yields
N N
∂f i
ÿ i = ∑ ẏ j = ∑ L ij ẏ j ,
j
∂y j j
from where it follows that with u⃗ = ẏ⃗ the time derivative of each solution of (4.75)
also provides a solution of the linear system (4.78). In particular this is valid for the
reference trajectory y⃗ (0) (t) itself, i.e., the deviation points always tangential to the tra-
jectory (Figure 4.24). This special (marginal) Lyapunov exponent holds with (4.79) as
1 1
σ m = lim ln |ẏ⃗ (0) (t)| ≤ lim ln |D2 | = 0 , (4.84)
t→∞ t t→∞ t
and therefore
σm ≤ 0 .
102 | 4 Ordinary differential equations I
û1
û0 û4
û2
û3
y(0) (t)
Fig. 4.24: A deviation pointing in the direction of the reference trajectory has a vanishing Lyapunov
exponent if the trajectory does not terminate at a fixed point.
one arrives at
|ẏ⃗ (0) (t)| = 0 , t→∞
and the trajectory would end at a fixed point. Therefore, if the trajectory does not ter-
minate at a fixed point as assumed, the only possibility remaining is
σm = 0 .
σ 1 = σ (1)
σ 2 = σ (2) − σ (1) (4.86)
(N) (N−1)
σN = σ −σ .
4.6.3.4 Classification
If all first-order exponents are known, the reference trajectory y⃗ (0) (t) can be classified
(Table 4.1). In particular, a positive Lyapunov exponent denotes the divergence of the
4.6 Chaos | 103
σ1 σ2 σ3
− − − trajectory terminates at a fixed point
0 − − stable limit cycle (periodic dynamics)
0 0 − stable torus (quasiperiodic dynamics)
+ 0 − strange attractor (chaotic dynamics)
trajectories. If, however, the dynamics is bounded on a finite region in state space,
contractions must also be present and at least one of the Lyapunov exponents must
be negative.
An N-dimensional volume element V N (t) whose corners move along trajectories
in state space is contracted in the temporal average if the system is dissipative; see
Section 3.2.3. For the sake of simplicity let us first assume div f ⃗ = c with c < 0 and c as
constant. From (3.23) follows
V N (t) = V N (0) e ct
and with (4.85),
N
σ (N) = ∑ σ k = c = div f ⃗ = Tr L . (4.87)
k=1
The sum over all Lyapunov exponents corresponds to the divergence of f (or the trace
of the Jacobi matrix L) and is negative for a dissipative system. Hence it follows also
that at least one Lyapunov exponent must be less than zero. Thus, for a three-dimen-
sional state space all possible combinations are listed in Table 4.1. But in general, div f ⃗
is not a constant. Then one can still compute the average and
N t
1
σ (N)
= ∑ σ k = lim ∫ dt div f ⃗ (4.88)
t→∞ t
k=1 0
holds, an expression being also negative for dissipative systems. For the example of
the damped pendulum one obtains
3
σ (3) = ∑ σ k = −α .
k=1
For Hamiltonian systems the equations of motions have canonical form (see Sec-
tion 3.3) and div f ⃗ = 0 results. The sum over all Lyapunov exponents vanishes.
in more or less one direction, namely in that assigned to the largest Lyapunov expo-
nent. This can be avoided if the spanning vectors are orthogonalized repeatedly after
certain time intervals, applying a Gram–Schmidt procedure for instance.
We demonstrate the algorithm for the three-dimensional state space, N = 3:
1. Select three orthonormal unit vectors û 1 , û 2 , û 3 , (û i ⋅ û j ) = δ ij , t = 0, ℓ = 0.
2. Integrate (4.78) from t through t + ∆T:
w⃗ i = Q(t + ∆T, t) û i
(p)
3. Compute the volumes Vℓ , which are spanned by w⃗ 1 . . . w⃗ p :
(p)
Vℓ = √| det V|
with the help of the p × p matrix
N
(i) (j)
V ij = ∑ w n w n
n
(i)
and w k as the kth component of the vector w⃗ i .
4. Using a Schmidt–Gram method, determine the next orthogonal set û i in such a
way that the first p vectors û i span the subspace defined by w⃗ 1 till w⃗ p :
w⃗ 1
û 1 = ,
|w⃗ 1 |
u⃗ 2
u⃗ 2 = w⃗ 2 − c12 û 1 , û 2 = , c12 = û 1 ⋅ w⃗ 2 ,
|u⃗ 2 |
u⃗ 3
u⃗ 3 = w⃗ 3 − c13 û 1 − c23 û 2 , û 3 = , c13 = û 1 ⋅ w⃗ 3 , c23 = û 2 ⋅ w⃗ 3
|u⃗ 3 |
5. t := t + ∆T, ℓ := ℓ + 1
6. If ℓ < k go to 2.
7. After sufficiently many steps (large k) the Lyapunov exponent of the order p can
be computed:
1 k (p)
σ (p) = ∑ ln Vℓ
k∆T ℓ=1
and from there according to (4.86) finally the whole spectrum σ 1 . . .σ N .
The subroutine dlyap_exp implementing the steps explained above is described in the
Appendix B.
Due to the last equation (4.77) there are no fixed points and at least one Lyapunov
exponent must vanish. Because of the simple structure of (4.89) we can make some
analytic conclusions. From the third line it follows immediately
u̇ 3 = 0 , u 3 = const.
(0) (0)
For small A we may assume self-consistently |y1 |, |y2 | ∼ A and linearize
(0)
cos y1 ≈ 1 . (4.90)
In particular for u 3 = 0 the two equations for u 1 , u 2 are equivalent to the damped
pendulum having the solutions
α
|(u 1 , u 2 )| ∼ h i (t) exp (− ) , i = 1, 2
2
where h i (t) is an oscillating bounded function. With (4.79) one finds the two Lyapunov
exponents
σ 2 = σ 3 = −α/2 .
Putting u 3 = 1, the two equations for u 1 , u 2 correspond to the driven harmonic oscil-
lator. The long-time behavior turns out to be
y1 ∼ sin(ωt + β) ,
providing σ 1 = 0. Therefore, for small A the solution y⃗ (0) (t) is a stable limit cycle
(Table 4.1).
–0.05
–0.1
1.5
0.5
0
0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8
Fig. 4.25: Lyapunov exponents and bifurcation diagram for the driven pendulum with friction; pa-
rameters as in Figure 4.20.
106 | 4 Ordinary differential equations I
For larger A the linearization (4.90) is invalid, the limit cycle becomes unstable, and
eventually chaotic trajectories emerge. Figure 4.25 shows numerical results for smaller
A, while Figure 4.22 shows those for larger values.
Code. In the code published on the website, instead of the original three-dimensional
autonomous system (4.77), the equivalent two-dimensional nonautonomous system
ẏ 1 = y2
(4.91)
ẏ 2 = −α y2 − Ω20 sin y1 + A cos ωt
0 1
L(t) = ( (0) ) (4.92)
−Ω20 cos y1 (t) −α
and only two Lyapunov exponents exist. The one vanishing for the 3D-system does
not occur (the theorem Section 4.6.3.2 is only valid for autonomous systems).
one finds
1 L
t∗ = ln ( )
σ1 ∆ϵ(0)
for the so-called Lyapunov time.
Depending on atmospheric conditions, for the weather forecast, t∗ lies in the re-
gion between only a few hours up to a maximum of two weeks. Studying the Centen-
nial Calendar or similar products is therefore proven useless.
Initiated by the Euclidean notion of dimension and analogue to the concept already
discussed in Section 2.4.1, we may assign a dimension to an object in state space.
A fixed point has the dimension d = 0, a limit cycle d = 1, a torus d = 2, etc. As it
4.6 Chaos | 107
2<d<3.
−π ≤ y1 ≤ π , −3.5 ≤ y2 ≤ 3.5 , 0 ≤ y3 ≤ 2π
is thereby covered with n3 cubes, where n runs through the powers of two n =
2, 4, 8, 16 . . . 512. For each n, M is determined and plotted as a function of the edge
length L in Figure 4.26. It turns out that in the chaotic regime the dimension is only
weakly larger than two. Hence, based on the fractal dimension alone one may hardly
distinguish between a chaotic attractor and a quasiperiodic motion.
Finally, Figure 4.27 depicts d K in a wide region of A. But also here, d K only slightly
exceeds values of two whenever chaos emerges.
The set can be the result of a numerical solution of an ODE but could also originate
from some series of measurements, e.g., temperature depending on time at N different
places, etc.
108 | 4 Ordinary differential equations I
10
A = 1.0
log (M)
5
A = 0.4
1 2 3 4 5 6
−log (L)
Fig. 4.26: Fractal dimension (slope) found with the box-counting method, called capacity dimension.
Driven pendulum, Ω0 = 1, α = 0.1, ω = 0.8, A = 0.4 (dots), A = 1.0 (squares). For A = 0.4 one
obtains d K ≈ 1.04; for A = 1.0 a dimension d K ≈ 2.01.
1.8
1.6
1.4
1.2
1
0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4
Fig. 4.27: Fractal dimension of the driven pendulum in the domain 0.4 ≤ A ≤ 1.4, parameters as in
Figure 4.20. The regions where d K ≈ 2 agree well with the chaotic regions of Figure 4.22.
The correlation dimension is computed by determining for each point the number of
neighbor points within the distance ≤ R:
18
16
ln C(R)
14
12
Fig. 4.28: Correlation dimension (slope) for the
–2 –1 –0 1 driven pendulum, Ω0 = 1, α = 0.1, ω = 0.8.
ln R Chaotic attractor at A = 1, d C ≈ 2.12.
C(R) ∼ R d
with d the dimension of the object where the data points are located. This can be illus-
trated for N = 3: if the points fill the space uniformly their number is proportional to
the volume of the sphere with radius R resulting in d = 3. If the points lie on a plane
one finds C(R) ∼ R2 and d = 2 and for a line d = 1.
Taking a small enough R, this is the definition of the correlation dimension:
ln C(R)
d C = lim . (4.93)
R→0 ln R
One obtains d C by plotting C over R in a log-log scale as the slope (Figure 4.28). How-
ever, the slope is not constant and as already discussed in Section 2.4.1, the question
is where to evaluate it. For R too small the curve flattens because too few points lay
inside the sphere to do a statistical evaluation. For too large R the slope also decreases
since the attractor has a finite extension (for the pendulum of the order 2π).
One may come to the position to analyze a one-dimensional collection of data, a time
series of a certain magnitude Y(t):
Y0 , Y1 , Y2 , . . .Y P−1 , Y n = Y(n∆t) .
But even without knowing the dimension N of the state space where the system
that produced the series lives, a fractal dimension can be determined. However, for
110 | 4 Ordinary differential equations I
a complex system, N can be quite large. If the data points are completely uncorre-
lated (e.g., the results of a coin toss), the series cannot be embedded at all in a finite-
dimensional state space and one expects N → ∞.
To reconstruct an attractor, we first unfold the series into a space with some given
dimension N , called embedding dimension. To this end we choose a certain time in-
terval ∆T, the delay rate, which is normally much larger than ∆t. Let
K = ∆T/∆t ≫ 1
y1 (t k ) = Y k
y2 (t k ) = Y k+K
y3 (t k ) = Y k+2K
..
.
y N (t k ) = Y k+(N −1)K
all P − (N − 1)K vectors of dimension N that can be used to determine the correlation
dimension as described above.
How large should we take N ? No intersections of the trajectory should be certainly
assured. F. Takens⁴ was able to prove in 1981 the following theorem [8]:
If a deterministic system generates an N-dimensional flow y:⃗
d y⃗
= f ⃗(y)⃗ ,
dt
then
x1 = y i (t) , x2 = y i (t + ∆T) , ... x2N+1 = y i (t + 2N∆T)
represents a continuously differentiable embedding, where y i can be any component
i = 1. . .N of y.⃗
Thus the dimension of an attractor is conserved if
N ≥ 2N + 1 .
In practice one has to increase N step by step until the fractal dimension computed
for consecutive N converges.
The Floquet⁵ theorem is equivalent to Bloch’s theorem in solid state physics and
applies for explicitly time-dependent linear ODEs of the form (4.78), but for a time-
periodic system matrix L(t):
L(t) = L(t + T) .
As already done in (4.80) we may introduce a time-evolution operator C:
⃗
u(T) ⃗
= C(T) u(0) , (4.94)
now developing u⃗ for one period T. This special operator is also called monodromy
matrix. Let w⃗ k be the eigenvectors of C
C w⃗ k = σ k (T) w⃗ k . (4.95)
But since
(σ k (T)) n = σ k (nT)
one immediately finds
σ k = exp(λ k T) . (4.96)
The σ k are named Floquet multipliers, while the λ k are the Floquet exponents.
Next we assume that the w⃗ k represent a complete base in N-dimensional state
space. Thus we may expand
N
⃗ = ∑ a k (t) w⃗ k e λ k t .
u(t) (4.97)
k
Applying C yields
N N
⃗ = ∑ a k (t) C w⃗ k eλ k t = ∑ a k (t) σ k w⃗ k eλ k t
C u(t)
k k
N
!
= ∑ a k (t) w⃗ k eλ k (t+T) = u(t
⃗ + T) . (4.98)
k
a k (t) = a k (t + T) .
Hence the expansion coefficients in (4.97) are periodic in t with the period T. We have
derived the Floquet theorem that summarizes as:
The solution of
̇⃗ = L(t) u(t)
u(t) ⃗ with L(t) = L(t + T) (4.99)
has the form
N
⃗ = ∑ q⃗ k (t) exp(λ k t) ,
u(t)
k
where q⃗ k are periodic functions
q⃗ k (t) = q⃗ k (t + T) .
The Floquet exponents λ k can be computed from the eigenvalues σ k of the monodromy
matrix C(T) with (4.96)
1 1 1 iα k
λk = ln σ k = ln |σ k |eiα k = ln |σ k | + . (4.100)
T T T T
Inserting
⃗ = y⃗ (0) (t) + u(t)
y(t) ⃗
and linearizing (4.75) with respect to u⃗ leads to a problem as (4.99) for the small de-
⃗
viations u(t). If one of the Floquet exponents has a positive real part the deviations
will grow exponentially and the limit cycle (4.101) will be unstable. The condition for
stability thus reads
|σ k | ≤ 1 for all k .
As an application we study the excited pendulum sketched in Figure 4.29. The pivot
oscillates with A sin ωt in the vertical direction, leading to an apparent force that can
be included in (4.4) by the substitution
Aω2
g → g(1 + a sin ωt) , a= .
g
4.7 ODEs with periodic coefficients | 113
A sin ωt
ẏ 1 = y2
ẏ 2 = −Ω20 (1 + a sin y3 ) sin y1 (4.102)
ẏ 3 = ω .
Contrary to (4.77) the time-dependence is now multiplicative and the two fixed points
for the undriven case persist in the (y1 , y2 )-plane. The lower rest position is simply
given by
(0) (0) (0)
y1 = y2 = 0 , y3 = ωt .
Linearizing around the lower rest position leads to
u̇ 1 = u 2
u̇ 2 = −Ω20 (1 + a sin ωt) u 1 (4.103)
u̇ 3 = 0 .
u̇⃗ = L u⃗ (4.104)
with
u⃗ = (u 1 , u 2 )
and
0 1
L(t) = ( 2 ) . (4.105)
−Ω0 (1 + a sin ωt) 0
The system (4.104) has the form (4.99) with
2π
T= .
ω
To determine the Floquet exponents we must first compute the monodromy matrix. To
this end we take two orthogonal initial conditions
and numerically integrate (4.104) with (4.105) for each u⃗ i until t = T. In this way we
find u⃗ i (T). On the other hand, due to (4.94) one obtains
and the vectors u⃗ i (T) form the columns of C. Now we can compute the eigenvalues σ 12
according to:
1 1
σ 12 = Tr C ± √(Tr C)2 − 4 Det C (4.107)
2 2
and from there with (4.100) also the Floquet exponents. The relation (4.88) or (4.87)
holds also for the sum of all the Floquet exponents and from Tr L = 0 it follows
λ1 + λ2 = 0 . (4.108)
The fixed point y⃗ (0) is stable (center). The loci in parameter space (a, ω) where two
real-valued solutions of (4.107) turn into a complex-conjugate pair are found from
The two first-order ODEs (4.104) with (4.105) are equivalent to one ODE of the second
order, the so-called Mathieu⁶ equation:
10 4
8
3
6
2
b
b
4
1
2
0 0
–5 0 5 10 15 20 –4 –3 –2 –1 0
p p
Fig. 4.30: Left: stability chart for the Mathieu equation (4.111). Black: λ1 = λ2 = 0, stability limits,
red: λ k real valued, unstable; blue: λ k = ±iα, stable. Right: blow-up of the dashed area for negative
p: the upper rest position is stable in the small wedge between the black lines.
and
4Ω20 2Ω20
p=
, b = a. (4.112)
ω2 ω2
As described above we determine the stability regions of the lower fixed point by com-
puting the monodromy matrix for certain parameters p, b:
C = C(p, b) .
are plotted in a parameter plane; Figure 4.30, left frame, shows the result. At the res-
onances
p = n2 , n = 1, 2, . . . (4.113)
arbitrarily small amplitudes b are sufficient to destabilize the pendulum, so the oscil-
lations grow exponentially. Inserting p = n2 into (4.112), one finds for the resonances
the ratio
Ω0 n
=
ω 2
between the eigenfrequency of the pendulum and the driving frequency. Interestingly
enough one obtains even for a negative p a tiny region with imaginary Floquet ex-
ponents; see Figure 4.30, right frame. But negative p corresponds to a linearization
around the unstable, upper fixed point of the pendulum, y1 = π. If b is chosen appro-
priately, the pendulum can be kept stable in its top position.
116 | 4 Ordinary differential equations I
4.7.5 Problems
Derive an equation of the form (4.111) for the deviations y1 = π + u(t). What is the
difference from (4.111)?
Show with the equation
u(t) = u 0 cos(t + α) e λt ,
that the pendulum may be stabilized in the upper position. Neglect higher har-
monics and use the approximation
1 1
sin 2t cos(t + α) = ( sin(t − α) + sin(3t + α)) ≈ sin(t − α) .
2 2
Which condition holds for λ to stabilize the upper rest position?
2. Examine the damped Mathieu equation
numerically. Plot the stability regions in the q-b-plane for given α > 0. What
changes qualitatively in Figure 4.30?
Bibliography
[1] J. Laskar, Large-scale chaos in the solar system, Astron. Astrophys. 287, L9 (1994).
[2] J. Laskar and M. Gastineau, Existence of collisional trajectories of Mercury, Mars and Venus with
the Earth, Nature 459, 7248 (2009).
[3] FORTRAN codes at http://www.degruyter.com/books/978-3-11-051513-8
[4] A. Rahman, Correlations in the Motion of Atoms in Liquid Argon, Phys. Rev. 136, A405 (1964).
[5] J. M. Thijssen, Computational Physics, Cambridge Univ. Press (2007).
[6] J. L. Lebowitz, J. K. Percus and L. Verlet, Ensemble Dependence of Fluctuations with Application
to Machine Computations, Phys. Rev. 153, 250 (1967).
[7] J. Argyris, G. Faust, M. Haase and R. Friedrich, An Exploration of Dynamical Systems and Chaos,
Springer (2015).
[8] F. Takens, Dynamical Systems and Turbulence, Lect. Notes in Math. Vol. 898 (1981).
5 Ordinary differential equations II,
boundary value problems
5.1 Preliminary remarks
https://doi.org/10.1515/9783110515145-005
118 | 5 Ordinary differential equations II
(0) (0)
A mass point starts at (x, y) = 0 with a certain given velocity v⃗ (0) = (v x , v y ) in a
constant gravity field and lands after a certain time t = T at x(T) = L, y(T) = 0. The
equations of motion read
ẍ = −α ẋ + β y
(5.4)
ÿ = −α ẏ − g ,
where speed-dependent friction α as well as a linearly, height-increasing horizontal
wind force (shear flow, β) are included. If α = β = 0, the trajectory is a parabola
(0) 1 2 (0)
y(t) = v y t − gt , x(t) = v x t
2
or
(0)
vy g
y(x) = (0)
x− x2
vx (0) 2
2 (v x )
with
(0) (0) (0)
2v y 2v x v y
T= , L= . (5.5)
g g
(0) (0)
̇
Given the initial conditions x(0) = 0, y(0) = 0, x(0) ̇
= v x , y(0) = v y , the solution
x(t), y(t) as well as the flight time T and the landing point L follow uniquely. This
of course is a classical initial value problem. How can we formulate it as a boundary
value problem? We seek a solution of (5.4) fulfilling the boundary conditions
for a given T (parameter). Hence the mass point should arrive after a given flight time
(0) (0)
T at the given place x = L. From (5.5) we find v y = g T/2 and v x = L/T or
1 L
y(t) = g t (T − t) , x(t) = t. (5.6)
2 T
But what to do if (5.4) looks a bit more involved (nonlinear wind or friction forces,
(0) (0)
etc.) and can be only solved numerically? One could iteratively try values for v x , v y
in such a way that the trajectory ended after t = T in (L, 0). This is the idea behind the
so-called shooting method to which we shall come back in more detail in Section 5.5.
As already done for initial value problems one can express the derivatives by the help
of differential quotients resulting in an algebraic system, the discretized equations.
5.2 Finite differences | 119
5.2.1 Discretization
We demonstrate the method with the example of the ballistic flight in Section 5.1.2.
At first we divide the axis 0 ≤ t ≤ T with equidistant mesh points
2 1 α 1 α
A ii = − , A i,i+1 = + , A i,i−1 = − (5.10)
∆t2 ∆t 2 2∆t ∆t 2 2∆t
and
a i = −g .
The boundary conditions read
x0 = y0 = 0 , xn = L , yn = 0
and have to be incorporated into the system (5.8, 5.9). Since A1,0 = 0, the points on the
left side are already included in the first equations (i = 1). On the right side (i = n − 1)
the last equation of (5.9) yields
The results for only 10 mesh points (in practice one would use much more) is shown
in Figure 5.1 for several values of α and β. A, however, more involved analytical solu-
tion can be even found for the case α, β ≠ 0 (see Problems), which is also shown in
the figure. The finite difference scheme provides a quite exact result even for a small
number of mesh points. Due to the approximations in (5.7) the discretization error is
∼ ∆t or ∼ 1/n.
The central task concerning this problem is the inversion of matrices, thus an im-
plementation using MATLAB seems to be nearby. For demonstration we list the pro-
gram including a graphical evaluation:
clear;
n=100; tend=1; g=9.81; xl=1;
alpha=[0.5,3,5.5]; beta=[-5,-2.5,0];
dt=tend/(n-1); dt2=dt^2; k=0;
for i=1:3
for j=1:3
a=(1/dt2-alpha(j)/2/dt)*ones(n,1); ! matrix elements
b=(1/dt2+alpha(j)/2/dt)*ones(n,1);
m=spdiags([b,a],[-1,1],n,n)-2/dt2*speye(n);
5.2 Finite differences | 121
1
1
1
0.5
0.5 0.5
1
1
1
0.5
0.5 0.5
1
1
1
0.5
0.5 0.5
Fig. 5.1: The ballistic flight, numerical solutions of (5.4) for 10 mesh points (circles) compared to the
exact solution (solid), L = 1 m, T = 1 s.
inh(1:n)=-g; ! inhomogeneity
y=inh/m; ! inversion y
inh=beta(i)*y;
inh(n)=inh(n)-xl*m(n,n-1);
x=inh/m; ! inversion x
k=k+1;
subplot(3,3,k); plot(x,y); ! plot
end
end
One of the standard problems of quantum mechanics is solving the Schrödinger equa-
tion [2]
ℏ2 ∂
[− ∆ + U(r,⃗ t)] Ψ(r,⃗ t) = iℏ Ψ( r, t) (5.11)
2m ∂t
for a certain given potential U(r,⃗ t). This is a partial differential equation that can be
transformed into an ODE for the special case of only one spatial dimension, say x, and
a time-independent potential U = U(x). Doing the separation
Ẽ
Ψ(x, t) = Φ(x) exp (−i t) ,
ℏ
̂ n = En φn
Hφ
where E n denote the eigenvalues and φ n (x) the eigenfunctions of the differential op-
erator (Hamiltonian)
d2
Ĥ = − 2 + V(x) .
dx
Discretizing (5.12) leads to a homogeneous algebraic eigenvalue problem of the
form:
∑ H ij Φ j = E Φ i (5.13)
j
which vanishes for all k due to symmetry reasons. Thus, the change of the spectrum
is at least of the second order, ∼ V02 and named the quadratic Stark effect.
For a direct numerical solution one has to find the eigenvalues and eigenvectors
of the problem (5.13-5.15) with
L
V(x i ) = V0 ⋅ (i∆x − L/2) , i = 1...n , ∆x = .
n+1
Here, i = 0 corresponds to the left, i = n + 1 to the right wall and H has the form of an
n × n tridiagonal matrix. Figure 5.2 depicts the probability densities |Φ(x)|2 for the first
three states and several values of V0 . It turns out that for increasing V0 the probability
densities are shifted more and more to the left where the potential is minimal.
To compute the eigenvalue problem the LAPACK routine SSTEQR (real-valued,
symmetric tridiagonal matrix) can be used:
...
xl=1. ! length L=1 of the well
dx=xl/FLOAT(n+1)
DO i=1,n
dl(i)=-1./dx**2 ! matrix elements
di(i)=2./dx**2 + v0*(FLOAT(i)*dx-xl/2)
ENDDO
CALL SSTEQR('i',n,di,dl,z,n,work,info)
c .. eigenvalues in di, eigenvectors in z
c .. z(1:n,k) belongs to di(k)
.. output, plot, etc
124 | 5 Ordinary differential equations II
Fig. 5.2: Numerical solutions of the stationary Schrödinger equation with (5.16). Shown in
each frame are the first three states (probability densities |Φ|2 ) (solid, thin, dashed) for
V 0 = 0, 300, 1000, 5000 (from left to right), L = 1, n = 1000.
100
50
–50
0 200 400 600 800 1000
The first three eigenvalues as a function of V0 are shown in Figure 5.3. All energies de-
crease for large V0 . Then also the higher states are localized in the region of a negative
energy (left).
Since this code again is mainly based on matrix computation we present here the
complete MATLAB code producing Figure 5.2:
5.2 Finite differences | 125
clear;
n=1000; v0=[0,300,1000,5000];
dx=1/(n+1); dx2=dx^2;
x=-.5+dx:dx:0.5-dx;
a=-1/dx2*ones(n,1);
for k=1:4
b=2/dx2*ones(n,1)+v0(k)*x';
m=spdiags([a,b,a],[-1,0,1],n,n);
[v,e]=eigs(m,3,'sr');
subplot(1,4,k);
plot(x,v(1:n,1).^2,x,v(1:n,2).^2,x,v(1:n,3).^2);
end
with
Ω0 = ω0 m/ℏ .
The problem belongs to the few ones in quantum mechanics that can be solved exactly.
One finds the equidistant eigenvalues, the energy levels¹
Eex
k = Ω 0 (1 + 2k) , k = 0, 1, . . .
and for the eigenfunctions, the Hermitian polynomials. Anyway we shall describe first
a numerical solution and will later generalize the quadratic potential to a nonlinear
spring. A new complication in solving (5.17) arises from the asymptotic boundary con-
ditions
lim Φ(x) = 0 ,
x→±∞
saying that the x-region is in fact infinite. In practice one can choose the x-interval
still finite but large enough to ensure an almost vanishing wave function at its borders
x = ±L/2, leading to the boundary conditions
1 Doing the rescaling, we of course arrive at the more familiar relation E k = ℏω0 ( 12 + k).
126 | 5 Ordinary differential equations II
0.8
0.6
0.4
0.2
0
–15 –10 –5 0 5 10 15
Fig. 5.4: The first three eigenfunctions |Φ|2 together with the 50th for the harmonic oscillator,
L = 30, Ω0 = 1, 1000 mesh points.
Hence we are again in the position to solve the problem of an infinitely high poten-
tial well, but now with an additional quadratic potential inside. We can resort to the
same program written for the Stark effect and must only adjust the potential. The ap-
propriate value for L can be found by trial and error. Figure 5.4 depicts the first three
probability densities as well as the 50th. One should respect that the spatial exten-
sion of the wave functions increase with k, see Section 5.2.2.4 below. To compute the
higher states correctly L should be large enough. Table 5.1 notes the computed energy
values together with the exact ones. The relative errors stay well below one percent.
The number of mesh points has been chosen with n = 1000 for the whole interval.
Tab. 5.1: Energy levels of the harmonic oscillator; finite difference method compared to the exact
values.
0 0.999717832 1 −2.82168388E-04
1 2.99929714 3 −2.34285995E-04
2 4.99920225 5 −1.59549716E-04
3 6.99843979 7 −2.22887305E-04
4 8.99729633 9 −3.00407410E-04
5 10.9976883 11 −2.10155136E-04
6 12.9952221 13 −3.67531407E-04
7 14.9935150 15 −4.32332366E-04
8 16.9906712 17 −5.48755401E-04
9 18.9886627 19 −5.96698956E-04
... ... ... ...
49 96.7354813 97 −2.72699725E-03
5.2 Finite differences | 127
300
p=4
200 p=3
Ek
100 p=2
p = 3/2
0
0 20 40 60 80 100
k
Fig. 5.5: The first 100 energy levels for different potentials (5.19).
Φ = γ(x) Φ
1 + 2k
xL = √ ,
Ω0
in very good agreement with Figure 5.4.
128 | 5 Ordinary differential equations II
The keynote of the weighted residual methods (WRMs) is to solve ODEs of the form
̂ x )y(x) = b(x)
L(d (5.20)
̃ 1 , a2 , . . . a N , x) ,
y = y(a (5.21)
where ỹ is called a test function. The N free parameters a k are determined in a way
that the residuum (the remainder)
R(x) = L̂ ỹ − b ,
If the number of the weight functions M is equal to the number of parameters N, the a k
can be determined from the N equations (5.22).
In particular we wish to examine in this section linear differential operators L̂ and
in a k linear test functions (5.21) of the form
N
̃
y(x) = ∑ a i φ i (x) (5.23)
i=1
with linearly independent base functions φ i (x). Then (5.22) turns into the linear sys-
tem
N
∑ L ij a j = b i (5.24)
j=1
̂ x )φ j (x) ,
L ij = ∫ dx w i (x)L(d b i = ∫ dx w i (x) b(x) .
X X
For a nonlinear operator L,̂ instead of (5.24), a nonlinear algebraic system for the set
a k would result, which can be only solved iteratively.
Depending on the weight functions, one distinguishes between different WRMs.
We mention the most important ones:
5.3 Weighted residual methods | 129
{1 if x ϵ Dk
w k (x) = {
0 else
{
In this way one can enlarge the accuracy (smaller and more subdomains) of the
method at certain places where the expected solution varies strongly, while in
other ‘quieter’ regions larger subdomains can be appropriate.
2. The collocation method can be considered as a special case of 1. Let each D k
shrink to a point
w k (x) = δ(x − x k )
where δ(x) denotes Dirac’s delta-function. Due to (5.22) one has
R(x k ) = 0
and
̂ x )φ j (x)
L ij = L(d b i = b(x i ) .
x=x ,
i
Due to (5.22) the residuum is orthogonal to the subspace spanned by the base func-
tions. If one further increases N, this subspace is getting more and more complete
leaving less and less space for the residuum. Thus, R(x) must vanish for N → ∞.
130 | 5 Ordinary differential equations II
We wish to compute the ground state and the first excited state of the stationary
Schrödinger equation
corresponding to the Stark effect in an infinitely high potential well with L = 1. Let the
test function be a polynomial of the third degree:
̃
Φ(x) = a0 + a1 x + a2 x2 + a3 x3 .
a0 = 0 , a3 = −a1 − a2 ,
or
Φ̃ = a1 φ1 + a2 φ2
with the two linearly independent base functions
φ1 = x − x3 , φ2 = x2 − x3 .
Contrary to (5.20), the problem (5.27) is homogeneous and instead of (5.24) we obtain
a generalized linear eigenvalue problem of the form
2
∑ (L ij − E M ij ) a j = 0 . (5.28)
j=1
The matrix elements L ij , M ij thereby depend on the method. The two eigenvalues E
are then determined from the solvability condition
Det (L ij − E M ij ) = 0 . (5.29)
40
collocation
E
2000 40 60 80 100
V0
Fig. 5.6: Stark effect, the methods by comparison, energy of the ground state, and the first excited
state over V 0 .
Tab. 5.2: The first two energy levels for V 0 = 0 for the three different methods.
E0 π ≈ 9.87
2
12.0 10.7 10.0
E1 4π 2 ≈ 39.5 48.0 32.0 46.0
V02
E0,1 = 26 ∓ √256 + .
28
Of course the results depend strongly on the applied method. Also note that only two
base functions have been used and more exact results cannot be expected from the
first. Figure 5.6 compares the outcome of the three methods with that of the finite differ-
ence algorithm from Section 5.2.2.1. In Table 5.2 we list the values for the undisturbed
problem V0 = 0.
All three methods provide a quadratic dependence on V0 as well as the correct
sign for the curvature of E. Not surprisingly, the first excited state inaccurately takes
a test function with only two free parameters. On the other hand, the energy of the
ground state agrees amazingly well at least for the Galerkin method. For the two
other methods, additional freedom lies in the choice of the subdomains or collocation
points, respectively.
132 | 5 Ordinary differential equations II
So far we have examined only linear problems of the form (5.20). In this section we
wish to extend the treatment to certain nonlinear systems
̂ nx )y(x) + g(y, d n−1
L(d x y, . . . ) = b(x) (5.30)
where L̂ denotes a linear differential operator and comprises the highest occurring
derivative. The nonlinear function g is at least bilinear in y and/or its derivatives. In-
dependently from the applied algorithm, one arrives after discretization at a nonlinear
system of algebraic equations.
There is no general receipt for solving nonlinear algebraic systems. This can be seen
already at a system of only two equations. Let us seek a solution of
f(x, y) = 0
(5.31)
g(x, y) = 0
with some nonlinear functions f, g of the two variables x, y. Graphically, we can plot
the zero lines of f and g and determine their intersections, as in Figure 5.7. But the two
functions are completely independent on each other. The zeros of each function can
Fig. 5.7: The zero lines of two functions f(x, y) = 0 (solid) and g(x, y)=0 (dashed). The intersections
correspond to the solutions of (5.31). As we can see, many solutions may exist, among them also
‘almost’ solutions and double zeros. A numerical solution found iteratively will surely depend on the
initial value x (0) , y (0) of any iterative scheme.
5.4 Nonlinear boundary value problems | 133
5.4.2 Newton–Raphson
f(x) = 0 (5.32)
iteratively. Let x(0) be an (initial) value not too far from the desired zero x k . In its neigh-
borhood, the Taylor expansion
is therefore valid. The values for f(x(0) ) and d x f at x(0) are given with f(x). From the
requirement
f(x(0) + δx) = 0
we can determine δx:
f(x(0) )
δx = − + O(δx2 ) (5.34)
d x f(x(0) )
and from there the zero
x k ≈ x(0) + δx . (5.35)
Because of the neglect of higher order terms in (5.33) the zero will not be reached ex-
actly and (5.35) provides only an approximate value x̃ k . However, x̃ k will be closer to
the exact zero than the initial value x(0) . Substituting x̃ k in formula (5.34) will yield an
even closer value and so on. Thus, an iteration rule
f(x(i) )
x(i+1) = x(i) − (5.36)
d x f(x(i) )
is obtained, where the sequence x(i) converges against the zero x k . For a stopping cri-
terion one may take
|δx(i) | = |x(i+1) − x(i) | < ϵ
with given accuracy ϵ. If (5.32) possesses many solutions the result will depend on the
initial value x(0) .
The Newton–Raphson method can be generalized straightforwardly to systems
with N equations:
f i (x1 , x2 , . . . x N ) = 0 i = 1 . . . N . (5.37)
134 | 5 Ordinary differential equations II
that can serve as a model of a charged particle in a self-generated charge density cloud,
having the potential
V = γ |Φ2 | .
Taking a real-valued Φ, we obtain
Φ + EΦ − γ Φ3 = 0 . (5.42)
Applying the finite difference method of Section 5.2.2 leads to the algebraic system
N
f i (Φ1 , Φ2 . . . Φ N ) = ∑ L ij Φ j − γ Φ3i = 0 (5.43)
j
∂f i
α ij = = L ij − 3 δ ij γ Φ2i
∂Φ j
E E
Φ(x) = ±√ tanh (√ (x − x0 )) . (5.46)
γ 2
2E 1
Φ(x) = ±√ . (5.47)
γ cosh (√−E (x − x0 ))
Φ Φ
x x
Fig. 5.8: Left: front for E, γ > 0, right: localized wave for E, γ < 0. Both are exact solutions of the NSE.
0.5
0.2
Φ
Φ
0 0
–0.2
–0.5
x x
Fig. 5.9: Two numerically found solutions of the NSE. Left: front four E = 1/2, γ = 1, right: another
solution for E = 1, γ = 1. The left frame corresponds to the exact solution (5.46).
This can be incorporated into the differential matrix (5.44) by modifying the first and
the last diagonal element according to
2 1 1
L11 = L NN = − +E+ 2 =− 2 +E.
∆x2 ∆x ∆x
As the initial value for Φ we can take a straight line Φ = x/L. Depending on parameters
one obtains different solutions where the exact one (5.46) is also present (Figure 5.9).
For the second case, E, γ < 0, the wave function has to vanish at infinity. Thus
we set
Φ|x=−L/2 = 0 → Φ0 = 0 , Φ|x=L/2 = 0 → Φ N+1 = 0 . (5.49)
These boundary conditions are already included in (5.44). To obtain a convergent iter-
ation one should again take an initial condition close to the expected solution, e.g.,
π
Φ = cos ( x) .
L
Again the computed solutions depend strongly on parameters. For γ = −1, E = −1
the algorithm converges to the state (5.47); for γ = −1, E = −2 one obtains numeri-
cal rubbish that, however, also fulfills the stopping criterion (Figure 5.10). As always,
‘prudence is the better part of valor!’
In J. Verne’s² famous novel [3] a space ship is shot toward the moon by a giant cannon.
Before the development of smoothly launching rockets this was the only at least hy-
pothetical possibility for leaving the gravity field of the earth. Albeit not realizable, at
20
1
10
0 0
Φ
Φ
–10
–1
–20
0 2 4 6 8 10 0 2 4 6 8 10
x x
Fig. 5.10: Two solutions in the parameter region of bounded states. Left: localized wave for E = −1,
γ = −1, right: numerical artifact for E = −2, γ = −1. For all computations 100 mesh points have been
used.
Mmoon
μ= ≈ 0.012 .
Mearth + Mmoon
After discretization of the time derivatives by finite differences, (4.45) turns into a non-
linear algebraic system
2n
∑ M ij q j = p j (q1 . . . q2n ) (5.50)
i
−2 0 1 −∆t 0 ..
0 −2 ∆t 1 0 ..
( 1 ∆t −2 0 1 −∆t 0 .. )
( )
(−∆t 1 0 −2 ∆t 1 0 .. )
1 (
(
)
)
M= 2( ...... ) ,
∆t ( )
( ...... )
( )
( ...... )
.. 0 1 ∆t −2 0
( .. 0 −∆t 1 0 −2)
(n is the number of mesh points; for the other notations see Section 4.4.4.2). Differing
from Jules Verne our space ship should ‘land’ on the moon after a given flight time
t = T. This leads to the Dirichlet boundary conditions:
with the start vector (xs , y s ), prescribed somewhere on the surface of the earth and the
target coordinates (x t , y t ) somewhere on the moon.
Being nonlinear, the system (5.50) can only be tackled iteratively. To improve con-
vergence it is advantageous to add on the right-hand side of (5.50) a damping term
having the form s (q⃗ k+1 − q⃗ k ). Solving for q⃗ k+1 then yields
−1
q⃗ k+1
= (M − s 1) (p(⃗ q⃗ k ) − s q⃗ k ) . (5.52)
clear;
n=10000; tend=[.2,0.75,2.5] % flight times (scaling as in sect.4.4.4)
mu=1./82; earth_radius=6300/380000; moon_radius=1600/380000;
xs=-mu+earth_radius; ys=0; xt=1-mu-moon_radius; yt=0; % Dirichlet
% conditions
s=100; % convergence factor
r13=sqrt((q(i)+mu)^2+q(i1)^2)^3;
r23=sqrt((q(i)+mu-1)^2+q(i1)^2)^3;
p(i)=(-(1-mu)/r13*(q(i)+mu)-mu/r23*(q(i)+mu-1)+q(i)*(1-s))*dt2;
p(i1)=(-(1-mu)/r13*q(i1)-mu/r23*q(i1)+q(i1)*(1-s))*dt2;
end
% boundary conditions as additional inhomogeneity.
p(1)=p(1)-ys*dt-xs; p(2)=p(2)+xs*dt-ys;
p(2*n)=p(2*n)-xt*dt-yt; p(2*n-1)=p(2*n-1)+yt*dt-xt;
q1=q;
q=p/m;
delta=norm(q-q1); % stopping criterion
end
yof=(kk-1)*3;
subplot(3,3,1+yof); plot(q(1:2:2*n),q(2:2:2*n)); % output
subplot(3,3,2+yof); plot(1:n,q(1:2:2*n));
subplot(3,3,3+yof); plot(1:n,q(2:2:2*n));
end
Taking the L2 norm, the deviation from one step to the next reads
δ k = |q⃗ k − q⃗ k−1
|.
If δ k falls below a certain given value, the iteration is stopped and the results are
plotted (Figure 5.11.). Apart from initial and target conditions, the flight paths depend
strongly on the given flight time T.
0 0
0.8
–0.02 0.6 –0.02
0.4
–0.04 0.2 –0.04
–1 0 –1
0 0.5 1 50 100 150 200 250 50 100 150 200 250
Fig. 5.11: Trajectories of the space ship (left), x (middle), and y (right) coordinates over time for three
different flight times T = 20 h, 75 h, 250 h (from top to bottom).
140 | 5 Ordinary differential equations II
Going back to dimensional variables one finds for the three flight times 20 h, 75 h, and
250 h, the touch-down speeds v(T) = √ẋ 2 (T) + ẏ 2 (T) of 18 000 km/h, 7000 km/h, and
5500 km/h, respectively. At launch the speed for all three cases is roughly 40 000 km/h.
Jules Verne was right assuming that his pilots could not have been injured by the
pressure wave of the detonation of the canon because they would have exceeded the
speed of sound in the first moment. However, the devastating acceleration would
have mashed them anyway beforehand.
5.5 Shooting
The main idea of the shooting method is to first neglect the boundary conditions on
one side, say on the right, and to convert the system under consideration to an initial
value problem. Then the solution is not unique and one varies iteratively the initial
values (aiming) until the boundary conditions on the right are met (meaning the shot
is on target).
Let us explain the method in more detail with a simple example. We are looking
for a solution y(x) of a second-order ODE in 0 ≤ x ≤ 1:
y = f(y, y , x)
One integrates (5.53) for instance with RK4 numerically from x = 0 through x = 1
taking the initial conditions
y1 (0) = a , y2 (0) = s
and different values for s (Figure 5.12). For each s one finds on the right-hand boundary
some
y R (s) = y1 (x = 1, s) .
If one is able to get a value for s leading to y R = b, this solution corresponds to a
solution of (5.53) fulfilling (5.54). Thus one has to seek the zero(s) of the function
f(s) = y R (s) − b ,
5.5 Shooting | 141
s1
s2
f(s2)
s3
b
Fig. 5.12: Shooting method. Three different
0 1 x
trials that fulfill the left side boundary condi-
tions only.
y(t = 0) = 1000 m , ̇ = 0) = 0 ,
y(t y(t = 60s) = 0 . (5.56)
{0 if y > y f
f ={ .
α |y|̇ if y ≤ y f
{
142 | 5 Ordinary differential equations II
Tab. 5.3: Height y after one minute flight time and touch-down velocity v for different values of y f .
The optimal y f is between 450 and 550 m.
1000
500
0
0 10 20 30 40 50 60
Fig. 5.13: Solution y(t) over t for the correct value y f = 518 s.
Since we have a second order ODE and there are three conditions to fulfill, the problem
looks over-determined at first glance. However, an additional degree of freedom comes
with the choice of y f . Taking the initial conditions (5.56), the equations (5.55) are inte-
grated with RK4 until t = 60s for different values of y f . The results for α = 0.1/m and
g = 10 m/s2 are shown in Table 5.3.
The sought value is about 500 m, which is now determined more exactly by a
Newton–Raphson method. Taking an accuracy of 1 meter, the iteration converges
within four steps at y f = 518 m. The solution for this value is shown in Figure 5.13.
Next we wish to extend the method to the general case of a system of N first-order
ODEs
dy i
= f i (y1 , y2 . . . y N , x) , i = 1 . . . N . (5.57)
dx
Again we seek a solution in a ≤ x ≤ b. Assuming linear and separable boundary
conditions we may have on the left-hand boundary n1 conditions
⃗
A y(a) = a⃗ , (5.58)
5.6 Problems
Bibliography
6.1 Classification
We restrict ourselves for the time being to one dependent variable, say u. Let us start
with only two independent variables, x and t. The most general (quasilinear) PDE of
the first order then reads
∂u ∂u
A(u, x, t) + B(u, x, t) = C(u, x, t) . (6.1)
∂x ∂t
If A and/or B depend additionally on the first derivatives of u, (6.1) is a nonlinear PDE.
In contrast, a linear first-order PDE has the general form,
̃ ∂u ̃ ∂u ̃ ̃
A(x, t) + B(x, t) = C(x, t) u + D(x, t) . (6.2)
∂x ∂t
https://doi.org/10.1515/9783110515145-006
6.1 Classification | 145
With the help of (6.1), the variation of u (the total differential) can be written as
∂u ∂u C ∂u B
du = dx + dt = dx + [dt − dx]
∂x ∂t A ∂t A
C ∂u A
= dt + [dx − dt] . (6.3)
B ∂x B
If we choose the path in the tx-plane in such a way that
dx A
= , (6.4)
dt B
both square brackets vanish and
C C
du = dt = dx (6.5)
B A
remains along the characteristic curve xc (t) that is given as a solution of the ODE (6.4).
For the special case C = 0 (homogeneous PDE) one obviously obtains du = 0 and
thereby, u(xc (t), t) = const.
∂ t u + v(x)∂ x u = 0 (6.6)
xc (t) = xs (1 − e−α(t−t 0) )
xs
Fig. 6.2: As the convection equation, the Burgers equation yields as a solution for u > 0 traveling
waves to the right. Since the velocity is proportional to the amplitude, wave crests move faster and
catch up to wave troughs (b), eventually leading to a breaking wave (c). In (c), u can no longer be
expressed as a function of x.
The nonlinearity steepens the wave front more and more and finally causes a singu-
larity at which the wave would break, Figure 6.2. However, at this point (6.8) loses its
validity.
A special solution of Burgers equation is linear in x and reads
αx
u(x, t) = − . (6.9)
1 − αt
For α > 0, a singularity exists at t∗ = 1/α, corresponding to an infinite slope and
wave breaking. This can also be recognized looking at the characteristics. From (6.4)
we obtain
dxc α xc
=u=− ,
dt 1 − αt
and once integrated,
xc (t) = x0 ⋅ (1 − αt)
We discuss again the case of two independent variables, now x, y. The general form
of a second order PDE reads
∂2 u ∂2 u ∂2 u ∂u ∂u
A + B + C +D +E +F=0 (6.10)
∂x2 ∂x∂y ∂y2 ⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟
∂x ∂y
≡H
y = y c (x) (6.11)
P = ∂x u , Q = ∂y u
du = P dx + Q dy (6.12)
and
dP = (∂2xx u) dx + (∂2xy u) dy , dQ = (∂2xy u) dx + (∂2yy u) dy . (6.13)
Using (6.13), the second derivatives along (6.11) can be expressed as
dP dQ 1 2
∂2xx u = − m ∂2xy u , ∂2yy u = − ∂ u. (6.14)
dx dy m xy
1 B √ B2
m1,2 = ( ± − AC) , (6.16)
A 2 4
the square bracket of (6.15) vanishes and the variation of P and Q along that curve can
be computed from
m i A dP i + C dQ i = −H m i dx i . (6.17)
P und Q (and with (6.12) also u) follow then from their previous values P i , Q i , u (see
Figure 6.4) as
P = P i + dP i , Q = Q i + dQ i . (6.18)
148 | 6 Partial differential equations I, basics
P, Q
yc(1) yc(2)
From the six equations (6.17, 6.18), the six unknowns P, Q, dP i , dQ i can be uniquely
determined. Knowing m i from (6.16), the characteristics can be found solving the ODEs
(i)
dy c (i)
= m i (y c , x) . (6.19)
dx
For a linear PDE, (6.16) and therewith y c (x) are independent from the solution u.
6.1.2.1 Discriminant
Are there always two different families of characteristic curves? Obviously this can be
only the case if the two roots (6.16) are real-valued and do not coincide. For a further
classification we consider the discriminant
B2
D= − AC (6.20)
4
and distinguish the cases
– D > 0 : m1 ≠ m2 , both real-valued, two characteristics, hyperbolic PDE
– D = 0 : m1 = m2 , real-valued, one characteristic, parabolic PDE
– D < 0 : m1 = m∗2 , complex-valued, no characteristics, elliptic PDE
In Table 6.1 we list several PDEs and their allocation according to the three classes
above, now for three spatial dimensions.
Tab. 6.1: Several important second order PDEs from different areas of physics and their classifica-
tion with respect to characteristics in three space dimensions, ∆ = ∂2xx + ∂2yy + ∂2zz . The eigenvalues
of the coefficient matrix A (6.21) are denoted by λ i .
The coefficient matrix A ij is symmetric and has only real eigenvalues whose signs al-
low for a classification according to Section 6.1.2.1. At first we take N = 2. Using the
notation from (6.10), the matrix A reads
A B/2
A=( )
B/2 C
R
n̂
u(x, y)
T(x, y) = T R (x, y) , x, y ϵ R ,
the solution is unique and corresponds to the stationary temperature profile of a heat
conducting plate. If, on the other hand, the heat current through the boundary (λ =
heat conductivity)
−λ n̂ ⋅ ∇T = j R , x, y ϵ R
is given, j R must be compatible with (6.23). This becomes clear by integrating (6.23)
over the whole area
1
∫∫ dxdy ∆T = ∫∫ dxdy div(∇T) = ∮ n̂ ⋅ ∇T dr = − ∮ j R dr = 0 . (6.24)
λ
F(R) F(R) R R
6.1 Classification | 151
n̂
dr
TR
j = jR n̂
T(x,y) T (x,y)
Dirichlet
Neumann
Fig. 6.6: Specifying the temperature (left) on, or the heat current (right) through the boundary deter-
mines the temperature inside the domain as a solution of the stationary heat equation.
The amount of heat flowing in the domain must be the same as that flowing out. Oth-
erwise a stationary temperature on the plate is not feasible, Figure 6.6.
∂T ∂2 T ∂2 T
= κ( 2 + ), (6.25)
∂t ∂x ∂y2
T(x, y, t = t0 ) = T0 (x, y) .
Note that for Neumann conditions the compatibility restriction (6.24) is now obsolete.
If the total heat flux through the boundaries is not zero, there will be no stationary
1 With (n + 1)-dimensional, we denote a system or an equation in n spatial dimensions plus one for
time.
152 | 6 Partial differential equations I, basics
solution and, depending on the sign of the flux, the plate is heating up or cooling
down forever.
The distinction between initial and boundary values is also important for hyper-
bolic equations. If we take for instance the (1+1)-dimensional wave equation
∂2 u ∂2 u
2
= c2 2 , (6.26)
∂t ∂x
there exist unique solutions in 0 ≤ x ≤ L, t ≥ 0 for given boundary conditions
Table 6.2 lists several combinations of second order PDEs and boundary/initial values.
Tab. 6.2: Only certain combinations of equation types and boundary conditions constitute well-
posed problems. With ‘Cauchy’ we denote here an initial value problem of the form (6.28). For the
definition of ‘open’ and ‘closed’; see Figure 6.7.
As for ODEs, the procedure for a numerical integration of PDEs consists in discretizing
the different independent variables and finally in an iterative or, in rare cases, a direct
solution of a normally large algebraic system of equations. The discretization can be
realized by different methods which should be suited to the problem at hand. We wish
to introduce here the most important ones and shall start with the finite-difference
method (FD).
6.2.1 Discretization
For the moment we concentrate on the case of two independent variables. One reduces
the sought solution u(x, y) on discrete mesh points or grid points
which are assumed to lie on a (not necessarily) regular grid in the integration domain
x0 ≤ x ≤ x1 , y0 ≤ y ≤ y1 .
The quantities
∆x = (x1 − x0 )/I , ∆y = (y1 − y0 )/J
are denoted as step sizes. In its most simple form the FD method obviously will work
only for rectangular geometries. Extensions are possible; one could choose space-
dependent step sizes, which could account for a better resolution in domains where
u is strongly varying.
Derivatives with respect to space are approximated by differential quotients,
which are available in different orders of ∆x and ∆y and in several symmetries. We list
the discretization for the first four derivatives²:
−1 1
du 1
= (u i+1,j − u i−1,j ) + O(∆x2 ) , (6.29)
dx x i ,y j 2∆x
1 −2 1
d2 u 1
= (u i+1,j − 2u i,j + u i−1,j ) + O(∆x2 ) , (6.30)
dx2 x i ,y j ∆x2
−1 2 −2 1
d3 u 1
= (u i+2,j − 2u i+1,j + 2u i−1,j − u i−2,j ) + O(∆x2 ) , (6.31)
dx3 x i ,y j 2∆x3
1 –4 6 −4 1
d4 u 1
= (u i+2,j − 4u i+1,j + 6u i,j − 4u i−1,j + u i−2,j ) + O(∆x2 ) . (6.32)
dx x i ,y j ∆x4
4
Configuration (a) is most common and (b) normally leads to numerical oscillations
since even grid points (i + j even) are decoupled from odd points. (b) is therefore not
suited to diffusion equations. The nine-points formulas (c) and (d) are linear combina-
tions of (a) and (b). The symmetry of (c) comes closest to the (continuous) rotational
symmetry of ∆, while (d) minimizes the truncation error to the order ∆x4 .
The biharmonic operator is built from fourth order derivatives also including the
mixed one. Here we state only the 13-points formula of lowest order (Figure 6.9):
∂4 u ∂4 u ∂4 u
∆22 u x ,y = ( 4 + 2 2 2 + 4 )
i j ∂x ∂x ∂y ∂y x i ,y j
1
= (20u i,j − 8 (u i+1,j + u i−1,j + u i,j+1 + u i,j−1 )
∆x4
+ 2 (u i+1,j+1 + u i−1,j+1 + u i+1,j−1 + u i−1,j−1)
+ u i+2,j + u i−2,j + u i,j+2 + u i,j−2) + O(∆x2 ) . (6.34)
6.2 Finite differences | 155
1 1 1
1 −4 1 −4
1 1 1
(a) (b)
1 1 1 1 4 1
1 −8 1 4 −20 4
1 1 1 1 4 1
(c) (d)
2 −8 2
1 −8 20 −8 1
2 −8 2
The standard problem of electrostatics is the computation of the electric field for a
given charge distribution and boundary conditions. Thus one has to find solutions for
the Poisson equation [2]
∆ u(x, y) = −4π ρ(x, y) (6.35)
with ρ as the charge density and u as the electrostatic potential. From the latter, the
electric field directly follows
E⃗ = −∇u .
We shall treat the problem again in two dimensions. If u is prescribed along the bound-
aries (Dirichlet condition) the problem is well-posed and a unique solution exists.
u = ub(x)
b
u=0 Δu = 0 u=0
For the special case ρ = 0 and a rectangular geometry as shown in Figure 6.10, the
problem is separable for certain boundary conditions. If, for instance,
where ∆x = ∆y = h, I = a/h, J = b/h, and ρ i,j = ρ(x i , y j ). The walls are located at the
grid lines i = 0, I, and j = 0, J. Since the boundary values are prescribed, the system
(6.37) has to be solved only in the bulk for i = 1 . . . I − 1 , j = 1 . . . J − 1, resulting
in N = (I − 1) × (J − 1) equations. If we combine the node values u ij and ρ ij in vector
notation, e.g., using the assignment
ũ k = u ij , ρ̃ k = ρ ij , k = i + (j − 1)(I − 1) ,
where L is an N × N sparse matrix with only five nonzero elements in each line.
Here we have already written the boundary term u i,0 on the right-hand side. Thus one
may substitute
ρ i,1 = ρ i,1 + u i,0 /(4πh2 )
in (6.37). The other boundaries are treated in the same manner.
If Neumann or mixed (Robin) conditions are posed, u ij has to be computed also
on the boundaries, increasing the number of equations and variables to (I +1)×(J +1).
To compute the derivatives at the walls an additional ‘virtual’ line outside the area is
appropriate whose node values must be computed from the boundary conditions.
To make it more clear we consider as an example a given Neumann condition
∂ y u|y=0 = f(x)
on the lower wall at y = 0. Taking the discretization (6.29) the virtual line
can be used.
As an improvement of the Jacobi method, faster convergence is provided by the
(n+1)
Gauss–Seidel method where on the right-hand side of (6.41) values of u ij are used
if they have been already computed in the same loop:
(n+1) 1 (n) (n+1) (n) (n+1)
u i,j = (u i,j+1 + u i,j−1 + u i+1,j + u i−1,j ) + πh2 ρ i,j . (6.43)
4
But note that the scheme (6.43) breaks the symmetries x → −x, y → −y inherent in the
Laplace-Operator (and also in (6.41)) and artificial results with predominant direction
may emerge. This shortage can be compensated running the loops in (6.43) over i and
j alternately back and forwards. For a backwards loop the iteration is modified to
(n+1) 1 (n+1) (n) (n+1) (n)
u i,j = (u i,j+1 + u i,j−1 + u i+1,j + u i−1,j ) + πh2 ρ i,j .
4
Also combinations like i forwards and j backwards should occur.
Convergence can be accelerated further by so-called successive over-relaxation.
One first writes
(n+1) (n)
u i,j = u i,j + ωR i,j
with the relaxation factor ω and R ij depending on the method, e.g., taking Gauss–
Seidel
1 (n) (n+1) (n) (n+1) (n)
R i,j = (u i,j+1 + u i,j−1 + u i+1,j + u i−1,j ) + πh2 ρ i,j − u i,j .
4
If ω = 1, the Gauss–Seidel method is recovered; for ω > 1 one obtains over-relaxation.
Figure 6.11 shows the number of necessary iterations for the Poisson equation
(6.35) with Dirichlet conditions u = 0 at the boundaries and a quadratic geometry with
50 × 50 grid points. As a stopping criterion according to (6.42), we choose ϵ = 10−4 ,
and the charges are given as
Fig. 6.11: Convergence for different ω. The Jacobi method diverges as soon as ω > 1.
Fig. 6.12: Approximate solutions of (6.35) for ϵ ≈ 10−4 , FD, 50 × 50 grid. Left: u b = 0 and charges as
(6.44), right: ρ = 0 and inhomogeneous boundary condition u b (x) = sin πx + sin 2πx + sin 3πx.
Figure 6.12 illustrates the result (left frame), together with a run for a charge free area
and an inhomogeneous Dirichlet condition (right). The simple Jacobi method shows a
rather slow convergence and becomes unstable for over-relaxation. The Gauss–Seidel
method converges much faster up to ω ≈ 1.9 but then also diverges.
Even fewer iteration steps for the same accuracy are needed for the ADI method,
an acronym for ‘Alternating Direction Implicit.’ One direction, say y, and the diagonal
terms in (6.37) are treated implicitly,
(n+1) (n+1) (n+1) (n) (n)
4u i,j − u i,j+1 − u i,j−1 = u i+1,j + u i−1,j + 4πh2 ρ i,j , (6.45)
by the assignment
0 1 0 0 ... 4 −1 0 0 ...
Q = (1 0 1 0 . . .) , L = (−1 4 −1 0 . . .) . (6.47)
0 1 0 1 ... 0 −1 4 −1 ...
With the help of the Thomas algorithm (Appendix A.3.5) L is inverted effectively,
(n+1) (n)
v⃗ i = L −1 [a⃗ i + Q v⃗ i ] , (6.48)
completing the first half step of the iteration. In the second half, the other direction is
treated implicitly:
(n+2) (n+2) (n+2) (n+1) (n+1)
4u i,j − u i+1,j − u i−1,j = u i,j+1 + u i,j−1 + 4πh2 ρ i,j . (6.49)
Inversion of L as in (6.48) completes the first step. In addition to the fact that more
elements are treated implicitly, the method has the advantage of a symmetric handling
of x and y. It can be easily extended to three dimensions adding a further step per
iteration.
A complete step is shown in the following code section:
DO ! iteration loop
s=0.
DO i=2,idim-1 ! 1st half step, y implicitly
DO j=2,jdim-1
d(j-1)=v*rho(i,j)+u(i+1,j)+u(i-1,j)
ENDDO
b=4.
CALL tridag(a,b,c,d,jdim-2) ! Thomas algorithm
6.2 Finite differences | 161
DO j=2,jdim-1
ua=u(i,j)
u(i,j)=d(j-1)
s=s+ABS(u(i,j)-ua)
ENDDO
ENDDO
DO j=2,jdim-1 ! 2nd half step, x implicitly
DO i=2,idim-1
d(i-1)=v*rho(i,j)+u(i,j+1)+u(i,j-1)
ENDDO
b=4.
CALL tridag(a,b,c,d,idim-2)
DO i=2,idim-1
ua=u(i,j)
u(i,j)=d(i-1)
s=s+ABS(ua-u(i,j))
ENDDO
ENDDO
IF(s<epsilon) EXIT ! stop criterion
ENDDO
...
with L given in (6.47). We evaluate (6.51) for three consecutive mesh points:
w⃗ j−2 − L w⃗ j−1 + w⃗ j = −a⃗ j−1
L (w⃗ j−1 − L w⃗ j + w⃗ j+1 ) = −L a⃗ j
w⃗ j − L w⃗ j+1 + w⃗ j+2 = −a⃗ j+1 .
Adding the three equations eliminates w⃗ j±1 and yields
(1)
w⃗ j−2 − L(1) w⃗ j + w⃗ j+2 = −a⃗ j , j = 2, 4, . . . J − 2 (6.52)
with
L(1) = 2 ⋅ 1 − L ⋅ L , a⃗ (1) = a⃗ j−1 + 2L a⃗ j + a⃗ j+1 .
With (6.52) we have halved the numbers of equations to solve. Now we continue ap-
plying the same steps until we arrive at the boundaries where the last equation (6.52)
reads
(k)
L(k) w⃗ (J+1)/2 = a⃗ (J+1)/2 + w⃗ 0 + w⃗ J+1 , (6.53)
162 | 6 Partial differential equations I, basics
with w⃗ 0 and w⃗ J+1 given from the boundary conditions. The method will work only if
the number of grid points in the y-direction is chosen with J = 2k − 1. In (6.53), L(k)
denotes an I × I matrix that is dense and constructed recursively according to
w⃗ ℓ , ℓ = (J + 1)/2 ± (J + 1)/4
T(x = 0, t) = T a , T(x = L, t) = T b ,
T(x, t = 0) = T0 (x) .
∂ϑ ∂2 ϑ
=κ 2
∂t ∂x
with
ϑ(x = 0, t) = ϑ(x = L, t) = 0 .
Decomposition of ϑ into suitable trigonometric functions yields the analytic solution
in the form of an infinite series
x ∞
T(x, t) = T a + (T b − T a ) + ∑ g n (t) sin k n x (6.55)
L n=1
where
g n (t) = A n e−k n κt ,
2
k n = nπ/L .
6.2 Finite differences | 163
in one and in two dimensions, respectively. Starting from the initial condition
(0)
Ti = T0 (x i )
T
=0
y
open window
T=TE
T T
=0 =0
x x
heating
T=TH
T
=0
y
Fig. 6.13: Sketch of the system: room with window and heating. FD-grid, dashed: virtual points.
Along window and heating we take Dirichlet conditions; along walls, Neumann conditions apply.
6.2 Finite differences | 165
Fig. 6.14: Time series, temperature distribution after 0.1, 1, 20 days. Stove and window marked in
green, TE = 0°C, TH = 70°C. The extremely long relaxation time is a consequence of the total disre-
gard of any convection.
Figure 6.14 shows a time series computed on a 70 × 70 grid. The step sizes
∆x = 3/69 , ∆t = 0.1∆x2 /κ
have been used where
κ = 2 ⋅ 10−5 m2 /s
denotes the thermal diffusivity of air. As an initial condition, the temperature inside
the room was fixed to the outdoor value TE .
Once the temperature distribution is known the heat current densities accord-
ing to
̂
j = −λ n∇T
can be computed (λ = thermal conductivity of air³) and integrated along the window
and the surface of the stove. The temporal evolution is depicted in Figure 6.15. For
the stationary (equilibrium) case, both currents should be equal. The discrepancy of
about 10 percent seems to have numerical reasons (resolution too low).
3 Thermal diffusivity and thermal conductivity are different material properties but linked by the re-
lation κ = λ/ρc with density ρ and specific heat c.
166 | 6 Partial differential equations I, basics
For a stable method the solution should asymptotically approach some stationary
value, which is only possible if
(n+1) (n)
A ≤ A .
As a consequence, the absolute value of the so-called amplification factor
V k = 1 + 2s(cos k − 1) (6.62)
must be less than or equal to one for arbitrary k. This is the stability criterion of von
Neumann⁴. From (6.62) one finds V k ≤ 1 for all k and the stability limit is given as
V k ≥ −1, leading to
1
s≤ .
1 − cos k
Since this constitutes an upper bound for ∆t we must find the specific k that minimizes
s, giving
k = π , s = 1/2
and therefore the condition
1 ∆x2
∆t ≤ . (6.63)
κ 2
If ∆t is chosen as larger, the grid becomes numerically unstable first with the ‘most
dangerous mode’
e iπℓ ,
corresponding to a change of signs from one grid point to the next (Figure 6.16). The
relation (6.63) is typical for an explicit method. In general one has
∆t ∼ (∆x)n
if the time derivative is first order and the highest occurring space derivative is of or-
der n.
If the mesh has N grid points the number of equations is N and the number of time
iterations K ∼ 1/∆t ∼ 1/(∆x)n = N n . Then the total numerical effort turns out to be
NE ∼ N n+1 ,
which may restrict the application of fully explicit methods, in particular if higher
derivatives are around.
The same stability consideration can be done for the implicit scheme (6.59) for
which one obtains
1
Vk = ,
1 − 2s(cos k − 1)
an amplification factor whose absolute value is less than or equal to one for all k.
Thus, the implicit method is unconditionally stable, and restrictions for the time step
are only due to accuracy constraints. The numerical effort is then independent on the
order of the appearing derivatives
NE ∼ N .
To construct a stable algorithm one can change the representation of the deriva-
tives, the differential quotients. The most simple way is the so-called upwind scheme.
Here, a space derivative is taken asymmetric in the ‘upstream’ direction. Instead of
(6.64) one obtains in the lowest order
(n) (n)
(n+1) (n) {u i − u i−1 , C, v > 0
ui = ui − C{ (6.66)
(n) (n)
{u i+1 − u i , C, v < 0
which can be extended to the more general case v = v(x) by substituting v with v i .
With a constant v the amplification factor reads
|C| ≤ 1 . (6.67)
(n)
Substituting u i on the left-hand side of (6.64) by its average
The second order time discretization (6.69) applied on the diffusion equation leads to
an unstable scheme. For the convection equation on the other hand, it yields a much
6.2 Finite differences | 169
1 1 1
t
0.4 0.4 0.4
0 0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x x
Fig. 6.17: Numerical solutions of the convection equation with contour lines in the xt-plane. Left: up-
wind with ∆x = 1/1000, middle: upwind with ∆x = 1/100, right: leapfrog with ∆x = 1/1000.
Maximal Courant number C = 0.1. The leapfrog method shows no dissipation.
better stability behavior as the one-step schemes discussed before. Hence for the am-
plification factor one finds
which for all |C| ≤ 1 has an absolute value equal to one. At least in the case of the
convection equation, the method is free of any numerical dissipation.
Since time integration ‘jumps’ over the spacial grid line at each time step, the
method is also called the leapfrog scheme. Even and odd grid points (black and white
squares on a checkerboard) are decoupled and may drift apart in the course of the
iterations. This can be avoided by introducing a weak additional diffusion.
Figure 6.17 shows three numerical solutions of the convection equation with the
same initial condition
u 0 = e(x−0.1) /γ 2
2
, γ = 0.2 , ua = 0
and the same time-depending v(t) = 2 cos(πt). For the upwind scheme, one clearly
recognizes numerical dissipation ∼ ∆x that vanishes using leapfrog (right frame).
Thus one has to determine twice as many coefficients as for the diffusion equation and
needs accordingly twice as many initial conditions. For physical problems one often
prescribes
u(x, 0) = u 0 (x) , ∂ t u(x, 0) = v0 (x) (6.71)
Discretizing the second time derivative with the help of (6.30) yields a leapfrog scheme
of the form
(n+1) (n) (n−1) ∆t2 (n) (n) (n)
ui = 2u i − u i + c2 2 (u i+1 − 2u i + u i−1 ) . (6.72)
∆x
(n+1)
As already seen in (6.70), this is a two-step method. To compute u i we must know
(n) (n−1)
u i and additionally u i . Let the initial conditions be given in the form (6.71). Then
(0) (−1)
we find u i and u i from
(0) (−1) (0)
ui = u 0 (x i ) , ui = u i − v0 (x i )∆t .
with q = c∆t/∆x and the auxiliary variable B(n) . We write (6.73) in matrix form
(n+1) (n)
A A
( ) = M( )
B B
with
2 + 2q2 (cos k − 1) −1
M=( ) .
1 0
To achieve a stable algorithm, the absolute values of the two eigenvalues λ12 of M have
to be less than or equal to one. Due to
λ1 λ2 = Det M = 1
6.2 Finite differences | 171
this is only possible if λ1 = λ2 = 1 or the two λ i form a complex conjugated pair having
an absolute value of one. From this we derive
2
q2 ≤ .
1 − cos k
An upper limit for q and hence for the time step is provided by k = π (compare Fig-
ure 6.16) and results in q2 ≤ 1 or
∆t ≤ ∆x/c .
If we substitute the phase velocity c by the transport velocity v this is again the Courant
condition (6.67).
As an application, we wish to study a problem from fluid mechanics. Based on the
Euler equations for an inviscid fluid, one systematically derives the (two-dimensional)
shallow water equations:
v⃗H = ∇Φ .
Equations (6.74) are valid only for surface structures (waves) that are slowly varying
on the scale of the average water depth h0 . For a derivation of the shallow water equa-
Fig. 6.18: Sketch of the shallow water system. The water is confined by the stationary ground at
z = f and the deformable surface at z = h.
172 | 6 Partial differential equations I, basics
tions we refer to fluid mechanics textbooks, e.g., [3]. Like the underlying basic hydro-
dynamic equations, the shallow water equations are nonlinear. However, for small
wave amplitudes η
h(x, y, t) = h0 + η(x, y, t)
Differentiating the first equation with respect to time and inserting the second one
yields
∂2tt η − g ⋅ (h0 − f)∆η + g ⋅ (∇f ) ⋅ (∇η) = 0 .
If the slope of the ground is also small we can finally neglect the last term and arrive
at the (2+1)-dimensional wave equation
∂2tt η − c2 ∆η = 0 (6.76)
Thus waves are propagating slower in shallow water, in agreement with experience.
What happens if a wave travels from deep water into more shallow regions, for in-
stance while approaching the shore? To find out we solve (6.76) numerically applying
the scheme (6.72). For the ground we use a parabola in x direction:
f(x) = 0.9 x2
on the unit square. One can choose the scaling of space and time to obtain h0 = g = 1.
Neumann boundary conditions at x = 0, 1 and y = 0, 1 allow for unique solutions.
To create the waves we assume an oscillating δ-shaped source term on the right-hand
side of (6.76)
∼ δ(x − x0 )δ(y − y0 ) cos ωt ,
which can be realized numerically by setting a certain single grid point, e.g., in the
middle of the layer x0 = y0 = 1/2 to
u I/2,J/2 = cos ωt .
Figure 6.19 shows three snapshots at consecutive times as well as the correspond-
ing surface profiles along the line y = 1/2. If the waves reach the shore their speed
and their length decrease but their amplitude increases. The grid consists of I × J =
200 × 200 mesh points; the code can be found in [4].
6.3 Alternative discretization methods | 173
Fig. 6.19: Wave propagation caused by an oscillating point source in the middle of the integration
domain. The water depth decreases with increasing x. Bottom row: cross section along the dashed
lines.
FD schemes can be developed and coded in a straightforward way with rather less
effort while proving reliable and robust for various applications. On the other hand,
more sophisticated methods have been developed to approximate differential equa-
tions with a system of algebraic equations that have higher accuracy and better con-
vergence. Although the effort in code writing can be higher at first, this normally pays
off with the lower CPU consumption and faster performance.
The method is again explained with one spacial dimension and can be generalized
afterwards. We follow mainly the first parts of the recommended book by Guo et al. [5].
As already seen in Section 5.3, the idea behind spectral methods is to decompose the
desired solution u(x) into a (finite) sum of certain given functions φ i (x), called base
functions, Galerkin functions, or ansatz functions:
N
u(x) ≈ u (N) (x) = ∑ a i φ i (x) . (6.77)
i=0
174 | 6 Partial differential equations I, basics
Even the FD method fits in this representation, taking the special base functions
{1 if x = x i
φ i (x) = { (6.78)
0 else
{
with the N grid points x i . However, here the notion FD has become more accepted.
As one easily may recognize, the Lagrange polynomials have the same property (6.78)
as the ‘FD base’, namely
(N)
L i (x j ) = δ ij (6.80)
with the Kronecker symbol δ ij . As for the FD methods x is only defined at certain dis-
crete points x j , called mesh points or collocation points. For the Chebyshev–Gauss–
Lobatto method the mesh points are generated via
jπ
x j = − cos ( ) , j = 0...N (6.81)
N
and span the interval [−1, 1]. Note that the mesh points are no longer equidistant but
accumulate towards the borders, which improves the convergence and accuracy of the
method.
Figure 6.20 shows the four Lagrange polynomials for N = 3. All polynomials are
of third degree, the mesh points from (6.81) are computed as
x0 = −1 , x1 = −1/2 , x2 = 1/2 , x3 = 1 .
1
L0(3) L(3)
1 L2(3) L3(3)
0.8
0.6
0.4
0.2
Fig. 6.20: The four Lagrange polynomials for
–1 –0.5 0 0.5 x 1 N = 3. The four mesh points are located at
x0 = −1, x1 = −1/2, x2 = 1/2, x3 = 1 (dashed).
6.3 Alternative discretization methods | 175
Here, the N + 1-dimensional vector u⃗ represents the function u (N) (x) in the base of the
(N)
N + 1 Lagrange polynomials L i . Due to (6.80) the inverse relation
u i = u (N) (x i )
Defining
(1) du (N) (x)
ui ≡
dx x=x i
we may write (6.83) in the form
u⃗ (1) = D u⃗ . (6.84)
The differentiation matrix D has the dimension (N + 1) × (N + 1). Its elements
dL j (x)
(N)
D ij =
dx
x=x i
can be computed explicitly as:
c i (−1)i+j {2 if k = 0, N
D ij = for i ≠ j = 0 . . . N with c k = {
cj xi − xj 1 else
{
xi (6.85)
D ii = − for i = 1...N −1
2(1 − x2i )
2N 2 + 1
D00 = −D NN = − .
6
For the case N = 3 one finds
u⃗ (2) = D D u⃗ = D 2 u⃗ (6.87)
with
16 −28 20 −8
1 10 −16 8 −2
D2 = ( ) . (6.88)
3 −2 8 −16 10
−8 20 −28 16
1 0 0 0
̃2 10/3 −16/3 8/3 −2/3
D =( ) (6.91)
−2/3 8/3 −16/3 10/3
0 0 0 1
with Q i = Q(x i ). The numerical task consists now in inverting D̃ and the determina-
2
tion of the solution T i . If, on the other hand, Neumann conditions are given on one or
on both boundaries, D 2 has to be changed accordingly. Take, for instance,
d x T|x=−1 = S , T(1) = T r ,
so the first line of D 2 has to be substituted by the first line of D (first derivative) and
instead of (6.92), we obtain the system
0.02
0.01
–0.01
Fig. 6.21: Temperature distribution (bold) cre-
ated by randomly chosen heat sources as a
–0.02 solution of (6.92) with N = 100 Chebyshev–
Gauss–Lobatto mesh points. The thin line
–1 –0.5 0 0.5 1 shows Q(x).
Figure 6.21 shows a solution of (6.92) but for N = 100 and the Dirichlet conditions,
T(−1) = T(1) = 0 .
The heat source was chosen randomly, but obeys the constraint
1
∫ dx Q(x) = 0 .
−1
Note that in the discretized form of the integral the variable step sizes (6.81) must be
accounted for, thus
1 N
∫ dx Q(x) ≈ ∑ Q i ∆x i , with ∆x i = x i − x i−1 .
−1 i=1
Next we consider the time-dependent heat equation (6.54) with the boundary con-
ditions (6.90) and the initial condition
T(x, 0) = T a (x) .
with
T⃗ (j) = (T0 (j∆t), T1 (j∆t), . . . T N (j∆t))
and the matrix
M = 1 + κ∆t D̃
2
178 | 6 Partial differential equations I, basics
with the modified matrix D̃ that takes for the special case N = 3 the form
2
0 0 0 0
̃2 10/3 −16/3 8/3 −2/3
D =( ) . (6.95)
−2/3 8/3 −16/3 10/3
0 0 0 0
u(x) = u(x + L)
where i = √−1. The function u at the now equidistant mesh points x j = j∆x = jL/N is
given as
N−1
u j = ∑ ũ n e−2πinj/N (6.98)
n=0
1 N−1
ũ n = ∑ u j e2πinj/N . (6.99)
N j=0
The method is best suited for linear PDEs with constant coefficients but can also be
extended to certain nonlinear problems, as we shall see below.
6.3 Alternative discretization methods | 179
T̃ n = k −2 ̃
n Qn (6.100)
k n = 2πn/L .
1 N−1
Q̃ 0 = ∑ Qj ,
N j=0
the mean of Q must be zero, which also follows by integrating (6.89) over x and sup-
posing periodic boundary conditions. Obviously the Laplace operator is in diagonal
form in Fourier space for arbitrary spatial dimensions and can be inverted easily. Back-
transformation via (6.97) yields T(x) in real space. The Fourier transforms can be exe-
cuted effectively applying the FFT-algorithm (Fast-Fourier-Transform), the numerical
effort thereby is ∼ N log N.
Taking the FD-representation of (6.89)
and inserting the Fourier transform (6.98), a different result from (6.100) is obtained,
namely
∆x2
T̃ n = Q̃ n . (6.101)
2 − 2 cos(k n ∆x)
0.00020
0.00015
0.00010
(1)
0.00005
∆x2 1 ∆x2
≈ 2 + + O(∆x4 ) ,
2 − 2 cos(k n ∆x) k n 12
we see that the difference vanishes with ∆x2 but can become important for larger val-
ues of k n , as in Figure 6.22.
u(0) = u(L) = 0 .
can be also fulfilled with (6.102) by adding the homogeneous solution of (6.89)
d2 u h
=0, (6.104)
dx2
leading to
u(x) = u s (x) + u h (x) ,
where u h must satisfy the inhomogeneous boundary conditions (6.103). In one dimen-
sion the solution of (6.104) is
x
u h (x) = u ℓ + (u r − u ℓ ) ,
L
with possible extension to more dimensions. Thus, for the rectangle
0 ≤ x ≤ Lx , 0 ≤ y ≤ Ly
∂2 ∂2
( 2
+ 2 ) u h (x, y) = 0 . (6.106)
∂x ∂y
6.3 Alternative discretization methods | 181
with
Ly
2
An = ∫ dy f(y) sin(πny/L y ) .
L y sinh(πnL x /L y )
0
For the discretized form we obtain
M−1
u hij = ∑ Ã n sinh(πni/M) sin(πnj/M)
n=1
with
M−1
2
à n = ∑ fℓ sin(πnℓ/M)
M sinh(πnN/M) ℓ=1
and fℓ = f(ℓ∆y). Here we have assumed equal step sizes
∆x = ∆y = L x /N = L y /M
for an N × M grid.
has to be solved, which can be done exactly in one dimension. One finds
Tr
A= − Tℓ coth(αL) , B = Tℓ .
sinh(αL)
The finite-element method (FE) was developed to solve PDEs, mainly from fluid me-
chanics, on complex geometries. It belongs to the spectral methods with base func-
tions that are only nonzero in certain places, namely at the finite elements. Inside
each element a linear space dependence or a simple polynomial is assumed [6].
We shall introduce the method during the example of the two-dimensional
Laplace equation
∂2 u ∂2 u
+ =0 (6.111)
∂x2 ∂y2
with Dirichlet boundary conditions.
(x i , y i ) , i = 1...n
and m (outer) points lying on the boundaries. The domain is divided in triangles hav-
ing the inner and outer points as corners (vertices). In higher (d) dimensions, cells
with d + 1 corners are defined. The approximate solution sought after can be written
similarly to (6.77) according to:
n
u(x, y) = ∑ φ i (x, y) , (6.112)
i
where φ i is nonzero only in those cells containing the node x i , y i as a vertex. There,
one adjusts
φ i (x i , y i ) = u i = u(x i , y i )
with u i as the function value (node value) at the node i. Let the points (x i , y i ), (x k , y k ),
(xℓ , yℓ ) span triangle number j, Figure 6.24. We split the function φ i into
φi = ∑ αj , (6.113)
j ϵ neighbors(i)
6.3 Alternative discretization methods | 183
Fig. 6.23: Irregular geometry with n = 1894 inner and m = 242 outer points. The domain, here
multiply connected, is paved with finite elements that are triangles for the two-dimensional case.
uℓ
ui
αj
α j (x, y) = a j + b j x + c j y . (6.114)
The sum over j in (6.113) runs over all triangles having x i , y i as vertex and shown in
Figure 6.24. The coefficients a j , b j , c j , different in each triangle, follow (6.112) to form
184 | 6 Partial differential equations I, basics
three equations:
1 xi yi aj ui
(1 xk y k ) (b j ) = (u k ) (6.115)
1 xℓ yℓ cj uℓ
and, after an inversion of the matrix:
aj x k yℓ − xℓ y k xℓ y i − x i yℓ xi yk − xk yi ui
1
(b j ) = ( y k − yℓ yℓ − y i y i − y k ) (u k ) . (6.116)
D
cj xℓ − x k x i − xℓ xk − xi uℓ
D = x i y k + x k yℓ + xℓ y i − x k y i − xℓ y k − x i yℓ .
The coefficients a j , b j , c j and hence the element functions α j depend linearly on the
node values u i .
(∂ x u)j = b j , (∂ y u)j = c j .
where the sum runs over all triangles and F j denotes the surface area of triangle j.
The extremum of S is found by equating all its derivatives with respect to u i to zero:
∂S ∂b j ∂c j
= ∑ F j (b j + cj )=0. (6.119)
∂u i j
∂u i ∂u i
Since b j and c j depend linearly on u i , (6.119) has the form of a linear, inhomogeneous
system of equations for the n inner node values u i . The m boundary points thereby
play the role of the inhomogeneities.
6.3 Alternative discretization methods | 185
6.3.3.3 Algorithm
The tasks of an FE-algorithm can be divided into three parts:
(a) Mesh generation. The location of the nodes is chosen as appropriate to the domain
and the geometry of the boundaries. The node coordinates
xi , yi , i = 1...n +m
are stored and the boundary points are marked, e.g., by sorting as the first or the last
m pairs. To evaluate (6.116) later, for each point i one must know the amount as well
as the ordinal number of its neighbor points (the points with a common triangle). This
can be achieved introducing an array NN(i, j), where NN(i, 0) denotes the amount k
of neighbors and NN(i, j), j = 1 . . . k the corresponding ordinal numbers.
(b) Laplace solver. The linear system (6.119) has the form
n m
∑ L ij u j = ∑ R ik u rk , i = 1...N . (6.120)
j k
(c) Evaluation. To visualize the results one can plot, for instance, contour lines. Let
u i , u j , u k be the node values at the corners of a certain triangle. The contour line u = h
crosses the triangle if
For a triangle where (6.121) is fulfilled one computes the intersections of h with its
edges and connects them with a line. Normally, two intersection points on two differ-
ent edges exist. The cases where h is exactly equal to a value on one or more corners
can be treated separately.
Figure 6.25 shows the solution of the two-dimensional Laplace equation on the
domain of Figure 6.23, built of n = 1894 inner and m = 242 outer points.
To facilitate mesh generation, an unambitious ‘semiautomatic’ program
mesh_generator is presented in [4]. A ppm-file (portable pixmap) containing the ge-
ometry of the domain in the form of the boundaries is needed, created with a standard
graphics program, e.g., xfig. Then the Laplace equation is solved on the prescribed
domain by the program laplace_solver. An output file is generated containing the
node values, which can be plotted by grid_contour. A plot as shown in Figure 6.25
is the result. More detailed instructions can be also found in [4] as well as in Ap-
pendix D.2.
186 | 6 Partial differential equations I, basics
ur = −1
ur = 1
ur = −1
1
=
ur
ur = 0
Fig. 6.25: Numerical solution for the Laplace equation with the annotated Dirichlet conditions
and three point charges in the interior. The contour lines correspond to the potential values
u = 0.001/0.05/0.2/0.4/0.6/0.9 (solid) und u = −0.001/ − 0.05/ − 0.1/ − 0.2/ − 0.4 (dashed).
In the next chapter we shall investigate in more detail several nonlinear problems as
applications and examples. Here, we wish to concentrate on the Ginzburg–Landau
equation.
Based on the original idea of Landau⁵ [7] the Ginzburg–Landau equation serves as a
phenomenological model describing phase transitions. A macroscopic quantity, for
instance the magnetization of a ferromagnetic material, is described by the help of an
order parameter q(t). The values q = ±q0 correspond to the magnetic state where all
elementary magnets are parallel and point in the same direction, and q ≈ 0 denotes
the nonmagnetic state above the Curie temperature Tc where the spins are not ordered.
If there is no preferred direction in space, the free energy F should not depend on the
sign of q and F(q) = F(−q). Expanding F up to the fourth order yields
1 2 1 4
F(q, T) = F(0, T) + αq + βq . (6.122)
2 4
dq dF
=− = εq − βq3
dt dq
dq
= εq − q3 . (6.123)
dt
The three stationary solutions of (6.123)
q0s = 0 , s
q12 = ±√ ε (6.124)
correspond to the different phases; see Figure 6.26. By the natural extension
q(t) → q(x, t)
∂ t q = εq + D ∆q − q3 .
∂ t q = εq + ∆q − q3 . (6.126)
With (6.126) we have a PDE that is nonlinear with the dependent variable q. A fully
explicit scheme (FTCS) as an extension of (6.60) is obtained adding the extra terms
evaluated at time t:
(n) (n) (n) (n) (n)
(n+1) (n) (n) (n) 3
q i,j+1 + q i+1,j − 4q i,j + q i−1,j + q i,j−1
q i,j = q i,j + ∆t (εq i,j − (q i,j ) + ) . (6.127)
∆x2
To check the numerical stability we must linearize around one of the stable solutions,
e.g., q s = √ε:
q ij = √ε + u ij .
For small u the linear system
(n) (n) (n) (n) (n)
(n+1) (n) (n)
u i,j+1 + u i+1,j − 4u i,j + u i−1,j + u i,j−1
u i,j = u i,j + ∆t (−2εu i,j + ) (6.128)
∆x2
results. A von Neumann analysis similar to Section 6.2.3.3 but now in two dimensions
(n)
u m,n = A(n) ei(k x m+k y n)
leads to
A(n+1) = V A(n)
with the amplification factor
1
V = 1 + 2 [−ε + (cos k x + cos k y − 2)] .
∆x2
The stability condition |V| ≤ 1 yields an upper limit for the time step
∆x2
∆t ≤ . (6.129)
ε∆x2 + 4
In practice, the inequality
ε ∆x2 ≪ 1
For a fully implicit method all terms inside the brackets on the right-hand side of
(6.127) have to be known to the ‘new’ time t+∆t. Hence a nonlinear system of equations
had to be solved which would have been possible only iteratively. An easier realizable
procedure is obtained if only the linear parts of the right-hand side are considered at
t + ∆t whereas the nonlinearity remains explicit at t. Instead of (6.127) we arrive at the
semi-implicit scheme
(n+1) (n+1) (n+1) (n+1) (n+1)
(n+1) (n) (n+1) (n) 3
q i,j+1 + q i+1,j − 4q i,j + q i−1,j + q i,j−1
q i,j = q i,j + ∆t (εq i,j − (q i,j ) + ) .
∆x2
(6.131)
The same stability analysis as above yields now the upper time step limit
1
∆t ≤ , (6.132)
2ε
independently of the spatial step size ∆x.
Coding in MATLAB we can use the toolbox ‘gallery’ [8], providing several standard
matrices, amongst others the FD-version of the Laplacian in two dimensions, as shown
in Figure 6.8 (a). Running the script
190 | 6 Partial differential equations I, basics
clear;
kplot=[5,10,20,30,60,100,150,200,300]; % at k=kplot(m) make pic. m
n=200; dx=0.5; dt=1; kend=300; eps=0.1; % mesh size, steps,epsilon
psi=zeros(n); % 2D-array for plotting
if k==kplot(ib) % plotting
subplot(3,3,ib); ib=ib+1;
psi(:)=phi; % reshape phi to 2D
contourf(psi);
axis off; title(sprintf('t = %5.1f',k*dt));
drawnow;
end
end
6.4.4 Problems
∂ t u(x, t) = D ∂2xx u(x, t)+ αu(x, t)− βu 2 (x, t), u(x, t) ≥ 0, D, α, β > 0. (6.133)
Fig. 6.27: Numerical solution of the real Ginzburg–Landau equation (6.126) obtained with the
scheme (6.131) for ε = 0.1, time series.
2. Show with a linear stability analysis that the fixed point (stationary solution)
u (0) = 0 is unstable, and that the fixed point u (0) = 1 is stable.
3. Monotonic solutions that connect the two fixed points
are denoted as fronts or kinks. Therefore the front moves with a certain velocity v
towards the fixed point u = 0, i.e., to the right-hand side. Find a lower limit for v.
192 | 6 Partial differential equations I, basics
about the solution u 0 (x) found in 5. and derive a stationary Schrödinger equation
for the disturbances w(x) of the form
Find the ground state by expanding V(x) up to the order x2 . What can you say
about the stability of u 0 (x)?
And to code:
1. Verify the results of 1–4 solving (6.134) numerically with an FTCS method and the
appropriate boundary conditions u(x = 0) = 1, u(x = L) = 0. Assume a large
enough L.
2. Solve the Schrödinger equation (6.137) writing for instance a MATLAB code. Ana-
lyze its spectrum and its eigenfunctions.
Bibliography
We first consider two interacting particles in one spatial dimension. The particles,
each with mass m, are located at x1 , x2 and connected with a spring having the spring
constant −α. The stationary Schrödinger equation thus reads
Ĥ Ψ(x1 , x2 ) = E Ψ(x1 , x2 ) ,
In the following we leave the tildes. For the decoupled case α = 0 the exact solutions
simply read (N → ∞)
2 N
Ψ(x1 , x2 ) = ∑ cℓm sin ℓx1 sin mx2 (7.4)
π ℓ,m=1
where the coefficients cℓm are determined from the initial condition. For the energy,
one finds the levels
E = Eℓm = ℓ2 + m2 , (7.5)
which are two-fold degenerated if ℓ ≠ m, reflecting the symmetry x1 ↔ x2 . The
decoupled problem is similar to the single particle Schrödinger equation in a two-
dimensional potential well.
https://doi.org/10.1515/9783110515145-007
194 | 7 Partial differential equations II, applications
As happens quite often in quantum mechanics, one is confronted with the task to di-
agonalize a large matrix. To convert M into a two-dimensional matrix, one can confine
each pairs of indices to one:
and the same for (ℓ, m). N is the number of modes included in (7.4). The larger N, the
better spatial resolution of the wave functions is achieved. However, M has N 2 × N 2
elements and the numerical effort grows fast with N 4 .
Figure 7.1 shows the lower energy levels depending on α for N = 10. Note that
the degeneracy vanishes due to the coupling. On the other hand, for large α nearly
degenerated states occur again where a symmetric and an antisymmetric state belong
to (almost) the same energy value.
Figure 7.2 depicts contour lines of the 12 lowest states for α = 10. The probability
densities are largest near the corners of the line x1 + x2 = L, corresponding to the
furthest possible separation of the two particles. In Figure 7.3 we show the states for
attractive interaction, α = −10. Here, the probability density is maximal along the line
x1 = x2 , hence the particles prefer to be close to each other.
7.1 Quantum mechanics in one dimension | 195
20
10
Ψ22
Ψ00
E 0
–10
Ψ21 Ψ12
–20
–20 –10 0 10 20
α
Fig. 7.1: Energy levels as a function of α. The states Ψ ℓm , Ψ mℓ , degenerated for α = 0, split up. Inset:
by linear combination of two degenerated states (bottom), new states can be constructed (top).
Fig. 7.2: The 12 lowest states in the x1 , x2 -plane, from top left to bottom right, α = 10. The states
(1,2), (3,4) (5,6) are almost degenerated, compare Figure 7.1.
196 | 7 Partial differential equations II, applications
Fig. 7.3: The lowest states for α = −10. Here, degeneracy is completely removed.
{0 , 0<x<π
U(x) = {
∞, else .
{
Since the particle cannot penetrate into a domain with infinite energy its wave func-
tion must be zero there. Then, continuity of the wave function yields the Dirichlet con-
ditions
Ψ(0, t) = Ψ(π, t) = 0 .
Separation of space and time dependence allows for an exact solution of the form
∞ ∞
Ψ(x, t) = ∑ A n e−iω n t f n (x) = ∑ A n e−in t sin nx ,
2
(7.10)
n n
7.1 Quantum mechanics in one dimension | 197
N 2 = ∫ dx |Ψ|2 .
0
As is easily shown by the help of the Schrödinger equation, N does not depend on time
and the norm is conserved.
7.1.2.3 Algorithm
With the help of the time-evolution operator
t ̂
̂ t0 ) = e−i ∫t0 dt H(t ) ,
∂2
U(t, Ĥ = − 2 + U(x, t) ,
∂x
1 However, the initial condition should also fulfill the boundary conditions. This is here only approx-
imately true, the wave packet should therefore be narrow enough and not too close to one of the walls
so that Ψ(0, 0) ≈ Ψ(π, 0) ≈ 0 holds.
198 | 7 Partial differential equations II, applications
̂ t0 )Ψ(x, t0 ) .
Ψ(x, t) = U(t, (7.14)
Looking at the evolution for a small time interval ∆t = t − t0 and expanding with
respect to ∆t up to the first order, the ‘short-time-evolution’ operator
t+∆t
̂ )
dt H(t ̂
̂ + ∆t, t) = e−i ∫t
U(t ̂
= e−i H(t)∆t + O(∆t2 ) = 1 − i H(t)∆t + O(∆t2 ) (7.15)
Ψ(x, t + ∆t) = (1 ̂
− i H(t)∆t) Ψ(x, t) , (7.16)
⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟
Â
analogue to an explicit Euler scheme. But contrary to U,̂ the truncation  is no longer
unitary, thus keeping the norm if Ψ
̂
⟨Ψ(x, t + ∆t) | Ψ(x, t + ∆t)⟩ = ⟨AΨ(x, ̂
t) | AΨ(x, ̂
t)⟩ = ⟨Ψ(x, t)|Â + A|Ψ(x, t)⟩
with
 +  = (1 + i H(t)∆t)
̂ ̂
(1 − i H(t)∆t) = 1 + Ĥ 2 ∆t2
only conserved up to the order ∆t. The trick to get rid of this issue is to formulate (7.15)
in a different way,
̂ ̂ ̂ ̂ −1 ̂
̂ + ∆t, t) =e−i H(t)∆t
U(t = e−i H(t)∆t/2e−i H(t)∆t/2 = [ei H(t)∆t/2] e−i H(t)∆t/2
−1
̂
= (1 + i H(t)∆t/2) ̂
(1 − i H(t)∆t/2) + O(∆t2 ) ,
with
B̂ = 1 − i H(t)∆t/2
̂ .
Due to
−1 +
Û Û + = [( B̂ + ) B]̂ [(B̂ + )−1 B]
̂ = (B̂ + )−1 B̂ B−1 B̂ + = (B̂ + )−1 B̂ + = 1
this is unitary in any order of ∆t. Hence instead of (7.16) it is much better to take the
norm-conserving rule
−1
Ψ(x, t + ∆t) = (B̂ + ) B̂ Ψ(x, t)
or
B̂ + Ψ(x, t + ∆t) = B̂ Ψ(x, t) . (7.17)
7.1 Quantum mechanics in one dimension | 199
At each iteration step B̂ + must be inverted to compute Ψ(x, t + ∆t), therefore (7.17) can
be considered an implicit method.
To evaluate (7.17), Ψ can be decomposed into a function system. The most straight-
forward way is to do a discretization by finite differences; see Section 6.2:
where L is tridiagonal.
Figure 7.4 shows a numerical solution of (7.18) with ∆x = π/1000 and ∆t = 10−5 .
As an initial condition, the wave packet (7.13) with
x0 = 1 , k 0 = 40 , σ = 3/4 (7.19)
0.8
0.6
0.4
0.2
0
0 1 2 3
x
Fig. 7.4: xt-diagram obtained by integrating (7.18). Plotted are the contour lines of |Ψ(x, t)|2 .
200 | 7 Partial differential equations II, applications
Fig. 7.5: Mean and variance of x. After t = 2π the initial state is completely restored, and after t = π
the modes with even n take their initial values.
was utilized. It can be clearly seen how the wave packet flows apart up to t ≈ 0.5. Then,
the particle can be hardly localized, which becomes also obvious from Figure 7.5. The
wave packet (7.13) after T is completely, and after T/2 partially, reconstructed. There,
the variance
Var(x) = ⟨x2 ⟩ − ⟨x⟩2
takes a minimum.
σ 2 2T32
b = 2√ + 2
2 σ
is about equal to the length of the well π, hence
π2 σ2 σ4
T3 = √ − ≈ 0.8
8 4
(4) Validity of the Courant condition (6.65). In (7.10), the phase velocity of the wave
with amplitude A n is v p = n. We estimate the maximal occurring n = n m by re-
quiring
A n m = ϵ A k0 = ϵ
with a given ϵ ≪ 1 (accuracy). From
A n = e−σ (k−k0 )2 /2
= e−σ (n−k0 )2 /2
2 2
it follows that
2
n m = √− ln ϵ + k 0 .
σ2
The Courant condition (6.65) is valid for an upper T4 of
∆x
T4 = .
nm
To determine ∆x one must define a certain spacial resolution. If we assume that
the shortest occurring wave length λ0 = 2π/n m is resolved with 10 mesh points,
we find
2π
∆x = (7.20)
10n m
or
2π
T4 = .
10n2m
Taking the parameters (7.19) and ϵ = 10−4 , we obtain n m = 46 and
T4 ≈ 3 ⋅ 10−4 .
Let the motion of the particle with mass m and charge q be restricted on the xy-plane
perpendicular to a given magnetic field
B⃗ = B ê z .
The classical analogue provides closed, circular trajectories having the angular fre-
quency ω c = qB/m, named cyclotron frequency. Along the canonical formalism, the
Hamiltonian is modified by the minimal substitution
1 ̂⃗ 2
Ĥ = ( p̂⃗ − q A)
2m
̂
with the operator A⃗ belonging to the vector potential of the magnetic field B⃗ such that
B⃗ = curl A.⃗ Due to gauge invariance A⃗ can be only determined up to an expression ∇ϕ.
Thus we can take for instance the symmetric form
y
1
A⃗ = B (−x ) .
2
0
The scaling of Section 7.1 yields the dimensionless Schrödinger equation
1 2 2
[−∆ + iB0 (y∂ x − x∂ y ) + B (x + y2 )] Ψ(x, y, t) = i∂ t Ψ(x, y, t) (7.21)
4 0
with the 2D-Laplacian ∆ = ∂ xx + ∂ yy and
qL2
B0 = B.
π2 ℏ
We assume again the particle located in a square potential well of length L with in-
finitely high walls, leading to the boundary conditions
Ψ(0, y, t) = Ψ(π, y, t) = Ψ(x, 0, t) = Ψ(x, π, t) = 0 .
7.2.2 Algorithm
The reasoning of Section 7.1.2.3 is valid just as well in two dimensions. Discretizing
again with finite differences on an N × N-grid with step size ∆x,
Ψ(x, y, t) → Ψ(x k , yℓ , t) = Ψ k,ℓ (t)
7.2 Quantum mechanics in two dimensions | 203
2i∆x2
( − 4 − β 2 (x2k + y2ℓ )) Ψ k,ℓ (t + ∆t)
∆t
+ (1 − iβyℓ )Ψ k+1,ℓ (t + ∆t) + (1 + iβyℓ )Ψ k−1,ℓ (t + ∆t)
+ (1 + iβx k )Ψ k,ℓ+1 (t + ∆t) + (1 − iβx k )Ψ k,ℓ−1 (t + ∆t)
2i∆x2
=( + 4 + β 2 (x2k + y2ℓ )) Ψ k,ℓ (t)
∆t
− (1 − iβyℓ )Ψ k+1,ℓ (t) − (1 + iβyℓ )Ψ k−1,ℓ (t)
− (1 + iβx k )Ψ k,ℓ+1 (t) − (1 − iβx k )Ψ k,ℓ−1 (t) (7.22)
7.2.3 Evaluation
Figures 7.6 and 7.7 show the temporal evolution of a wave packet with and without a
magnetic field. The initial condition is chosen with
⃗
Ψ(x, y, 0) = ei k0 x⃗ e−(x−⃗ x⃗ 0 ) /2σ 2
2
(7.24)
where
k⃗ 0 = (100, 70) , x⃗ 0 = (π/2, π/2) , σ = 1/20 .
Fig. 7.6: Temporal evolution of the wave packet (7.24), computed with the scheme (7.22), snapshots
at equidistant times without magnetic field. Plotted are the contour lines of |Ψ|2 as well as the ‘tra-
jectory’ x⃗m (t) = ⟨Ψ| x|Ψ⟩.
⃗
204 | 7 Partial differential equations II, applications
Fig. 7.7: If the magnetic field is switched on (B 0 = −300), the particle travels along segments of a
circle.
The FD-grid consists of 200 × 200 points, and the step sizes are
∆x = π/199 , ∆t = 5 ⋅ 10−6 .
The solid black lines depict the mean of position. Clearly one recognizes at least in the
beginning and as long as the wave packet is still localized, the classically expected
path, including reflections at the side walls.
Here we shall concentrate on incompressible fluids with ρ = ρ 0 = const. and start with
the isothermal case T = const. Conservation of momentum and total mass leads to the
Navier–Stokes equations and the continuity equation, respectively [1]
1
∂ t v⃗ + (v⃗ ⋅ ∇) v⃗ = ν∆ v⃗ − ∇P , (7.25a)
ρ0
∇ ⋅ v⃗ = 0 , (7.25b)
where ν denotes the, here constant, kinematic viscosity².
2 If ν is not constant, for instance for non-Newtonian fluids or nonisothermal problems, (7.25a) be-
comes more involved. We refer to textbooks of hydrodynamics, e.g., [1].
7.3 Fluid mechanics: flow of an incompressible liquid | 205
7.3.1.2 Vorticity
The vorticity of a given flow is defined by the curl
ξ ⃗ = curl v⃗ .
In two dimensions and with (7.27) this simplifies to the scalar field
ξ = −∆Ψ . (7.28)
3 In fluid dynamics the notion ‘particle’ stands rather for a volume element of the continuum swim-
ming with the flow.
206 | 7 Partial differential equations II, applications
Boundary conditions are necessary in (7.29) as well as for the inversion of (7.28). Along
a rigid no-slip wall both components of v⃗ must vanish. We take as an example, the wall
at x = 0. From v⃗ = 0 it follows from (7.27)
∂ x Ψ(x = 0, y) = ∂ y Ψ(x = 0, y) = 0 .
Hence, Ψ must be a constant along the wall and since only derivatives of Ψ occur we
may put
Ψ(x = 0, y) = 0 , ∂ x Ψ(x = 0, y) = 0 . (7.30)
But now we have two conditions for Ψ, namely Dirichlet and Neumann, but none for
the vorticity ξ . To end up with a well-defined problem one must somehow ‘distribute’
the conditions to the two arrays Ψ and ξ [2].
Equation (7.28) can be uniquely inverted with the Dirichlet condition Ψ = 0. To
include also the Neumann condition, we expand Ψ at x = 0 up to the second order
and make use of (7.30):
1
Ψ(∆x, y) = ⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟
Ψ(0, y) + ⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟
∂ x Ψ(0, y) ∆x + ∂ xx Ψ(0, y)∆x2 . (7.31)
=0 =0
2
If Ψ is constant along the wall, its second derivative ∂ yy Ψ also vanishes. Then (7.28)
reduces to
ξ(0, y) = −∂ xx Ψ(0, y)
and, substituted in (7.31), a Dirichlet condition for ξ can finally be stated:
2Ψ(∆x, y)
ξ(0, y) = − . (7.32)
∆x2
U0
Ψ = 0, ξ = −2Ψ(x = L − Δ x, y)/Δ x 2
Ψ = 0, ξ = −2Ψ(x = Δ x, y)/Δ x 2
Ψ = 0, ξ = −2Ψ(x, y = Δ x)/Δ x 2 L
Fig. 7.8: Driven cavity with boundary conditions. The upper wall moves with the constant velocity U 0
to the right. Inside the fluid (gray) vorticies are created.
7.3.2.3 Algorithm
The discretization of x and y is achieved using finite differences with step size ∆x.
We refer to the algorithm of Section 7.3.1.3. For step (2) the ADI-method introduced in
Section 6.2.2.2 is implemented. Here we wish to explain step (3), the numerical inte-
gration of the vorticity equation (7.34), in more detail, see also [2]. Substitution of the
time derivative by the forward differential quotient of the first order yields the one-step
scheme⁵
ξ(t + ∆t) − ξ(t) 1
= −∂ x (u(t )ξ(t )) − ∂ y (v(t )ξ(t )) + ∆ξ(t ) , (7.35)
∆t Re
which can be, depending on t , an explicit (t = t) or an implicit (t = t + ∆t) scheme.
Introducing the variation
δξ = ξ(t + ∆t) − ξ(t) (7.36)
we may formulate (7.35) as
δξ = ∆t (A x + A y ) ξ(t ) (7.37)
1
Ax = L − L x (u)
R e xx
1
Ay = L − L y (v) ,
R e yy
with
ξ i+1,j − 2ξ i, j + ξ i−1,j u i+1,j ξ i+1,j − u i−1,j ξ i−1,j
L xx ξ = , L x (u)ξ = ,
∆x2 2∆x
ξ i,j+1 − 2ξ i, j + ξ i,j−1 v i,j+1 ξ i,j+1 − v i,j−1 ξ i,j−1
L yy ξ = , L y (v)ξ = .
∆x2 2∆x
A semi-implicit method (Crank–Nicolson) converges more quickly and has a higher
accuracy compared to a fully explicit one. Instead of (7.37) we choose
1 1
δξ = ∆t (A x + A y ) ξ(t) + ∆t (A x + A y ) ξ(t + ∆t) , (7.38)
2 2
which can be converted with (7.36) into
1
[1 − ∆t (A x + A y )] δξ = ∆t (A x + A y ) ξ(t) . (7.39)
2
The expression in the square brackets can be factorized
1 1 1
[ . . . ] = (1 − ∆t A x ) (1 − ∆t A y ) − ∆t2 A x A y ,
2 2 4
where the last term is of order ∆t2 and will be self-consistently neglected. The inver-
sion of the square bracket in (7.39) can now be achieved in two consecutive steps where
in each step only a tridiagonal matrix must be inverted.
Step (I):
1
(1 − ∆t A x ) δξ ∗ = ∆t (A x + A y ) ξ(t) . (7.40)
2
Applying the Thomas algorithm, δξ ∗ can be computed efficiently.
Step (II):
1
(1 − ∆t A y ) δξ = δξ ∗ . (7.41)
2
As for the ADI-method, i, j must be exchanged to obtain A x and A y in tridiagonal form.
Finally, ξ(t + ∆t) can be determined from
7.3.2.4 Results
We present results on a 200 × 200 grid with ∆x = 1/199, ∆t = 1.25 ⋅ 10−4 , and
for two different Reynolds numbers. The stream lines at several times are depicted
in Figures 7.9 and 7.10. As it is known from the literature [4], the stationary vortices for
smaller R e become oscillatory unstable at about R e ≈ 8000, what can be seen from
the figures. In Figure 7.11 we show the total deviation (7.36)
200
δ ξ ̄ (t) = ∑ |δξ ij (t)| (7.42)
i,j=1
over time for the two runs. For R e = 5000 a stationary state is reached after t ≈ 100.
Fig. 7.9: Driven cavity, time series for R e = 5000. The state in the right frame is stationary. Times are
in units of τ = 2s (water, cavity length 10 cm, U 0 = 5 cm/s).
210 | 7 Partial differential equations II, applications
Fig. 7.10: Time series for R e = 10 000. Here the stream lines remain time-dependent, τ = 1s, U 0 = 10
cm/s.
To get a feeling for the time and length scales, we go back to dimensionful quanti-
ties and take water as the fluid with ν = 10−6 m2 /s. For R e = 5000 and L = 0.1 m
a lid speed of U0 = 0.05 m/s results. For the time scale, one finds τ = L/U0 = 2 s.
At R e = 10 000 (Figure 7.10) and the same cavity size, one has U0 = 0.1 m/s and
τ = 1 s.
7.3 Fluid mechanics: flow of an incompressible liquid | 211
0.8
Re = 10000
0.6
0.4
0.2 Re = 5000
0
0 10 20 30 40 50 60 70 80 90 100
t
Fig. 7.11: The integrated deviations (7.42) over time. For R e = 10 000 the flow field remains time-
dependent.
Now we can come back to the question of the temperature distribution in a heated
room with insulating walls from Section 6.2.3.2. There we assumed pure thermal dif-
fusion caused by heat conduction of the air in rest and found that it would take many
days to obtain a somewhat homogeneous temperature across the room. By an exten-
sion of the code developed in the previous section we are now able to account for the
flow field of the air caused by the temperature gradients, a process also named convec-
tion. Contrary to the former system from Section 6.2.3.2 we simplify the situation and
assume isolating walls on the left, right, and on the ceiling. Along the lower side we
prescribe a fixed and constant temperature T0 , corresponding to floor heating. Win-
dow and stove are removed.
6 The boundary condition at y = L is thereby only approximately fulfilled, however the error remains
small as long as t << τ.
212 | 7 Partial differential equations II, applications
Ψ = 0, ξ = −2Ψ(x, y = Δ x)/Δ x 2, T = T0 L
Fig. 7.12: A room uniformly heated from below and its boundary conditions.
Here, κ again denotes the thermal diffusivity of the air and erf(x) stands for the error
function. The solution (7.43) describes a temperature front moving slowly from the
floor to the ceiling by thermal diffusion. The time needed to cross the room is in the
order of the thermal diffusion time
τ = L2 /κ (7.44)
and amounts for L = 3 m about 5 days, as already computed in Section 6.2.3.2. To ac-
count for the air flow, the diffusion equation must be extended to the transport equa-
tion
∂ t T + v⃗ ⋅ ∇T = κ∆T .
The air begins to move due to buoyancy. Warm air is lighter and tends to move up-
wards; cold air descends in a vertical gravitation field. Assuming a linear relation
(Boussinesq approximation) between density ρ and temperature
ρ(T) = ρ 0 (1 − α(T − T0 ))
where
1 dV
α=
V dT T=T0
7.3 Fluid mechanics: flow of an incompressible liquid | 213
is the thermal expansion coefficient, on the ride-hand side of the Navier–Stokes equa-
tion (7.25a) an additional volume force density occurs
ρ(T)g
− ê y = −g (1 − α(T − T0 )) ê y
ρ0
with the gravitation acceleration g = 9.81 m/s2 . Since no reference velocity U0 exists,
the scaling we choose here differs from that of Section 7.3.2.2:
L ⃗
v⃗ = ṽ , (x, y) = (L x,̃ L y)̃ , t = τ t̃ , T = T0 Θ
τ
with τ from (7.44). The complete system thus reads (tildes removed)
1
[∂ t ξ + v x ∂ x ξ + v y ∂ y ξ ] = ∆ξ + R ∂ x Θ (7.45a)
Pr
ξ = −∆Ψ (7.45b)
∂ t Θ + v⃗ ⋅ ∇Θ = ∆Θ (7.45c)
gαL3 T0
R= . (7.46)
κν
R ≈ 7 ⋅ 1010 .
Fig. 7.13: Evolution of the temperature field, time series for R = 108 . The flow becomes turbulent
soon. The times stated are valid for air (τ = 0.45 ⋅ 106 s).
The air flow becomes turbulent almost immediately and small-scaled vortices are cre-
ated, which demand an extremely high resolution in space; see also Section 7.3.3.4
below. Since the code should run on a normal PC, we take the much smaller value
R = 108 for which a 200 × 200 grid
proves to be sufficient. Figure 7.13 depicts contour lines of the temperature field at sev-
eral times; see also Figure 1.4. The diffusion front (7.43) becomes unstable after about
7.3 Fluid mechanics: flow of an incompressible liquid | 215
Fig. 7.14: Averaged temperature of the ceiling (7.47) for convection (R = 108 ) and pure diffusion
(R = 0). For this Rayleigh number, convection leads to an at least fifty times larger heat transport
than diffusion alone.
4 minutes and a vortex flow occurs that entrains and quickly distributes the tempera-
ture field in the whole room. Thereby, the heat transport from the floor to the ceiling
becomes much more effective, which can be clearly seen at the time dependence of
the mean ceiling temperature
1
1 200
Θ1 (t) = ∫ dx Θ(x, y = 1, t) = ∑ Θ i,200 (t) (7.47)
200 i=1
0
T(x, y = L) = 0 , (7.48)
Θ(0) = 1 − y , v⃗ = 0 , (7.49)
216 | 7 Partial differential equations II, applications
i.e., a linear temperature profile with the air in rest, is a solution of (7.45). Linearizing
the dimensionless equations around this state yields the system
1
∂ t ξ = ∆ξ + R ∂ x Θ̃ (7.50a)
Pr
ξ = −∆Ψ (7.50b)
∂ t Θ̃ = ∆ Θ̃ − ∂ x Ψ (7.50c)
with Θ̃ = Θ − Θ(0) . Idealizing the boundary conditions for the vorticity and stream
function as⁹
ξ =0, Ψ =0
at all four boundaries, the linear problem (7.50) can be solved exactly with
0≤y≤∞
and the scaling length L used above is no longer of relevance. Instead, we take now
the space and time scaling
ℓ2
(x, y) = (ℓx,̃ ℓy)̃ , τ=
κ
9 This leads for v⃗ to the free boundary conditions that actually could be only valid at a plane and free
surface.
7.3 Fluid mechanics: flow of an incompressible liquid | 217
with
κν 1/3
ℓ=( )
gαT0
and obtain a system similar to (7.45) but now only with one parameter, the Prandtl
number, left:
1
[∂ t ξ + v x ∂ x ξ + v y ∂ y ξ ] = ∆ξ + ∂ x Θ (7.54a)
Pr
ξ = −∆Ψ (7.54b)
∂ t Θ + v⃗ ⋅ ∇Θ = ∆Θ . (7.54c)
Performing a linear stability analysis about the (scaled) base state (7.43)
results in a linear system with an explicit time dependence. The trick of the ‘frozen
time’ analysis, or approximation, is to decouple the time scales of the base state and
that of its disturbances. Thus we may consider the time in (7.55) as ‘frozen’ and call
it t∗ , which brings an additional control parameter into play. Substituting
λ
(k 2 Φ − Φ ) = −Φ + 2k 2 Φ − k 4 Φ − k 2 ϑ
Pr (7.57)
λϑ = ϑ − k 2 ϑ + (∂ y T (0) ) Φ
with
1 y2
∂ y T (0) = − e− 4t∗
√πt∗
with primes denoting y-derivatives. The remaining task is to determine the critical
time t∗c for which the largest eigenvalue λ becomes positive and the perturbations (7.56)
may start to grow exponentially. This can be achieved by discretizing (7.57), e.g., with
finite differences and solving the linear system by a standard routine as DGGEV, for
instance; see Figure 7.15. Again, the infinite y-domain must be approximated by a finite
length L, which however, must be large compared with the size of the diffusion front
(7.55), thus
2√t∗ ≪ L
must be checked self-consistently.
If we use the realistic values for a room as stated in Section 7.3.3.2 and leading to
R = 7 ⋅ 1010 , we find ℓ ≈ 0.73 mm and τ ≈ 0.026 s. Thus, the front would be unstable
almost immediately at t c ≈ 0.08 s and the typical wave length of the growing vortices
is estimated with Λ = 2π/k c ≈ 2.5 cm.
218 | 7 Partial differential equations II, applications
t*
stable
t*c
kc
k
Fig. 7.15: Stability chart found numerically by solving (7.57). Modes above the zero line λ = 0 (bold)
are unstable. Instability occurs first at t c∗ ≈ 3.2 with k c ≈ 0.18.
The Rayleigh number computed from (7.46) for a normal room is larger than the crit-
ical one by a factor of about 108 . Since R ∼ L3 this changes if one goes to the ‘lab-
oratory scale.’ Taking for instance L = 1 cm and instead of air a 50 cs silicone oil
ν = 5 ⋅ 10−5 m/s2 , α = 0.7 ⋅ 10−3 1/K, a Rayleigh number of
R ≈ 1400
results for a vertical temperature difference of one degree, a value rather close to the
critical one.
Hence, lateral boundaries play a negligible role and the linearized system is instead
of with (7.51), better solved by a plane wave ansatz of the form
Periodic lateral boundary conditions are fulfilled for certain wave numbers
2π
kn = n.
Lx
For large L x , k can be considered continuous, and we can leave the index n. Periodic
structures in x direction with wave length Λ = 2π/k are obtained, as in Figure 7.16.
With (7.58) one finds instead of (7.53) the relation
(k 2 + m2 π2 )3
R cm (k) = (7.59)
k2
from which the minimal R c for m = 1 and k = k c = π/√2 is computed as
27π4
Rc = ≈ 658 .
4
∂y Ψ ∂x ∂z Φ
v⃗ = (−∂ x Ψ ) + (∂ y ∂ z Φ ) . (7.60)
0 −∆2 Φ
220 | 7 Partial differential equations II, applications
Here, ∆ denotes the complete 3D-Laplacian and ∆2 = ∂2xx + ∂2yy its horizontal ver-
sion. From here on, the vertical component is denoted with z. Forming the curl of the
Navier–Stokes equations (7.25a) its z-component reads:
1 1
{∆ − ∂ t } ∆2 Ψ(r,⃗ t) = − [∇ × ((v⃗ ⋅ ∇)v)]
⃗ . (7.61)
Pr Pr z
An equation for Φ is obtained by twice applying the curl, according to
1 1
{∆ − ∂ t } ∆∆2 Φ(r,⃗ t) = −R ∆2 Θ(r,⃗ t) − [∇ × ∇ × ((v⃗ ⋅ ∇)v)]
⃗ . (7.62)
Pr Pr z
For the temperature field one gets
{∆ − ∂ t } Θ(r,⃗ t) = −∆2 Φ(r,⃗ t) + (v⃗ ⋅ ∇)Θ(r,⃗ t) . (7.63)
The necessary boundary conditions for Φ and Ψ follow from the ansatz (7.60). We fo-
cus on laterally periodic boundary conditions. No-slip conditions at the lower and
upper boundaries require the vanishing of all three velocity components, leading to
Φ(r,⃗ t) = Ψ(r,⃗ t) = ∂ z Φ(r,⃗ t) = 0 , z = 0, 1 . (7.64)
For the temperature field, a general (Robin) condition applies
∂ z Θ(r, t) = ±Bi Θ(r, t) z = 0, 1 , (7.65)
with another dimensionless parameter Bi, called Biot number¹². It describes the ratio
of thermal conductivities of the boundary plates to that of the liquid. If the boundaries
are perfect conductors (metal) Bi → ∞, a bad or nearly insulating material like glass
or plastic is reflected by Bi ≪ 1.
The system (7.61–7.65) completely describes the convection of a Newtonian liquid
in the Boussinesq approximation. For the sake of simplicity we shall concentrate fur-
ther on the limit of a large, or better infinite, Prandtl number. This is a very good ap-
proximation for viscous fluids like many oils, at least not too far from threshold R c .
If Pr → ∞ (7.61) reduces to
∆∆2 Ψ(r,⃗ t) = 0 ,
which allows, in combination with the boundary conditions in (7.64), only the trivial
solution
Ψ =0.
Thus, the infinite Prandtl number case is completely described by the two scalar
fields Φ and Θ. This considerably reduces and simplifies the dynamics of the possible
structures. Near the instability, one usually observes a transient temporal behavior
leading after an initial phase asymptotically to a fixed point consisting of more or less
parallel oriented convection rolls (large Bi) or squares (small Bi). For larger values of
R further instabilities occur and more involved, partially time-dependent structures
can be seen that we shall not further discuss here.
In two spatial dimensions the main task is the inversion of band matrices. In three
room dimensions another method is more suited, the so-called pseudospectral scheme.
Here, the system is split into its linear and nonlinear parts. The linear parts are treated
in Fourier space and can be inverted easily, the nonlinear ones are computed in po-
sition space. This trick avoids the expensive computation of convolution sums in
Fourier space.
We scale the position coordinates so that
0 ≤ x ≤ Lx , 0 ≤ y ≤ Ly , 0≤z≤1.
If periodic lateral boundary conditions are given, a Fourier decomposition with re-
spect to the horizontal coordinates x, y using plane waves as in Section 6.3.2 is nearby.
We apply the 2D-Fourier transforms
J L
⃗
Θ(r,⃗ t) = ∑ ∑ Θ(̃ k⃗ jℓ , z, t) e−i k jℓ x⃗
j ℓ
(7.67)
J L
̃ k⃗ jℓ , z, t) e −i k⃗ jℓ x⃗
Φ(r,⃗ t) = ∑ ∑ Φ(
j ℓ
Substitution in (7.66) and discretization of the time derivative by (we leave the indices
at k)⃗
Θ(̃ k,⃗ z, t + ∆t) − Θ(̃ k,⃗ z, t)
∂ t Θ(̃ k,⃗ z, t) ≈
∆t
leads to the semi-implicit system¹³
1 ̃ k,⃗ z, t + ∆t) = 1 Θ(
( + k 2 − ∂2zz ) Θ(̃ k,⃗ z, t + ∆t) + k 2 Φ( ̃ k,⃗ z, t) − F(̃ k,⃗ z, t) (7.68a)
∆t ∆t
2
(∂2zz − k 2 ) Φ( ̃ k,⃗ z, t + ∆t) + R Θ(̃ k,⃗ z, t + ∆t) = 0 (7.68b)
13 We replace ∆ 2 with −k2 , which is strictly speaking only correct for L x , L y → ∞, see Section 6.3.2.
222 | 7 Partial differential equations II, applications
Q(⃗ k,⃗ t) = (Θ̃ 1 (k,⃗ t), Φ̃ 1 k,⃗ t) , . . . , Θ̃ N (k,⃗ t), Φ̃ N (k,⃗ t))
(7.70)
P(⃗ k,⃗ t) = (Θ̃ 1 (k,⃗ t)/∆t − F̃ 1 (k,⃗ t), 0 , . . . , Θ̃ N (k,⃗ t)/∆t − F̃ N (k,⃗ t), 0)
7.3.4.4 Results
(A) Linear analysis: The critical Rayleigh number R c where the liquid starts to move
and patterns are formed depends on the Biot number. To determine R c we perform a
linear stability analysis of (7.68) just removing the quadratic terms F̃ in (7.68a). To find
the critical point we put ∂ t Θ = 0, i.e., we cancel in M k the terms including ∆t. Writing
in (7.68b) the expression with R on the right-hand side, (7.69) can be formulated as a
generalized eigenvalue problem
M k w⃗ = −R D w⃗ (7.71)
where
{1 for i even and j = i − 1
D ij = { .
0 else
{
The system (7.71) is then solved numerically by a suitable LAPACK routine (e.g.,
SGGEV). Figure 7.17 shows the smallest eigenvalue corresponding to the critical R
needed for the onset of convection, both for a finite and an infinite Biot number and
depending on k.
Tab. 7.1: The band matrix M k has the band width 9.
Ak − a k2 −1/∆z2 0 0 0 ...
R B k + 1/∆z4 0 Ck 0 1/∆z4 0 0 ...
(−1/∆z2
( 0 Ak k2 −1/∆z2 0 0 ... )
)
( 0 Ck R Bk 0 Ck 0 1/∆z4 0 0 ... )
( )
( )
( 0 0 −1/∆z2 0 Ak k2 −1/∆z2 0 0 ... )
( )
( 0
( 1/∆z4 0 Ck R Bk 0 Ck 0 1/∆z4 0 ... )
)
( ... | | )
( )
Mk = ( )
( ... | ------- bandwidth ------- | )
( )
( ... )
( )
( )
( ... )
( )
( ... )
( )
( ... )
... 0 −1/∆z2 0 Ak − a k2
( ... 1/∆z4 0 Ck R B k + 1/∆z4 )
3000
Bi → ∞
2000
R
1000
Bi = 0.5
Fig. 7.17: Critical Rayleigh number where con-
0 vection sets in. Both R c and k c decrease with Bi.
1 2 3 4 5 In particular one finds R c ≈ 1700 for Bi → ∞,
k and R c ≈ 900 for Bi = 0.5.
Fig. 7.18: Temperature field at the midplane z = 1/2 at several times. Left row: Bi → ∞,
R = 1900, t = 75 (top), 150 (bottom), right row: Bi = 0.5 R = 1000, t = 75 (top), 1000 (bottom).
The patterns of the bottom frames are not yet stationary. For t → ∞ one obtains parallel rolls (left)
or a perfect square pattern (right), respectively.
7.4 Pattern formation out of equilibrium | 225
(B) Nonlinear analysis: Figure 7.18 shows the temperature distribution along the mid
plane of the layer, computed by a numerical simulation of (7.68). As an initial condi-
tion, a randomly distributed temperature field
has been applied. The grid consists of 128 × 128 × 20 mesh points, the step sizes are
∆t = 0.05 , ∆x = 0.2 .
From experiment as well as from theory one knows that for small Biot numbers
squares are encountered, for larger ones rolls (or stripes). The hexagons observed
in Bénard’s original work result only if the surface is free and surface tension as a
function of temperature is considered in addition. This is called the Marangoni effect
which we cannot discuss here in more detail.
Based on a system of chemical reactions with K reactants, from the law of mass action
one can systematically derive the reaction equations in the form of a set of nonlinear,
ordinary differential equations for the concentrations w i (t) of the reactant i:
14 Alan Turing, British mathematician, computer scientist, and theoretical biologist, 1912–1954.
226 | 7 Partial differential equations II, applications
Fig. 7.19: Following Alan Turing, coat, skin, or scale patterns on certain animals are created in their
embryonic phase by a chemical nonequilibrium reaction. Randomly placed defects and dislocations
in the otherwise rather regular structures seem to confirm Turing’s hypothesis. Courtesy of Marlies
Bestehorn.
Expanding the f i in (7.74) up to the linear order we obtain for the deviations u i (x, t)
from the fixed point w0i the system
(M − λ 1) v⃗ = 0 (7.79)
Instead of solving (7.80) for λ we may also ask for parameter settings a i , b i where a sta-
ble (old) state (λ < 0) becomes unstable (λ > 0). Hence the critical point is determined
by λ = 0. From (7.80) we find
(D1 k 2 − a1 )(D2 k 2 − a2 ) − b 1 b 2 = 0 ,
a2 b1 b2 1 a1 a2
k 2c = + √− = ( + ) . (7.82)
D2 D1 D2 2 D1 D2
For a1 > a1c the fixed point w0i becomes unstable and the mode (7.78) with k = k c
grows exponentially in time. This spatially periodic structure is nowadays called Tur-
ing instability or Turing structure.
λ = iω (7.83)
228 | 7 Partial differential equations II, applications
with a real valued frequency ω. Inserting (7.83) into (7.80) and separating real and
imaginary parts one obtains the two equations
0 = (D1 + D2 )k 2 − a1 − a2 . (7.84b)
Equation (7.84b) determines the critical point depending on the wave number:
a1 = (D1 + D2 )k 2 − a2 . (7.85)
a1 ≥ −a2 .
Hence the oscillatory mode comes with a long-wave, even homogeneous, spatial struc-
ture, corresponding to
kc = 0 . (7.86)
As already noted in Section 3.2, instabilities belonging to a pair of conjugate complex
eigenvalues are also denoted as Hopf instabilities, and the frequency at the critical
point is named Hopf frequency. It follows from (7.84a) with k = 0:
To obtain a real valued frequency, b 1 b 2 < −a21 must hold. Let b 1 < 0 and b 2 > 0. Then
the substance w1 creates via the coupling b 2 the substance w2 , while w2 diminishes
w1 via b 1 . This is why (7.74) is also denoted as an activator-inhibitor system with w1 as
the concentration of the activator and w2 as that of the inhibitor.
Temporal oscillations of a spatially uniform state were first experimentally ob-
served by Boris Belousov in 1950 and are now named Belousov–Zhabotinskii reac-
tions.
7.4.1.3 Codimension-two
But what happens now if one of the control parameters, say a1 , is increased over the
threshold? The uniform stationary state becomes unstable, but how so exactly is de-
termined by the other parameters. Depending on the values of a1 , b 1 , and b 2 as well
as on the diffusion constants, the homogeneous state will give way either to a time pe-
riodic (Hopf) or to a space periodic (Turing) structure. From mathematics, the notion
codimension is familiar. The codimension of an object is defined as the difference of
the dimension of the room in which the object lives and the dimension of the object
itself. A plane in the three-dimensional space possesses the codimension 3 − 2 = 1.
Instability conditions like (7.81) or (7.85) determine the value of one parameter related
to the others. They define an n −1-dimensional subspace of the n-dimensional param-
eter space and therefore have the codimension one.
7.4 Pattern formation out of equilibrium | 229
Fig. 7.20: Sketch of Turing and Hopf instability for the two-equation system (7.76). If increasing a1
and a2 < a2CD2 , the Turing instability comes first (a), if a2 > a2CD2 the Hopf instability occurs directly
above threshold (b). For (c), a2 = a2CD2 .
But now we can adjust the parameters in such a way that the Turing and Hopf modes
are unstable at the same a1 . This additionally restricts the parameter setting into an
n − 2-dimensional subspace. A ‘double’ instability of this kind is named codimension-
two instability (CD2); see also Figure 7.20.
Inserting the critical wave number (7.82) into (7.81), one finds the smallest neces-
sary value for a1 to get a Turing instability:
D1 D1
a1T = a2 + 2√−b 1 b 2 . (7.88)
D2 D2
In the same way one obtains for the oscillatory instability from (7.85) with (7.86)
vated by the chemical oscillations discovered about ten years before by Belousov¹⁶ and
consisted in its original form of two coupled ODEs (K = 2). Later, diffusion terms were
added and spatio-temporal pattern formation was examined extensively. The system
has the form of (7.74) and may show, depending on parameters, either Hopf or Turing
instabilities.
(A) Equations and linear analysis. For the Brusselator one finds
Since there are only two free parameters (A, B), the four coefficients a i , b i of the Ja-
cobian (7.77) are not independent from each other and read
a1 = B − 1 , b1 = A2 , a2 = −A2 , b 2 = −B . (7.92)
(T) A2 + (D1 A2 + D2 )k 2 + D1 D2 k 4
Bc =
D2 k2
(H)
Bc =(D1 + D2 )k 2 + A2 + 1 . (7.93)
From (7.82) we obtain for the Turing mode the critical wave number
A
k 2c = . (7.94)
√D1 D2
2√D1 D2 (D1 + D2 )2
A CD2 = , B CD2 = . (7.96)
D2 − D1 D2 − D1
Figure 7.21 shows the parameter plane for D1 = 1/2, D2 = 1. Depending on A, both
instability types are possible.
u 1 = w1 − A , u 2 = w2 − B/A
∂ t u 1 = D1 ∆u 1 + (B − 1) u 1 + A2 u 2 + f(u 1 , u 2 ) (7.97a)
2
∂ t u 2 = D2 ∆u 2 − B u 1 − A u 2 − f(u 1 , u 2 ) (7.97b)
∆t + D 2 k + A
1 2 2
1 A2
M −1
k = ( ) .
Det M k −B 1
+ D1 k2 + 1 − B
∆t
232 | 7 Partial differential equations II, applications
t = 200 t = 200
Fig. 7.22: Depending on the value of A, for the plane (2D) Brusselator either (asymptotically station-
ary) Turing structures (left, A = 0.8), or spatially large-scaled temporally oscillating Hopf patterns
(right, A = 0.35) emerge. For D1 /D2 = 0.1 it follows that A CD2 ≈ 0.7.
t = 15 t = 26
t = 34 t = 50
Fig. 7.23: Spreading fronts can be seen for other parameters in the oscillatory region. They are sim-
ilar to the chemical nonequilibrium patterns observed experimentally in the Belousov–Zhabotinsky
reaction. Time series for D1 /D2 = 0.5, A = 0.2, B = 1.2.
7.4 Pattern formation out of equilibrium | 233
clear
n=512; % mesh points
% parameter input
d=input('d1/d2? ');
acd2=2.*sqrt(d)/(1.-d) % cd-2 point
a=input('value for a? ');
bh=1.+a^2 % threshold Hopf mode
bt=(1.+a*sqrt(d))^2 % threshold Turing mode
b=input('value for b? '); ba=b/a;
if(n==100) % plotting
n=0; contour(u1); drawnow; t
end
end
7.4.2.1 Motivation
Turing structures originate from instabilities where the fastest growing, most unstable
modes have a finite wave number k c . If we evaluate for instance (7.80) for the Brusse-
lator, a growth rate λ(k 2 ) is obtained in the super-critical domain B > B c as shown in
Figure 7.24. The function λ(k 2 ) seems to be rather involved, including a square root. If
λ
0.01
rg
be
en
k2
oh
0
−H
2 2.5 3 3.5
ift
Sw
–0.01
r
lato
sse
k2c
–0.02
Bru
–0.03
–0.04
Fig. 7.24: The basic idea behind the Swift–Hohenberg equation is to expand the eigenvalue λ(k2 ) of
a Turing instability, here for the Brusselator, in the neighborhood of the critical point, leading to the
polynomial (7.101). Parameters: D1 = 0.1, D2 = 1, A = 0.8, B c = 1.57, B = 1.01B c .
7.4 Pattern formation out of equilibrium | 235
we restrict ourselves only to the region of the unstable (linearly growing) modes, we
may expand λ at B c , k 2c , according to:
with
∂λ 1 ∂2 λ
a= , b=− .
∂B B c ,k2c 2 ∂(k ) B c ,k2c
2 2
In position space one may simply replace k 2 with −∆ and obtain a linear PDE whose
solution reflects the instability behavior (7.101):
After appropriate scaling of time and space, (7.102) takes the form
dt L ≤ 0 (7.107)
17 The original work was for A = 0. The extension with a square term was first proposed and studied
by H. Haken [6].
236 | 7 Partial differential equations II, applications
7.4.2.2 Algorithm
For periodic boundary conditions it is easy to construct a pseudospectral scheme as
already done in Section 7.4.1.4. Since we now have only one equation to iterate, the
matrix inversion turns into a simple division in Fourier space:
f k (Ψ(t))
Ψ k (t + ∆t) = (7.108)
1/∆t − ε + (1 − k 2 )2
with the Fourier transform f k of
Ψ
f(Ψ) = + A Ψ2 − Ψ3 .
∆t
Another possibility is the discretization in position space with finite differences. Let
N be the number of mesh points in each direction (for simplicity we assume a square
geometry). We organize the node values in a one-dimensional vector Φ k , k = 1 . . . N 2
as in (7.23) and formulate a large (N 2 ) system of equations
N2
Φ i (t)
∑ M ij Φ j (t + ∆t) = + A Φ2i (t) − Φ3i (t)
j
∆t
clear;
n=200; dx=0.5; dx2=dx^2; dt=3; tend=1000; eps=0.1; a=0.;
lap=-gallery('poisson',n); lap2=lap*lap; % Laplace and biharmonic FD in 2D
pot=speye(n^2)+lap/dx2; % matrix needed for Lyapunov potential
m=(1/dt-eps+1)*speye(n^2)+2*lap/dx2+lap2/dx2^2; % matrix M
psi=zeros(n);
k=0;
for t=0:dt:tend % time loop till tend
k=k+1;
phi=(phi/dt-phi.^3+a*phi.^2)/m; % matrix inversion
lyap=eps*phi.^2-.5*phi.^4+2./3.*a*phi.^3-(phi*pot).^2; % potential
lyap_plot(k)=-0.5*dx2*sum(lyap); t_plot(k)=t; % plot values
7.4 Pattern formation out of equilibrium | 237
5 200
0 150
–5 100
–10 50
–15
0 50 100 150 200 50 100 150 200
Fig. 7.25: Numerical solution of the Swift–Hohenberg equation at t = 200 for ε = 0.1, A = 0 (right)
and Lyapunov functional (7.106) over t (left), computed on a 200 × 200 grid and for a random-dot
initial condition.
10 200
0 150
–10 100
–20 50
–30
0 50 100 150 200 50 100 150 200
It produces output as shown in Figures 7.25, 7.26. After t = 200 the depicted patterns
are not completely stationary but still evolving towards their fixed points. Performing
a linear analysis around a perfectly regular stripe solution, it turns out that at a critical
value
√3ε
Ac =
2
238 | 7 Partial differential equations II, applications
stripes become unstable and give way to hexagons already found for the Brusselator. If
the symmetry Ψ → −Ψ is broken, i.e., A ≠ 0, one always finds hexagons directly above
threshold ε = 0 since A c = 0. Thus, hexagons are the typical (generic) structure for a
Turing instability with no further symmetry restrictions. As a secondary instability for
larger ε stripes, or for more involved nonlinearities, squares may also occur.
Ψ =0, n̂ ⋅ ∇Ψ = 0 (7.109)
with n̂ normal to the boundaries. Conditions of the form (7.109) can be realized by
modifying the diagonal elements of the matrix ‘lap2’ that belong to the points next to
the four sides, according to
for j=1:n:n^2
j1=j+n-1;
lap2(j,j)=lap2(j,j)+2; lap2(j1,j1)=lap2(j1,j1)+2;
end
for j=1:n
j1=j-n^2-n-1
lap2(j,j)=lap2(j,j)+2; lap2(j1,j1)=lap2(j1,j1)+2;
end
This code section must be included in the code on page 236 before computing the
matrix ‘m’ in line 5. The modification of the diagonal elements can be understood by
assuming a ‘virtual line’ outside of the integration domain, as explained in more detail
in Section 6.2.2.1.
7.4.3 Problems
Similar to the derivation in Section 7.4.2.1, a model equation valid for the weakly non-
linear case close to an oscillatory (Hopf) instability can be found. This equation is also
named the complex Ginzburg–Landau equation and reads:
∂ t Ψ(x, t) = [ε + iω0 + (1 + ic1 ) ∂2xx ] Ψ(x, t) − (1 + ic3 )|Ψ(x, t)|2 Ψ(x, t) (7.110)
Bibliography | 239
Ψ = A exp(iΩt) (7.111)
c1 c3 < −1 . (7.112)
3. Solve (7.110) for ε = 0.1 numerically using an FTCS scheme in the stable regime,
i.e., for
c1 = 1/2 , c3 = −1/2 ,
and in the unstable regime, i.e., with
c1 = 1/2 , c3 = −4 .
Take L = 800, ε = 0.1 and the step sizes ∆x = 0.8 und ∆t = 0.05. As the
initial condition, assume a random dot distribution of Ψ(x, 0) in the interval
0.9A . . . 1.1A. Represent the solution graphically in a space-time diagram.
4. If (7.112) is fulfilled, (7.110) possesses spatio-temporal solutions that are chaotic.
Examine them by determining their largest Lyapunov exponent Λ for different val-
ues of c3 and fixed c1 = 1/2. Plot Λ as a function of c3 .
Bibliography
[1] L. D. Landau and E. M. Lifshitz, Fluid Mechanics, Vol. 6, Butterworth–Heinemann, 2nd edn.
(1987).
[2] C. A. J. Fletcher, Computational Techniques for Fluid Dynamics 2, Springer (2013).
[3] FORTRAN codes at http://www.degruyter.com/books/978-3-11-051513-8
[4] C. H. Bruneau, The 2D lid-driven cavity problem revisited, M. Saad, Computers & Fluids 35, 326
(2006).
[5] P. N. Swarztrauber and R. A. Valent, FFTPACK5 – a FORTRAN library of fast Fourier transforms,
http://www.netlib.org/fftpack, February 11, 2018.
[6] H. Haken, Synergetics: Introduction and Advanced Topics, Springer (2012).
[7] A. M. Turing: The chemical basis of morphogenesis, Phil. Trans. R. Soc. London B 237, 37 (1952).
[8] J. D.Murray, Mathematical Biology, Springer (2008).
[9] J. Swift, P. C. Hohenberg, Hydrodynamic fluctuations at the convective instability, Phys. Rev. A15,
319 (1977).
8 Monte Carlo methods (MC)
The terms ‘Monte Carlo methods’ or ‘Monte Carlo simulations’ refer to a variety of nu-
merical methods mainly based on random numbers. On the one hand these can be
problems arising from physics where fluctuations or other random processes play a
central role, for example thermal motion in statistical physics, trajectories of particles
in disordered media, or equilibrium phase transitions. On the other hand, mathemat-
ical problems like the approximate computation of high-dimensional integrals or the
determination of extreme values in a high-dimensional variable space can be often
only tackled by MC methods.
Since random numbers play a crucial role, we wish to start with their properties and
their realization on a computer. Because all processes on computers are in principle
deterministic, one should better talk about ‘pseudorandom numbers’. A pseudoran-
dom number generator is implemented in FORTRAN95. The statement
CALL RANDOM_NUMBER(x)
assigns to the real variable x an equally distributed random number in the interval
0≤x<1. (8.1)
If x is defined as a real valued array, all its elements are filled with different random
numbers.
Random number generators are based on maps of the form
A simple, however not applicable, example with n = 1 is the logistic map somewhere
in the chaotic region, studied in Chapter 1. FORTRAN95 uses different maps with a
much larger n, producing much better and much less correlated random sequences.
The value of n thereby depends on the compiler and operating system. The actual n
can be found by
CALL RANDOM_SEED(size=n),
for GNU-FORTRAN running under Linux one obtains n = 12. At each run the very same
values (x1 . . . x n ) are initialized and as a consequence exactly the same reproducible
random series is generated. This can be changed by the call
CALL RANDOM_SEED(put=ix),
https://doi.org/10.1515/9783110515145-008
8.1 Random numbers and distributions | 241
where ix is an integer array of length n, containing the initial values for the iteration
(8.2). If one wishes to create a different sequence for each run, one can link the initial
values to the system clock. A subroutine for the initialization is given below; see also
Appendix B:
SUBROUTINE RANDOM_INIT
INTEGER, DIMENSION(100) :: ix ! auxiliary array for initial values
CALL RANDOM_SEED(size=n)
CALL SYSTEM_CLOCK(ic)
ix=ic
CALL RANDOM_SEED(put=ix(1:n))
END
The distribution function Φ(x) denotes the probability to draw a random variable X
that is less than x. For the equal (rectangular) distribution (8.1) it follows
{
{ 0, if x < 0
{
Φ r (x) = { x , if 0 ≤ x < 1 . (8.3)
{
{
{1 , if 1 ≤ x
can be computed. The integrals thereby run over the domain of definition of the ran-
dom variable. If, on the other hand, a series x1 . . . x k of randomly distributed numbers
is given, one evaluates mean and variance as
1 k 1 k 2
⟨x⟩ = ∑ xi , Var(x) = ∑ x − ⟨x⟩2 .
k i=1 k i=1 i
Particularly for the equal distribution in [0, 1) one finds
⟨x⟩ = 1/2 , Var(x) = 1/12 .
8.1.3.1 Acceptance-rejection
We seek for a random variable y in the region
a≤y<b (8.9)
with given PDF ρ(y). First we draw an equally distributed x1 ϵ [0, 1) and stretch it to
the interval (8.9)
y = a + (b − a) x1 .
This value should be accepted with the probability ρ(y)/ρ m , where ρ m denotes the
maximum of ρ. To this end one determines another equally distributed number x2
and accepts y if
x2 ≤ ρ(y)/ρ m . (8.10)
Otherwise, y is rejected and the process of drawing two new numbers x1 , x2 is repeated
as long as (8.10) is fulfilled. The method can be readily extended to higher dimensional
distributions ρ(x, y, . . . ). If one wishes to construct a distribution having long tails,
ρ(y)/ρ m can become rather small and many trials to find an acceptable value y can
become necessary, making the method slow and inefficient.
Φ(y) = Φ r (x) ,
1800
1600
1400
1200
1000
800
600
400
200
0
0 0.5 1 1.5 2 2.5 3 3.5
Fig. 8.1: Histogram of y from (8.13) for 100 000 randomly drawn numbers.
To demonstrate the method we give an example. Let us find f for a variable y ϵ [0, π)
with the desired PDF
1
ρ(y) = sin y . (8.12)
2
y
Because Φ = ∫0 dy ρ(y ) = 12 (1 − cos y) we obtain from (8.11)
n=100000;
y=acos(1-2*rand(1,n));
hist(y,100)
provides a histogram of y, Figure 8.1, where the PDF (8.12) can be identified clearly.
2000 3500
3000
1500 2500
2000
1000
1500
500 1000
500
0 0
–4 –2 0 2 4 –5 0 5
Fig. 8.2: Histograms of y from (8.14) for 100 000 random numbers, left for N = 2, right for N = 50.
(A) Central limit theorem. According to the central limit theorem of statistics, the
sum of infinitely many equally distributed random numbers provides a normally
distributed number. Let x i be a series of equally distributed numbers in [0, 1). Then
N
1
y = y0 + a ∑ (x i − ) (8.14)
i
2
for increasing N approaches more and more a Gaussian distributed variable in the
domain
y0 − aN/2 ≤ y < y0 + aN/2
with mean ⟨y⟩ = y0 and variance
a2 N
Var(y) = ⟨(y − y0 )2 ⟩ = a2 N Var(x) = .
12
In practice a rather small N is quite often sufficient. If one is not interested in rather
small or large y (again the tails) one can produce quite accurately distributed num-
bers already for N ≈ 50; see Figure 8.2. A code producing an approximately Gaussian
distributed random number with given mean and variance could look like this:
with equally distributed x ϵ [0, 1). Eventually the variable w should be in the interval
[0, ∞) and therefore c = 1. We can thus write the initial velocity for each particle as
where the angle φ should be equally distributed in [0, 2π). Finally we obtain for an
initial equilibrium velocity distribution with temperature T
with the two independently drawn random numbers x1 , x2 in [0,1). The relations (8.15)
are denoted as the Box–Muller method.
with
x i = (i − 1)∆x + a , ∆x = (b − a)/(N − 1) .
The order k of the error in (8.16) depends on the choice of the weights g i . Thus one
obtains the rectangle rule for
gN = 0 , gi = 1 , i = 1...N −1
246 | 8 Monte Carlo methods (MC)
with k = 1. For
g1 = g N = 1/2 , gi = 1 , i = 2...N −1
the trapezoidal rule yields k = 2 and for
the even more accurate Simpson rule is achieved having k = 4. Central to all formulas
is a systematic evaluation of the integrand f(x) at many points.
Instead of a systematic evaluation, Monte Carlo integration is based on the com-
putation of the integrand at N randomly chosen points x i in a ≤ x i ≤ b. Due to scaling
and shifting x can always be transformed to the domain a = 0, b = 1 and we shall
further consider only this case here. The integral (8.16) is thus computed with
1 N
J= ∑ f(x i ) + O(1/N k ) (8.17)
N i
with arbitrary x i ϵ [0, 1] drawn with a certain given probability density ρ(x). Compared
to (8.16) the numerical effort seems to be the same. One has to evaluate f for N different
x i . How large is the error exponent k in (8.17)?
Contrary to (8.16) the error is no longer systematic but rather depends on the ran-
dom series x i . We must determine the standard deviation of (8.17) with respect to dif-
ferent random series. Let
x ki , i = 1...N , k = 1...M
the kth series x i . Then we compute for the integral along (8.17) a mean value of
1 M
⟨J⟩ = ∑ Jk
M k
with
1 N
Jk = ∑ f(x ki ) .
N i
1 M
Var(J) = ∑ (J k − ⟨J⟩)2
M k
2
1 M 1 N
= ∑ ( ∑ f(x ki ) − ⟨J⟩)
M k N i
1 M N
= ∑ ∑ (f(x ki ) − ⟨J⟩) (f(x kj ) − ⟨J⟩) .
MN 2 k ij
8.2 Monte Carlo integration | 247
If the individual numbers x ki are completely uncorrelated, the summands in the last
line will cancel for i ≠ j. Only the expressions with i = j remain and we obtain
1 M N 2
Var(J) = ∑ ∑ (f(x ki ) − ⟨J⟩) . (8.18)
MN 2 k i
On the other hand we can compute the variance of f :
1 M N 2
Var(f) = ∑ ∑ (f(x ki ) − ⟨J⟩) . (8.19)
MN k i
But what happens in higher dimensional spaces? We study the n-dimensional integral
1 1
8.2.2.1 Example
As an example we wish to compute the integral
1 1
1 NT 2
J nM ≈ ∑ (ξ1 + ξ2 + . . . ξ n )
N T i =1
1
If ρ(x) is the probability density of x, we can interpret (8.25) as the mean ⟨f/ρ⟩ and
compute the variance
b
f(x) 2
Var(f/ρ) = ∫ dx [ ] ρ(x) − J 2 . (8.26)
ρ(x)
a
8.2 Monte Carlo integration | 249
Fig. 8.3: Numerical computation of the integral (8.23) for n = 1, 4, 7 room dimensions. Monte Carlo
integration compared to rectangle rule. Relative error in percentage over the total number of mesh
points N T = N n . For the rectangle rule N = 3 . . . 20 have been used in each dimension. The MC error
−1/2
goes with N T (straight line). For n = 1 the rectangle rule is superior, whereas for n = 4, MC is
already more precise.
F[ρ] = Var(f/ρ) + λ ∫ dx ρ
a
∫ dx ρ(x) = 1 (8.27)
a
yields
−f 2 /ρ 2 + λ = 0
or
|f|
ρ= ,
√λ
where λ is to be determined with (8.27). The error becomes smaller the more the shape
of ρ resembles that of |f|. Adjusting the PDF according to the form of the integrand is
named importance sampling, and can be readily extended to higher dimensions.
250 | 8 Monte Carlo methods (MC)
One could be tempted to find the ‘ground state’ with the lowest energy just by testing as
much as possible configurations. Assuming N = 1000, we had to vary 2000 variables
(3000 in 3D) in the region [0, 1]. To detect a minimum in such a high-dimensional
space seems to be rather hopeless.
with Boltzmann’s constant k B and energy E i of the microstate i. The sum runs over
all macroscopically possible microstates. If one deals with continuous variables as
for the hard spheres gas model, the sum is converted into a 2N-dimensional integral
according to
If the partition sum is known, the probability in finding a state with energy E i in the
canonical ensemble is expressed by
1
ρi = exp(−E i /k B T) , (8.32)
Z
also denoted as Boltzmann distribution. With (8.32) we can compute mean values as
⟨Y⟩ = ∑ Y i ρ i , (8.33)
i
where again the sum runs over all states and has to be replaced by the appropriate
integrals for the case of continuous variables.
How can the sums or high-dimensional integrals for the computations of Z be
evaluated numerically? It is possible to apply MC-integration. Normally (8.32) is con-
centrated in a very narrow region around its mean
⟨E⟩ = ∑ E i ρ i
i
and simple sampling will not work effectively. A much better strategy is to draw only
states with E i ≈ ⟨E⟩. Hence one varies the state variables not arbitrarily but rather
in such a way that the system moves towards thermal equilibrium. Let X i be a set of
variables describing the system in the state i, i.e., the position coordinates of the gas
from Section 8.3.1.1. Now one seeks a sequence of states
X0 → X1 → . . . X n
that converges preferably quickly to equilibrium. Each state should be uniquely deter-
mined by its predecessor; such a sequence is denoted as a Markov chain. Let
P(X i → X j )
be the transition probability from state i into state j. A stationary distribution ρ(X) is
given if the condition
ρ(X j )
P(X i → X j ) = P(X j → X i ) = P(X j → X i ) exp(−∆E ji /k B T) (8.34)
ρ(X i )
P(X i → X j ) = 1 if ∆E ji < 0 .
Importance sampling with the Metropolis algorithm is built by the following steps:
1. Choose an initial configuration X0 . Compute E0 (X0 ). i = 1.
2. Construct the next configuration X i by modifying the position of an arbitrary par-
ticle. Compute E i (X i ) and ∆E i,i−1
3. If ∆E i,i−1 ≤ 0, accept the new configuration X i . i = i + 1. Go to 2.
4. If ∆E i,i−1 > 0, draw an equally distributed random number 0 ≤ r < 1. If r <
exp(−∆E i,i−1 /k B T), accept the new configuration X i . i = i + 1. Go to 2.
5. If r > exp(−∆E i,i−1/k B T), restore the old configuration X i = X i−1 . Go to 2.
We exemplify steps 1–5 with a code for MC simulation of the 2D gas with the interaction
potential given in (8.29). For the complete listing see [3].
Step 1 Initial position is computed with program section on page 250. Computation
of E0 :
E0=0.
DO i=1,n-1
DO j=i+1,n
E0=E0-1./d(x(1:2,i),x(1:2,j))
ENDDO
ENDDO
Step 2
Fig. 8.4: (N = 500), configuration at T = 2000 (left frame) and drop formation at T = 20 (right).
Step 3
IF(dE.LT.0.) THEN
E0=E0+dE ! new E0
GOTO 100 ! next configuration
ENDIF
Step 4
CALL RANDOM_NUMBER(r)
IF(r.LT.EXP((-dE/t)) THEN
E0=E0+dE ! new E0
GOTO 100 ! next configuration
ENDIF
Step 5
Figure 8.4 presents two particle configurations for high and low T. Scaling of temper-
ature and distances are such that α = k B = 1 and d0 = 0.01. Obviously, a circu-
lar assignment of the particles minimizes the energy for lower T and a single drop is
formed. For T = 2000 one obtains a gaseous state. The transition becomes visible if a
histogram of the particle distances is recorded as a function of temperature. From the
histogram one finds the average particle distance as
∑i r i H(r i )
⟨r⟩ = ;
∑i H(r i )
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 200 400 600 800 1000 1200 1400 1600 1800 2000
Fig. 8.5: Mean particle distance ⟨r⟩ over temperature for N = 500, d 0 = 0.01.
Fig. 8.6: Drop formation under gravity for g = 103 (left) and g = 104 (right) at T = 20.
to (8.29). For g > 0 the particles ‘move’ downwards and eventually a drop having a
certain contact angle is formed on the lower wall. For larger g the drop is squeezed
and the contact angle becomes smaller; see Figure 8.6.
Certain metals such as iron or nickel show spatial regions where spins orient them-
selves in a parallel fashion and create a permanent magnetic field, a property called
256 | 8 Monte Carlo methods (MC)
where ε measures the coupling strength, NN(i) denote the indices of the nearest neigh-
bors and H stands for an external, homogeneous magnetic field. The amount γ of
nearest neighbors depends on the room dimension n as well as on the geometry of
the periodic grid. One finds
{
{ 2 if n = 1, chain
{
{
{
{4 if n = 2, square lattice
{
{
{
γ = {6 if n = 2, hexagonal lattice
{
{
{
{ if n = 3, simple cubic lattice
{
{ 6
{
{
{8 if n = 3, body-centered cubic lattice.
Taking (8.36) we compute the partition sum (we shall use from here the abbreviation
β = 1/k B T)
Z(H, T) = ∑ ∑ ⋅ ⋅ ⋅ ∑ exp(−βE(s1 . . . s N )) , (8.37)
s1 s2 sN
where each sum runs only over the two values s i = −1, 1. Hence we have to evaluate 2N
expressions in total. With the partition sum at hand, we can compute the free energy
F(H, T) = −k B T ln Z(H, T) (8.38)
and from there further important macroscopic quantities like the internal energy
∂ F
U(H, T) = −k B T 2 ( ) , (8.39)
∂T k B T
the specific heat
∂U
C(H, T) = , (8.40)
∂T
or the overall magnetization
N
∂ F
M(H, T) = ⟨∑ s i ⟩ = − ( ) . (8.41)
i
∂H k B T
with
γ
1
s̄NN = ∑ sj (8.43)
γ jϵNN(s)
as the mean of the neighbor spins. With the partition sum (two states, s = ±1)
1 +1
s̄ = ̄ + βHs) = tanh(βεγ s̄NN + βH)
∑ s exp(βεγs sNN (8.44)
Z s s=−1
is computed. One now makes the strongly simplified assumption that the mean of the
neighbors (8.43) is equal to the mean (8.44) and obtains the transcendental equation
this solution becomes unstable and two new real branches ±s̄1 appear (three intersec-
tions of tanh(βεγ s)̄ and s̄ exist). The two new branches are identified with the ferro-
magnetic phases. The Curie temperature is given from (8.46)
k B T c = εγ .
s̅ s̅
1 1
0.5 0.5
0
1 2 3 4 –3 –2 –1 0 1 2 3
Tc H
–0.5 –0.5
–1 –1
Fig. 8.7: Left: magnetization for H = 0 over T . Right: magnetization over external field H for T = 2.
The dashed line is computed from (8.45). It is unstable where its slope is negative and the true pro-
cess follows the arrows. Scaling: kB = ε = 1 and γ = 4, T c = 4.
more stable, and the other can still be metastable for a certain range of H, while a
hysteresis loop shows up: Figure 8.7, right frame.
Based on the mean-field approach, magnetic phases should occur also in one di-
mension (spin chain) at finite T = 2ε/k B . However, in real life this is not the case,
which we briefly demonstrate in the next section.
and the partition sum can be computed exactly. For the sake of simplicity we shall
concentrate on the case H = 0 and substitute 2ε = ϵ. Using (8.47) one finds from
(8.37)
and shows to be independent on s2 . Next, the sum over s2 is executed in the same way
and so on, and finally one arrives at
0.5 1
0.4
M 0.5
0.3
C
0.2 –2 –1 0 1 2
H
0.1 –0.5
0
0 1 2 3 4 –1
T
Fig. 8.8: Left: specific heat per spin for the one-dimensional Ising model (H = 0); right: magne-
tization per spin depending on an external magnetic field for T = 1 (solid) and T = 2 (dashed),
kB = ϵ = 1.
ϵ2 N
C(T) = (8.51)
k B T 2 cosh(ϵ/k B T)
can be determined. The shape of C(T) could allude to a phase transition for a specific
T c ≈ 1, Figure 8.8, left. However, this is not the case as we shall see if we compute
the magnetization according to (8.41). To this aim one must know the partition sum
for H ≠ 0. This can be achieved also exactly but the computation is more involved; for
details we refer to the literature, e.g., [2]. Here, we only present the result (N ≫ 1):
N
Z(H, T) = exp(Nβϵ) [(cosh(βϵ) + √sinh2 (βH) + exp(−4βϵ)] . (8.52)
We finally get
N sinh(βH)
M(H, T) =
√sinh2 (βH) + exp(−4βϵ)
No spontaneous magnetization occurs for finite temperature; see also Figure 8.8, right.
Applying thermodynamics, this can be understood by an estimate of the free en-
ergy
F = U − TS .
260 | 8 Monte Carlo methods (MC)
(a)
In a homogeneous magnetic phase all spins are aligned (Figure 8.9 (a)), the entropy
is S = 0, and the internal energy reads U = −Nϵ. If, on the other hand, a disloca-
tion as shown in Figure 8.9 (b) is included, the internal energy increases by 2ϵ, but in
the meantime the entropy increases also by k B ln N since there exist N possibilities to
place the dislocation. Thus, the free energy is in total changed by
∆F = 2ϵ − k B T ln N ,
which becomes negative for T > 2ϵ/(k B ln N). Since F decreases on the way to ther-
modynamic equilibrium and finally takes a minimum there, more and more disloca-
tions are created by thermal fluctuations and the order vanishes. In the thermody-
namic limit N → ∞ fluctuations at even infinitesimal temperature are large enough
to destroy a one-dimensional magnetic structure independently from the coupling
strength ϵ.
Why then does the mean-field approximation in one dimension yield a value of
T c = 2ε/k B ? If one assumes as in (8.45) for all spins the same mean value, the influence
of fluctuations is considerably diminished, leading to larger values of T c in general.
For only one spatial dimension, even a qualitatively wrong result can turn out.
∆F = 2Mϵ − k B T ln M ,
where ‘rest’ denotes all terms that do not depend on s k . Subtracting the two equations
above yields
∆E = E({s }) − E({s}) = 2s k h k (8.55)
with the abbreviation
γ
hk = ε ∑ sj + H . (8.56)
jϵNN(k)
In two dimensions the sum in (8.56) can only take one out of the five values −4,−2,0,2,4
and one finds
∆E = ±2(4ε + H, 2ε + H, H, −2ε + H, −4ε + H) .
The Boltzmann factors are needed only for the cases ∆E > 0. Assuming
|H| < 2ε
̃ T)̃ exp(−4T)̃ ,
exp(±2H/ ̃ T)̃ exp(−8T)̃ ,
exp(±2H/ ̃ T)̃
exp(−2H/
occur. It suffices to compute the four different exponential functions for one time at
the beginning of the program what increases its speed considerably.
A code section containing steps 2–5 of page 253 could look like this (for the com-
plete code see [3]):
262 | 8 Monte Carlo methods (MC)
ex(0)=0.5
ex(1)=EXP(-4./T) ! the four exp-functions
ex(2)=EXP(-8./T)
exh(1)=EXP(2.*H/T)
exh(2)=EXP(-2.*H/T)
....
c should the spin is(i,j) be changed?
in=-is(i,j)*(is(i,j+1)+is(i,j-1)+is(i+1,j)+is(i-1,j)) ! sum over
! 4 neighbors
IF(in.GT.0) THEN ! Delta E > 0, change!
is(i,j)=-is(i,j)
ELSE ! Delta E<=0
CALL RANDOM_NUMBER(r)
k=-in/2 ! pointer to ex
k1=(is(i,j)+3)/2 ! pointer to exh
IF(r.LT.ex(k)*exh(k1)) THEN ! r < Boltzmann fact., change!
is(i,j)=-is(i,j)
ENDIF
ENDIF
For H = 0, (8.56) is an integer and the case ∆E = 0 occurs frequently. For a faster
thermalization it is advantageous to allow for transitions with the probability 1/2. This
is why we put ex(0)=0.5 in the first code line.
Let us start with the case without external field H = 0. After about N steps, con-
figurations close to equilibrium are created. Figure 8.10 shows different spin configu-
rations depending on temperature. The magnetization is found from
N
1
⟨M⟩ = ⟨∑ s i ⟩ , (8.57)
N i
where the brackets denote an average of over 1000 different configurations, each
found after a preliminary iteration of 5N steps. Figure 8.11 left shows the typical form
of M for a phase transition already known from the mean-field approximation. Ac-
tually, the mean should be computed by (8.33) with (8.32). But since all states that
contribute belong to almost the same E i , the difference is small. The standard devia-
tion of E is smaller by two orders of magnitude than its mean.
In the same way as (8.57) one finds for the mean energy
1 K
⟨E⟩ = ∑ E({s k }) (8.58)
K k
with E({s k }) belonging to the configuration k according to (8.36). Again the averaging
should be computed for many states after a certain number of preliminary iterations
8.3 Applications from statistical physics | 263
Fig. 8.10: Configurations for several T of an 80 × 80 grid. The critical point where magnetization
changes strongly is at T c ≈ 2.3.
264 | 8 Monte Carlo methods (MC)
1 2.5
0.9
0.8 2
0.7
0.6 1.5
0.5
〈M〉
〈C〉
0.4 1
0.3
0.2 0.5
0.1
0 0
1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3 1.6 1.8 2 2.2 2.4 2.6 2.8 3
T T
Fig. 8.11: Average magnetization (left) and specific heat of the 80 × 80 grid. Both curves are typical
for a phase transition of the second kind at T c ≈ 2.3.
〈M〉 〈M〉
0.5
0.5
T H
0
1 2 3 4 5 6 7 8 −0.1 0.1
−0.5
−0.5
Fig. 8.12: Left: Imperfect bifurcation for an external magnetic field H = 0.03, computed from the
mean-field approach. Right: magnetization for T = 2 as function of the external field. Left branch:
H from 0.1 ⋅ ⋅ ⋅ − 0.1, right branch from −0.1 . . . 0.1.
following each change of the temperature. If ⟨E⟩ is known for two neighbored temper-
atures with difference δT ≪ T, the specific heat per spin can be determined by
1 ⟨E⟩(T + δT) − ⟨E⟩(T)
⟨C⟩(T) = .
N δT
Clearly in Figure 8.11, right frame, a maximum of ⟨C⟩ is recognized at the critical point.
Finally we wish to discuss the case H ≠ 0. Then the pitchfork bifurcation in Fig-
ure 8.7 left turns into an imperfect bifurcation, and Figure 8.12, left, shows the cor-
responding result from the mean-field approximation, equation (8.45). The middle
8.4 Differential equations derived from variational problems | 265
branch is unstable, and for small T two stable solutions exist. Figure 8.12, right frame,
shows the magnetization found with the Metropolis algorithm for a fixed T = 2. The
magnetic field is first increased from −0.1 through 0.1, then reduced from 0.1 to −0.1. A
hysteresis loop appears.
We start with an example. The diffusion equation with internal sources reads:
δF δF 2
dt F = ∂t Ψ = − ( ) = − (∂ t Ψ)2 ≤ 0 .
δΨ δΨ
A minimum of F then corresponds to a stationary solution of (8.59), the Poisson equa-
tion:
δF
∆Ψ0 = −ρ and =0. (8.62)
δΨ Ψ =Ψ0
Ψ(x, y) → Ψ ij .
266 | 8 Monte Carlo methods (MC)
Thus one has to deal with an almost analogue problem to the Ising model, the only
difference is that the ‘spins,’ namely the node values of Ψ = Ψ ij , now may take con-
tinuous values. The Metropolis algorithm can be easily adjusted:
1. Choose an initial condition, e.g., random and equally distributed Ψ ij or Ψ ij = 0.
Compute F.
2. For the new configuration change one Ψ nm with randomly drawn n, m.
3. Compute the new F and ∆F = F − F.
4. If ∆F < 0, accept the new configuration.
5. If ∆F > 0, draw a random number r out of [0,1]. If r < exp(−∆F/T), accept the new
configuration; otherwise restore the old one.
What is here the role of the ‘temperature’? Analogue to thermodynamics, the possi-
bility to accept a Metropolis step with increasing F increases with T. Thus the system
may leave a secondary minimum to reach eventually the main minimum. Too large
temperatures however may yield rather noisy and not converging results and one has
to play around a bit to find the appropriate T. Also a ‘time-dependent,’ slowly decreas-
ing temperature could help in some cases.
8.4.1.3 Results
Figure 8.13 shows a ‘development’ of the initial condition Ψ ij = 0 on a 100 × 100 grid
with ∆x = 1. Two point sources
ρ 20,20 = −1 , ρ 80,80 = 1
8.4 Differential equations derived from variational problems | 267
Fig. 8.13: Solution of the Poisson equation for two point charges applying the Metropolis algorithm.
The snapshots are taken from left to right after 106 , 108 , 2 ⋅ 109 variations of the node values and for
a temperature of T = 4 ⋅ 10−5 .
Ψ̃ mn = Ψ mn + αξ (8.64)
with an equally distributed random variable ξ ϵ [−0.5, 0.5] and α = 0.1, while the
temperature is fixed with T = 4 ⋅ 10−5 . The boundary values Ψ0,j , Ψ M+1,j , etc. are not
changed and remain as zero (Dirichlet condition).
Fig. 8.14: Two solutions of the Swift–Hohenberg equation by variation of the Lyapunov potential
(7.106) with the help of the Metropolis algorithm. Left frame: ε = 0.1, A = 0, right frame: ε = 0.1,
A = 0.5. As in Section 7.4.2, one finds stripes for A = 0 and hexagons for A = 0.5.
0.8 1
0.6 0.5
0.4 0
–0.5
0.2
–1
0
–1.5
–0.2 –2
–0.4 –2.5
–0.6 –3
–0.8 –3.5
200 600 1000 1400 1800 200 600 1000 1400 1800
Fig. 8.15: Lyapunov functional over the number of variations (in millions) for the two parameter sets
of Figure 8.14, T = 2.5 ⋅ 10−4 .
12.6
12.2
11.8
Bibliography
[1] N. Metropolis, A. Rosenbluth, M. Rosenbluth, A. Teller and E. Teller, Equation of State Calcula-
tions by Fast Computing Machines, J. Chem. Phys. 21, 1087 (1953).
[2] K. Huang, Statistical Mechanics, Wiley & Sons (1987).
[3] FORTRAN codes at http://www.degruyter.com/books/978-3-11-051513-8
[4] E. Ising, Beitrag zur Theorie des Ferromagnetismus, Z. Phys, 31, 253 (1925).
[5] L. Onsager, Crystal statistics I. A two dimensional model with order-disorder transition, Phys.
Rev. 65, 117 (1944).
A Matrices and systems of linear equations
In this appendix, we concentrate on methods for the solution to large linear systems
of equations. These can be homogeneous
A ⋅ x⃗ = 0 (A.1)
or inhomogeneous
A ⋅ x⃗ = b⃗ , (A.2)
where x,⃗ b⃗ denote vectors in RN and A is an N × N square matrix.
We begin with some properties and definitions of square matrices.
A ⋅ v⃗ i = λ i v⃗ i with v⃗ i , λ i ∈ C (A.3)
holds is called the eigenvector of A and belongs to the eigenvalue λ i . The eigenvalues
are either real valued or come as conjugate-complex pairs; the same is found for the
eigenvectors.
is called the characteristic polynomial of A. Its N zeros λ i are the eigenvalues of A and
are also denoted as the spectrum of A.
Multiple zeros: Let λ i be a k i -fold zero of P,
https://doi.org/10.1515/9783110515145-009
A.1 Real matrices | 271
A.1.3 Notations
A Tij = A ji . (A.5)
T −1 ⋅ A ⋅ T = B (A.8)
where B is diagonal, B ij = b i δ ij . A and B are called similar and have the same char-
acteristic polynomial and thus the same spectrum λ i = b i . The eigenvectors of A (A T )
form the columns (rows) of the transformation matrix T (T −1 ).
or
λ j = exp(iφ j ) , φj ∈ R .
Because of det M = ∏Ni λ i it immediately follows with A.1.1
det M = ±1 .
cos θ − sin θ
D=( )
sin θ cos θ
A.2.1 Notations
The adjoint matrix A+ is obtained by interchanging rows and columns and forming
the conjugate-complex of each element
Special matrices:
– The self-adjoint matrix with A = A+ . Self-adjoint matrices are also named Hermi-
tian.
– The unitary matrix with A −1 = A + .
– The normal matrix with A ⋅ A+ = A+ ⋅ A.
– Self-adjoint and unitary matrices are also normal.
A.2 Complex matrices | 273
Example:
The matrix
λ1 1 0 0
0 λ1 0 0
J=( )
0 0 λ1 0
0 0 0 λ2
is already in Jordan canonical form and has the characteristic polynomial
P(λ) = (λ1 − λ)3 (λ2 − λ) .
It follows for the eigenvalues
λ1 λ2
algebraic multiplicity 3 1
geometric multiplicity 2 1
274 | A Matrices and systems of linear equations
Hence, J possesses only three eigenvectors, two belonging to λ1 and one to λ2 . Thus,
the eigenvectors do not form a complete orthogonal system.
A ⋅ x⃗ = b⃗ . (A.12)
The system (A.12) possesses a unique solution if the system matrix A is invertible. It
reads
x⃗ = A−1 ⋅ b⃗ . (A.13)
Hence, det A ≠ 0 and A is called a regular matrix. Then the rank of A is
rank(A) = N ,
ker(A)
v⃗1 , . . . , v⃗ K
for which
A ⋅ v⃗ i = 0 , i = 1...K .
The kernel is also called the null space. For a singular A, depending on b⃗ there exists
either no or infinitely many solutions to (A.12). There is no solution if b⃗ is partially or
completely in ker(A):
(A+ − λ i 1) ⋅ v⃗+i = 0 ,
and λ1 , . . . λ K = 0, λ K+1 , . . . λ N ≠ 0.
A.3 Inhomogeneous systems of linear equations | 275
For case (b), the solutions are found by expanding x⃗ and b⃗ into the base v⃗ i :
N N N
x⃗ = ∑ y i v⃗ i , b⃗ = ∑ β i v⃗ i = ∑ β i v⃗ i
i=1 i=1 i=K+1
v⃗+i ⋅ b⃗
yi = , i = K +1...N
λi
must hold. The other y i , i = 1 . . . K remain undetermined.
x⃗ = A −1 ⋅ b⃗ , if rank(A) = N
The matrix inversion to numerically solve (A.12) can be achieved by applying some
standard routines provided e.g., by the LAPACK library. Depending on the form of A
different routines are to be considered, a documentation is found for instance in¹
http://www.netlib.org/lapack/explore-html/files.html
The different names of the routines are logically derived and composed from their
functions, data types, etc., for details see
http://www.netlib.org/lapack/individualroutines.html
To solve (A.12), the matrix A does not need to be inverted completely, it suffices
to transform it into a triangular shape, applying Gauss elimination (for details see
e.g., [1]). Once (A.12) is in triangular form
A ⋅ x⃗ = b⃗ (A.14)
with
A11 . . . A1N
A22 . . .
A = ( A33 . . ) , (A.15)
.
0 ANN
the system (A.14) is easily solved by backward substitution and we obtain
b i − ∑Nk=i+1 Aik x k
x i := , (A.16)
Aii
A.3.4 LU decomposition
A ⋅ x⃗ = (L ⋅ U) ⋅ x⃗ = L ⋅ (U ⋅ x)⃗ = b⃗ . (A.19)
i−1
1 [
y i := b i − ∑ L ij y j ] . (A.22)
L ii
[ j=1 ]
Here we imply that the sum is zero for i = 1 and for y j occurring on the right-hand side
the values computed in the same loop are used (forward substitution).
As a second step, we solve
U ⋅ x⃗ = y⃗ (A.23)
by backward substitution just as in (A.14).
The main task is to find the decomposition (A.17), or, in other words, to determine
the matrices L and U. This is done by solving the inhomogeneous system
K
∑ L ik U kj = A ij , i = 1...N , j = 1...N , (A.24)
k=1
where because of the special structure of L and U the sum runs only up to
K = min(i, j) .
These are N 2 equations for 2× N 2+N = N 2 + N unknowns and the system is underdeter-
2
mined, meaning the LU decomposition is not unique. Thus, we can arbitrarily make
the N elements in the diagonal of L 1:
L ii = 1 , i = 1...N . (A.25)
4. j := j + 1. If j ≤ N go to 2.
Following the algorithm step-by-step, it turns out that on the right-hand sides only
elements are needed that have already been computed in prior steps.
278 | A Matrices and systems of linear equations
A.3.4.1 Pivoting
A division occurs in (A.27), which may cause numerical problems if the corresponding
U jj is small. One may show that Crout’s algorithm (as other elimination methods too)
is unstable if U jj becomes small compared to other matrix elements. A solution is pro-
vided by reordering the system. One may interchange arbitrarily rows and columns
but then has to swap also the elements of the vectors x⃗ and b⃗ accordingly. Finding
an appropriate permutation that leads to a large-valued divisor (the pivot element in
(A.27)) is called ‘pivoting.’ One distinguishes between full and partial pivoting. In the
first case, rows and columns of A are interchanged pairwise, in the latter only the rows.
How can we find the optimal pivot element? Normally it suffices to take that ele-
ment with the largest absolute value. To compare elements in different rows, the ma-
trix A should be scaled first. One can use the largest element in each row and scale
this to one, i.e., one computes for each row i a scaling factor
s−1
i = max |A ij | j
If the matrix A has many zeros, the methods can often be simplified considerably.
The special case of a tridiagonal matrix (only nonzeros in the diagonal, and in one
upper and lower diagonal) occurs often from finite differences discretization and can
be solved quite effectively. Let
A ⋅ x⃗ = y⃗ ,
with a tridiagonal A given as
b1 c1 0
a2 b2 c2
( . . . )
A=(
(
) .
) (A.28)
ai bi ci
. . .
(0 aN bN )
1 c1 0
1 c2
( . . )
A = (
(
) ,
) (A.29)
1 ci
. .
(0 1)
A.4 Homogeneous systems of linear equations | 279
The receipt (A.30-A.32) is known as the ‘Thomas algorithm’ and can be extended
straightforwardly to matrices having more than one upper and lower diagonal.
B ⋅ x⃗ − λ x⃗ = 0 , (A.33)
that can be brought into the form (A.1) by substituting B − λ 1 = A. The system (A.33)
has nontrivial solutions only if the determinant
det(B − λ 1) = 0
vanishes (solvability condition). As already stated in Section A.1.2, this yields the char-
acteristic polynomial P(λ) whose N zeros correspond to the eigenvalues of B. To each
eigenvalue λ i , an eigenvector v⃗ i is assigned so that
B ⋅ v⃗ i = λ i v⃗ i , i = 1...N , (A.34)
A.4.2 Diagonalization
The central task is to find eigenvalues and eigenvectors for a given matrix. As outlined
in Section A.2.2, each matrix can be transformed into Jordan canonical form:
C−1 ⋅ B ⋅ C = J .
280 | A Matrices and systems of linear equations
Since the transformation does not change the spectrum, the eigenvalues of A and J
are equal and can simply be read off from the diagonal of J:
λ i = J ii .
J ij = λ i δ ij ,
B is said to be diagonalizable and its desired eigenvectors are identical with the
columns of the matrix C (for matrices which can not be brought into diagonal form
there exist special methods which we shall not discuss here).
How can we obtain the transformation C? In practice, two different methods are
applied, sometimes also a combination of both methods. We shall present a short
overview of both, for more details see the literature, e.g., [1] or [2].
The resulting matrix B is similar to B and must not already be in diagonal form. Any-
way, it should be easier to handle than the original matrix. Finally, the better condi-
tioned B can be further diagonalized by factorization.
B = FR ⋅ FL . (A.36)
F R = F −1
L ⋅B,
B = F −1
L ⋅ B ⋅ FL . (A.37)
Hence, B and B are similar and have the same spectrum. Next, one constructs the
sequence
B (n+1) = F −1
nL ⋅ B
(n)
⋅ F nL = F nR ⋅ F nL (A.38)
A.4 Homogeneous systems of linear equations | 281
with B (0) = B and F nL , F nR as factors of B(n) . One can show that B(n) converges for
n → ∞ to a triangular matrix if the factorization (A.35) fulfills certain properties [2].
This will be described in greater detail in the next section.
A.4.2.3 LU factorization
Now we use in (A.35) the LU decomposition introduced in detail in Section A.3.4
B=L⋅U.
B(n+1) = L−1
n ⋅B
(n)
⋅ Ln = U n ⋅ Ln (A.39)
At each step B comes closer to an upper triangular matrix. If B has reached this form
it will not change further, hence each upper triangular matrix is a fixed point of the
map (A.39). This is evident because an upper triangular matrix B factorizes in a trivial
way into an upper triangular matrix U = B and the unit matrix as a ‘lower triangular
matrix’ L. Then one has L U = U L and B = B .
A.4.2.4 QR factorization
Not every matrix can be LU decomposed. Conversely, the so-called QR decomposition
B=Q⋅R
with R again as the upper triangular matrix but now an orthogonal matrix Q is always
possible. Instead of (A.39) we obtain
B(n+1) = Q −1
n
⋅ B(n) ⋅ Q n = R n ⋅ Q n . (A.40)
We list the following properties without proof, for details see [2]:
– If all eigenvalues of B have different absolute values, B (n) converges for n → ∞ to
an upper triangular matrix. The eigenvalues are ordered with increasing absolute
value in the diagonal.
– If k eigenvalues have the modulus |λ i |, i = 1 . . . k, B(n) converges to an upper
triangular matrix with the exception of a diagonal block matrix of order k whose
eigenvalues are λ i .
282 | A Matrices and systems of linear equations
P(x i ) = 0 , xi ∈ C , i = 1...N
b k = a k /a N , k = 0...N −1
having of course still the same zeros as P. We construct the N × N-Frobenius matrix
0 −b 0
1 0 −b 1
( 1 0 −b 2 )
( )
F=(
(. . ) ) . (A.42)
(. . )
. .
( 1 −b N−1 )
SUBROUTINE zeros(a,n,z)
C computes all zeros of the polynomial
C p = a(n)*x^n + a(n-1)*x^(n-1) ... a(0) = 0
C a(0:n) [in]: coefficients (not changed) real*8
C z(n) [out]: the complex zeros, complex*16
Bibliography | 283
Bibliography
[1] L. Hogben (editor), Handbook of Linear Algebra, Chapman & Hall (2007).
[2] J. Stoer and R. Bulirsch, Introduction to Numerical Analysis, Springer (2010).
[3] W. H. Press, B. P. Flannery, S. A. Teukolsky and W. T. Vetterling, Numerical Recipes, Cambridge
Univ. Press (2007).
B Program library
B.1 Routines
We wish to supply and to describe some useful and often needed routines. They can be
compiled separately and linked by specifying the corresponding object file (.o) during
the compilation process of the main program. If the routines are gathered e.g., in a file
named fortlib.f, one compiles once with
gfortran -c fortlib.f
The option -c tells the compiler not to create an executable but rather generate an ob-
ject file that is named for this case fortlib.o. If a routine from the library is used, one
must modify the script file used for compilation, (e.g., make_f95 from Section 1.2.4),
by adding the fortlib object file. Finally, the script file should look like this (if LAPACK
is also needed):
https://doi.org/10.1515/9783110515145-010
B.2 Graphics | 285
In the following, we only present the comment headers of the respective routines.
Where not specified otherwise, implicit type declaration is assumed and real
variables are in single precision (real*4). The complete listing is provided in
‘http://www.degruyter.com/books/978-3-11-051513-8’.
B.2 Graphics
All routines in this section resort to programs of the PGPLOT library (see chapter 1).
B.2.1 init
SUBROUTINE init(x0,x1,y0,y1,size,aspect,frame)
c initializes a graphics window
c x0,x1 [In] x-region
c y0,y1 [In] y-region
c size [In] size of window in inches
c aspect [in] aspect ratio (y/x)
c frame [In] if frame='Y' or 'y' a box is plotted
c
B.2.2 contur
SUBROUTINE contur(a,idim,jdim,n)
c Plots n contour lines of an array a. The contour values are chosen
c equidistant between min(a) and max(a).
c If n=0: only the a=zero line is plotted.
c a(idim,jdim) [In] 2D array
c idim, jdim [In] dimensions of a
c n [In] number of lines
B.2.3 contur1
SUBROUTINE contur1(a,idim,jdim,n)
c plots contour lines as 'contur'
c n=0 [In] only zero line plotted
c n>0 n lines between 0 and max(a) (equidistant)
c n<0 -n lines between min(a) and 0 (equidistant)
c rest see 'contur'
286 | B Program library
B.2.4 ccontu
SUBROUTINE ccontu(a,idim,jdim,n)
c plots contour lines as 'contur'
c the lines are plotted with ascending color indices from 2 through
c 2+n-1.
c rest see contur
B.2.5 image
SUBROUTINE image(a,idim,jdim,ic0,ic1,a0,a1)
c plots a colored bitmap of a real*4 array 'a'
c a(idim,jdim) [In] array whose values are pixeled
c idim, jdim [In] dimensions of a
c ic0, ic1 [In] defines the color range (ic0=min(a), ic1=max(a))
c a0,a1 [In] minimum and maximum for color values,
c if both =0 min(a) and max(a) is used.
B.2.6 ccircl
SUBROUTINE ccircl(i0,i1)
c loads the color register from i0 through i1 with a periodic color circle.
B.3 Runge–Kutta
All four routines are based on the 4th-order Runge–Kutta scheme for ODEs.
B.3.1 rkg
SUBROUTINE rkg(y,t,n,dt,eq)
c integrates the ODE system defined in eq (external) over one step
c [t,t+dt] by 4th order Runge--Kutta
c y [In/Out] dependent variables y(n)
c t [In] independent variable
c n [In] number of eqs.
c dt [In] step size
c eq [In] user-suppl. subroutine, defines the ODE system
B.4 Miscellaneous | 287
B.3.2 drkg
SUBROUTINE drkg(y,t,n,dt,eq)
C same as rkg, but in DOUBLE PRECISION (y,t,dt)
B.3.3 drkadt
SUBROUTINE drkadt(y,t,n,dt,eps,eqs)
c same as drkg, but with adaptive step size
c REAL*8 y [In/Out] dependent variables y(n)
c REAL*8 t [In] independent variable
c n [In] number of eqs.
c REAL*8 dt [In/Out] step width, to be computed
c REAL*8 eps [In] desired accuracy, dt is adapted such
c that the error is < eps
c eqs [In] user-suppl. subroutine
c resorts to routine drkg
B.4 Miscellaneous
SUBROUTINE tridag(a,b,c,d,n)
c solves a tridiagonal inhomogeneous algebraic system
c a(i)*x(i-1) + b(i)*x(i) + c(i)*x(i+1) = d(i), i=1..n
c using the Thomas algorithm
c a(n) [In] lower diagonal
c b(n) [In] diagonal, attention:b is overwritten!
c c(n) [In] upper diagonal
c d(n) [In/Out] r.h.s. (in), overwritten by solution x(n) (out)
B.4.2 ctrida
SUBROUTINE ctrida(a,b,c,d,n)
c same as tridag, but for a complex valued system (a,b,c,d)
288 | B Program library
SUBROUTINE dlyap_exp(eqs,eql,dt,tprel,tend,ntau,n,nfmax,fly)
c computes the nfmax largest Lyapunov exponents of the system 'eqs'
c all in DOUBLE PRECISION
c eqs [In] user-suppl. subroutine, defines the complete ODE system
c eql [In] user-suppl. subroutine, defines the linearized ODE system
c REAL*8 dt [In] step size for RK4
c REAL*8 tprel [In] preliminary iterations from when 'fly' is computed
c REAL*8 tend [In] maximum t for computation
c ntau [In] after tau=ntau*dt Lyap. exp. update
c n [In] number of eqs.
c nfmax [In] number of computed Lyap exp.
c REAL*8 fly [In/Out] in: initial values for main trajectory
c Out: fly(i) contains the i-th Lyap. exp.
c routines needed: drkg, schmid, volum
SUBROUTINE schmid(x,n,m)
c orthonormalizes the m vectors x(i,j)
c by a Schmidt--Gram algorithm
c REAL*8 x(i,j) [In/Out], i=1..n (components of vector j),
c j=1..m
c routine needed: norm
SUBROUTINE norm(x,n)
c normalizes the vector REAL*8 x(n), L2-norm
SUBROUTINE random_init
c initializes the FORTRAN95 random number generator RANDOM_NUMBER
c with the system clock. No parameters
C Solutions of the problems
We show solutions to the exercises, in particular to those solved with ‘paper and pen-
cil.’
C.1 Chapter 1
Problems 1.3.3
https://doi.org/10.1515/9783110515145-011
C.2 Chapter 2 | 291
C.2 Chapter 2
Problems 2.1.4
1. For K = 0:
y n+1 = y n , x n+1 = x n + y n ,
horizontal rows of dots, which are dense if y n is irrational, otherwise points with gaps.
ℓ = x N − x0 ,
thus for K = 0
ℓ = N y0 ,
a linear function of the initial value y0 . For small values of K the length deviates from
the straight line for certain rational y0 = 1/M, M integer, and locks in the form of steps
of a staircase. For larger K this effect increases and chaotic regions occur in addition;
see Figure C.1.
104 104
8000 8000
6000 6000
K = 0.2 K = 0.5
4000 4000
2000 2000
0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
104 104
8000 8000
6000 6000
K = 0.7 K = 1.0
4000 4000
2000 2000
0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Fig. C.1: Chain length as function of y 0 for several K after 10 000 iterations. For larger K an irregular
staircase (devil’s staircase) occurs.
292 | C Solutions of the problems
C.3 Chapter 3
Problems 3.1.2
C.4 Chapter 4
Problems 4.3.2
Problems 4.3.3.3
After scaling:
t = τ t̃ , n i = γ i ñ i
with
τ = 1/β 1 , γ1 = β 1 /β 2 , γ2 = β 1 /α 2
one arrives at the form (4.27) with the sole remaining (control) parameter
a = α 1 /β 1 .
2. The fixed points are computed from
0 = a ñ 1 − ñ 1 ñ 2
0 = −ñ 2 + ñ 1 ñ 2
as
294 | C Solutions of the problems
(i) ñ 1 = ñ 2 = 0
Stable for a < 0, node, unstable for a > 0, saddle node.
(ii) ñ 1 = 1 , ñ 2 = a.
This fixed point exists only for a > 0 since ñ i as a concentration is by definition posi-
tive.
Linearizing:
ñ 1 1 u1
( ) = ( ) + ( ) e λt
ñ 2 a u2
leads after insertion in (4.27) to the solvability condition
λ 1
det ( ) = λ2 + a = 0
−a λ
and
λ12 = ±i√a .
Hence the second fixed point is always marginally stable (Re λ = 0), but has a nonva-
nishing imaginary part. This is denoted as a center.
Problems 4.4.5
where k and ℓ are two coprime integers. The orbit is closed after one revolution if ℓ = 1,
leaving the condition for α
α = 4 − k2 , k = 1, 2, 3, . . .
In fact there are infinitely many sharp values for α where circular orbits stay closed
when slightly perturbed. We mention the first three ones, together with the behavior
of the force on distance and the potential:
1. α = 3: Kepler potential, F ∼ −1/r2 , U ∼ −1/r.
2. α = 0: 2D-harmonic oscillator, F ∼ −r, U ∼ r2 .
3. α = −5: anharmonic oscillator, F ∼ −r6 , U ∼ r7 .
To show numerically the existence of closed orbits we integrate the system (C.5) with
the initial conditions
for 100 revolutions and average the x(t i ) − x(0) value after each revolution i:
1 100
⟨δx⟩ = ∑ |x(t i ) − x(0)|
100 i
where t i is found from y(t i ) = 0 and w(t i ) > 0. The small deviation ϵ = 0.001 starts
the instability. The result for α = −6 through α = 4 is shown in Figure C.3. Clearly,
the deviations after one revolution get very small for the selected values α = −5, 0, 3,
indicating a closed orbit.
0.1000000
⟨δx⟩
0.0100000
0.0010000
0.0001000
Kepler
0.0000100 anharmonic
oscillator harmonic
oscillator
α
0.0000010
–6 –5 –4 –3 –2 –1 0 1 2 3 4
3. The Lagrangian points L1 through L3 are located on the x-axis. Thus it suffices to
evaluate the Jacobi potential (4.46) at y = 0:
1−μ μ x2
V(x, 0) = − − − =0.
|x + μ| |x + μ − 1| 2
Zeroing its derivative leads to the conditions for the fixed points
1−μ μ
∂ x V(x, 0) = (x + μ) + (x + μ − 1) − x = 0 .
|x + μ|3 |x + μ − 1|3
Due to the moduli one must distinguish between the three cases
1. x < −μ, left of m2 , sign(x + μ) = −1, sign(x + μ − 1) = −1
2. −μ < x < 1 − μ, between m2 and m3 , sign(x + μ) = 1, sign(x + μ − 1) = −1
3. 1 − μ < x, right of m3 , sign(x + μ) = 1, sign(x + μ − 1) = 1.
The roots of (C.7) can be computed for instance using the program zeros of Sec-
tion A.4.3. Figure C.4 shows the Lagrangian points depending on the mass relation μ.
0.5
–0.5
–1
Fig. C.4: Solid: x-coordinates of the three La-
grangian points L 1 , L 2 , L 3 over the mass param-
0 0.2 0.4 0.6 0.8 1 eter μ; dashed: position of the two main bodies.
298 | C Solutions of the problems
Problems 4.5.6
1. Thermalization: Multiplying (4.74) with v⃗ i and summation over all particles for
F⃗ i = 0 yields
1 d
∑ v2 = −γ ∑ v2i . (C.8)
2 dt i i i
2. 2D-equilibrium configurations:
(i) If only the four nearest neighbors (blue) are considered, the potential energy reads
U GQ = 4 U(r)
U GQ = 4 U(r) + 4 U(√2r)
and
U GH = 6 U(r) + 6 U(√3r)
and from the equilibrium condition (C.9)
and
U GH = 6 U(r) + 6 U(√3r)) + 6 U(2r) ,
C.4 Chapter 4 | 299
1/6 1/6
1 + 2−6 + 2−12 1 + 3−6 + 2−12
r Q = (2 ) ≈ 1.10100, r H = (2 ) ≈ 1.1132.
1 + 2−3 + 2−6 1 + 3−3 + 2−6
The more stable configuration is that with the lower energy. Computing U G for the
given equilibrium positions, one finds for all cases
U GH < U GQ ,
independently on the number of neighbors taken into account. Hence the lattice
should manifest a hexagonal geometry for low temperatures, in agreement with
Figure 4.14, left frame.
Problems 4.7.5
u̇ 1 = u 2
u̇ 2 = −Ω20 (1 + a sin ωt) ⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟
sin(π + u 1 )
=−u1
or
ü − Ω20 (1 + a sin ωt) u = 0 (C.10)
with u = u 1 . The same scaling as in Section 4.7.4 leads to
Its solvability condition constitutes a polynomial of 2nd degree in λ2 having the roots
λ2 = p − 1 ± √b 2 − 4p .
300 | C Solutions of the problems
Re λ = 0
p
Fig. C.5: The upper rest position is stable in the
1 shaded area.
For a nonpositive Re(λ), λ2 must be real valued and λ2 ≤ 0. The first condition leads
to
b ≥ 2√p ,
the latter to
b ≤ 1+p.
In addition, 0 ≤ p ≤ 1 must hold. This results in a stability diagram sketched in Fig-
ure C.5.
̃ =0
ü + β u̇ + (p + 2b sin 2t)u (C.12)
by the scaling of Section 4.7.4 and β = 2α/ω. To find the Floquet exponents one nu-
merically integrates the system (4.104), but now with
0 1
L(t)̃ = ( ) , (C.13)
−(p + 2b sin 2t)̃ −β
Fig. C.6: Stability chart for the damped Mathieu equation (C.12) with β = 0.1.
C.5 Chapter 5
Problems 5.6
̃ ,
t = t/α (x, y) = (x,̃ y)̃ ⋅ g/α 2
and reads
Only one parameter β̃ = β/α 2 is left. We leave all tildes. Different ways to solve the
system are possible. One can compute y from (C.15) and obtains
T
y(t) = f(t) − t (C.16)
f(T)
with
f(t) = 1 − e−t .
302 | C Solutions of the problems
The boundary conditions y(0) = y(T) = 0 are already implemented in (C.16). From
(C.14) and (C.15) y can be eliminated:
Ẍ + 2Ẋ + X = 0 ,
which is solved by
X(t) = (c t − a) e−t .
Here, x(0) = 0 is already included. Thus one finds for x
β 2
x(t) = (c t − a) e−t + a + b t − t . (C.17)
2
The coefficients b, c are determined by inserting (C.17) and (C.16) in (C.14) and com-
paring the coefficients:
βT
c= , b=c+β.
f(T)
The remaining coefficient a follows from the boundary condition x(T) = L:
T 2 β(1 + 3e−T ) L − βT
a=− + .
2f 2 (T) f(T)
2. Solution of the nonlinear Schrödinger equation.
The solution given is verified straightforwardly by insertion.
Discussion for arbitrary C: The integral found by separation of variables from
(5.45) has no analytic form. We discuss a ‘graphic solution’ coming from the analogy
to a classical one-dimensional motion of a mass point in a potential.
Writing (5.42) in the form
dV(Φ)
Φ = −EΦ + γ Φ3 = − (C.18)
dΦ
with
E 2 γ 4
V(Φ) = Φ − Φ , (C.19)
2 4
(C.18) is identical with the equation of motion of a mass point with m = 1 in the poten-
tial (C.19) (x plays the role of time, Φ that of the position). Equation (5.45) corresponds
to the conservation of energy and C/2 denotes the total energy
C 1 2
= (Φ ) + V(Φ) .
2 2
C.6 Chapter 6 | 303
V V V V
E2 /4γ
Φ Φ Φ Φ
E 2 /4γ
Fig. C.7: The four different potentials. Nonlinear waves can exist for (a), (b) and (d).
and correspond to plane, nonlinear waves in position space. For C > E2 /2γ or
C < 0, Φ diverges for x → ±∞.
(b) E > 0, γ < 0, Figure C.7 (b). Nonlinear waves for C > 0.
(c) E < 0, γ > 0, Figure C.7 (c). Diverging solutions for all C.
(d) E < 0, γ < 0, Figure C.7 (d). If E2 /2γ < C < 0, nonlinear waves about Φ = ±√E/γ.
For C > 0 nonlinear waves about Φ = 0 with square amplitude (C.20).
C.6 Chapter 6
Problems 6.4.4
2.
(i) Linearization with u 0 = 0, u = u 0 + w:
∂ t w = ∂2xx w + w
du 2u + 1
x − x0 = √3 ∫ = 2 atanh (√ ) .
√1 − 3u 2 + 2u 3 3
After some short manipulations one obtains the stationary solution
3
u 0 (x) = 1 − 2
, (C.22)
2 cosh ((x − x0 )/2)
corresponding to a localized solution at x = x0 with u 0 (x → ±∞) = 1 and u 0 (x0 ) =
−1/2.
C.6 Chapter 6 | 305
V = 1/6
u = –1/2 u=1 u
clear;
n=1000;
dx=50/(n+1); dx2=dx^2;
x=-25+dx:dx:25-dx;
a=-1/dx2*ones(n-1,1); % tridiagonal matrix
for k=1:n
b(k)=2/dx2+1-3/cosh(x(k)/2)^2;
end
b(1)=b(1)-1/dx2; b(n)=b(n)-1/dx2;
m=diag(a,1)+diag(a,-1)+diag(b,0); % boundary conditions
[v,e]=eigs(m,3,'sa'); % compute eigenvalues and vectors
plot(x,v(1:n,1),x,v(1:n,2),x,v(1:n,3)); % output
-diag(e)
306 | C Solutions of the problems
0.2
0.15 1
0.1
3
0.05
0
–0.05
2
–0.1
–0.15
–25 –20 –15 –10 –5 0 5 10 15 20 25
The values for λ are printed and read λ = 1.25, 0, −0.75. Note that the second
(marginal, λ = 0) mode corresponds to a lateral shift of u 0 with w ∼ d x u 0 . It can
be easily shown that w = d x u 0 is an exact solution of (6.137) with λ = 0.
C.7 Chapter 7
Problems 7.4.3
iΩ = ε − (1 + ic3 ) A2
ε − A2 = 0 , Ω + c3 A2 = 0
λ = −(1 + c1 c3 ) k 2 + O(k 4 )
1 + c1 c3 < 0 .
0 ≤ k 2 ≤ k 2c
and
1 + c1 c3
k 2c = −2ε
1 + c21
are growing exponentially in time, Figure C.10. This is called Benjamin–Feir instability.
3. Figure C.11 shows the real part of Ψ in an xt-diagram for c1 = 1/2, c3 = −3. It can be
easily seen that the initial condition (7.111) becomes unstable and after t ≈ 250 gives
way to a spatio-temporal chaotic evolution.
2000
1500
1000
500
parallel, one integrates the linearized DEQ for the complex valued deviations from the
reference trajectory u(x, t):
into (7.110) and linearizing around Ψ N . For u(x, 0) we choose a randomly distributed
but normalized initial condition
After a certain time δt (e.g., δt = 200∆t) the growth of |u| in the interval δt is com-
puted:
1/2
[ j ]
Thereafter u(x, δt) is again normalized. The continued numerical integration then
yields s(2δt) and so on. At the end, the largest Lyapunov exponent is found as the
mean value of all local exponents according to
1 K 1
Λ = lim ∑ ln s(kδt) . (C.24)
K→∞ K k=1 δt
For each single value of c3 the integration is carried on up to t = 34 000. After chang-
ing (increasing or decreasing) c3 , the evaluation of the corresponding Lyapunov ex-
ponent according to (C.24) is started after an initial run until t = 15 000.
C.7 Chapter 7 | 309
Fig. C.12: Largest Lyapunov exponent Λ of the complex Ginzburg–Landau equation over c 3 for
c 1 = 1/2. A transition to chaos showing a wide hysteretic region results.
Figure C.12 depicts Λ over c3 for a fixed c1 = 1/2. From (7.112) chaotic dynamics is
expected for c3 ≤ −2. Obviously, the behavior of Λ depends on the previous states
and a large hysteretic region shows up in which both chaotic and regular dynamics
may emerge at the same values of c3 .
D README and a short guide to FE-tools
D.1 README
http://www.degruyter.com/books/978-3-11-051513-8
The codes are ordered along their appearance in the book chapters.
In each subdirectory a script file
make_f95
are required.
In this directory:
------------
chap2/
lyap_2d.f
computes the largest Lyapunov exponent of the standard map,
sect. 2.2.3.
TI: K (control parameter)
https://doi.org/10.1515/9783110515145-012
D.1 README | 311
dbc_slp.f
decimal to binary converter from sect. 2.5.1.4
TI: following the learning phase, input of the decimal number to
be converted
kohonen_colormap.f
color map after Kohonen as shown in Figure 2.16.
TI: none
tsp.f
Traveling Salesman Problem from sect. 2.5.2.3
TI: R (radius of the initial circle)
------------
chap3/
henon_heiles.f
Plots the Poincaré section and trajectories from the Henon-Heiles
model from sect. 3.3.3.1, compare Figure 3.5. The value 'e' for the
energy can be modified in the code.
TI: initial values set by mouse
------------
chap4/
reduc_3_b_p.f
Plots and computes trajectories of the reduced three body problem
from sect. 4.4.4.4.
mu=1/4, can be modified in the code.
TI: value of energy 'e'. Then set initial value by mouse in allowed
region (red).
molecular_dynamics.f
Molecular dynamics simulation from sect. 4.5.4. On the left-hand side
particles are depicted in config. space; the right-hand side shows
the pair correlation function.
Simulations are also possible in a constant gravity field.
TI: temperature (0.1 - 2.0), gravitation (ca 1), tend (e.g. 200)
312 | D README and a short guide to FE-tools
pendulum_lyapunov_exp.f
Bifurcation diagram (bottom) and two Lyapunov exponents of the
driven pendulum from sect. 4.6.3.6.
TI: region for a, resolution
------------
chap6/
shallow_water.f
Solution of 2D shallow water eqs. from sect. 6.2.4.2 with FTCS.
Here for two oscillating point sources.
TI: none
grid_contur.f
mesh_generator.f
laplace_solver.f
Program tools for FE, see separate short guide in fe_guide.pdf
fe_guide.pdf
guide for the FE codes, see also appendix D.2
------------
chap7/
driven_cavity.f
solution of the hydrodynamic basic equations from sect. 7.3.2.3.
Plot of stream lines as in Figures 7.9., 7.10
TI: Reynolds number
benard_convection.f
Solution of the hydrodynamic eqs. from sect. 7.3.4.2 in 3D following
sect. 7.3.4.3.
Plot of temperature field. Rayleigh number, Biot number, tend
can be changed in the code.
Note: the library FFTPACK is needed (see make_95)
TI: none
D.2 Short guide to finite-element tools from Chapter 6 | 313
------------
chap8/
mc_gas.f
compute the equilibrium of a many-particle system based on the
Metropolis algorithm from sect. 8.3.1.2. In addition: constant
gravitation.
TI: temperature, gravitation. Note: units as in Figures 8.4 - 8.6
ising.f
solution of the Ising model with Metropolis algorithm from
sect. 8.3.2.3. temperature values are scanned, mean magnetization is
computed.
TI: external magnetic field
The three codes for grid generation, Laplace solving, and evaluation:
Example files:
kidney.ppm, house.ppm domain bound. Xfig (or similar); see Figure D.1
kidney.grd, house.grd grid files mesh_generator
kidney.knd, house.knd node files laplace_solver
D.2.1 mesh_generator
TI: name of ppm-file (P6-format, binary, one byte/pixel), contains the domain
boundary created by a graphics program, e.g., Xfig. The dimension of the bitmap can
be as large as 5000 x 5000.
314 | D README and a short guide to FE-tools
Fig. D.1: The two domain boundaries ‘house.ppm’ and ‘kidney.ppm.’ The latter also contains inner
boundaries (multiply connected domain).
TI: number of mesh points in the x-direction, defines the resolution of the triangular
grid. Reasonable values for the examples are 30–60.
The triangular grid is plotted (red). The outer boundary points are marked in blue. If
some are missing they must be added manually using the mouse.
If finished, type ‘s’ on keyboard. All mesh points left and right from the external
boundaries are then deleted automatically. Boundary points are now marked by cir-
cles.
Mouse modes:
There are three modes, which one can toggle between using the keys ‘d, r, z.’
Key ‘d’: delete mode: Clicked points near the mouse cursor are deleted.
Key ‘r’: boundary mode: Clicked points close to the mouse cursor are marked as
boundary points. Inner boundaries (example ‘kidney’) have to be marked by hand
and afterwards drawn to the desired position. Here, single points can also be set
(point charges).
Key ‘z’: draw mode: Clicked points near the mouse cursor can be drawn, e.g., onto
the boundary. The new location is obtained by positioning the mouse cursor and
repeated clicking. Attention: avoid crossing lines!
Key ‘s’: TI for grid file name (output, .grd) and termination of the program.
D.2 Short guide to finite-element tools from Chapter 6 | 315
D.2.2 laplace_solver
In the code the boundary node values have to be defined one by one. The number of
corresponding mesh points is obtained from mesh_generator.
TI: node file name. Here, the node values are stored after computation.
D.2.3 grid_contur
TI: node file name. Then request for the value of the contour line(s) to be plotted.
Termination by Ctrl-d.
The package can be extended and improved in various ways. Here, we only note a few
ideas:
– Handling of the boundary conditions. Instead of setting the (Dirichlet) boundary
values in the code laplace_solver it could be better to define them in an extra file,
or by mouse input.
– Other boundary conditions (Neumann, mixed).
– Automatic detection of the inner boundaries.
– Extension to the Poisson equation.
– Extension to time-dependent problems (diffusion equation, Schrödinger equa-
tion).
– Extension to 3D.
Index
A correlation dimension 107
acceptance-rejection method 242 Courant number 167
activator-inhibitor system 228 Crank–Nicolson method 67, 208
ADI method 159 Crout algorithm 277
algebraic multiplicity 270 cyclic reduction 161
anharmonic oscillator 127 cyclotron frequency 202
apsidal precession 76
autonomous system 43 D
decimal to binary converter 33
B degree of freedom 41
ballistic flight 118 detailed balance 252
Barnsley ferns 23 differential quotient 153
Belousov–Zhabotinskii reaction 228 discretization
bifurcation diagram 97, 105 – biharmonic operator 154
biharmonic operator 154 – Laplace operator 154
boundary conditions 117, 149
distribution function 241
– Dirichlet 150, 152
driven cavity 206
– Neumann 150, 152, 157
drop formation 255
– Robin 150, 157
dynamical system 41
Boussinesq approximation 212
box-counting method 25, 108
E
Box–Muller method 90, 245
eigenvalue problems 279
Brusselator 229
elliptic PDE 149
Burgers equation 146
embedding dimension 110
butterfly effect 15
ensemble 250
C Euler method 60
Campbell–Baker-Hausdorff relation 52 expectation value 241
canonical ensemble 88, 251
canonical equations 50 F
capacity dimension 107 finite differences 118, 153
celestial mechanics 73 finite element
characteristics 144 – evaluation 185
Chebyshev spectral method 173 – Laplace solver 185
Chebyshev–Gauss–Lobatto 174 – mesh generation 185
Chirikov map 13 – method 182
Circle map 13 fixed point 43
codimension-two 228 Floquet
collocation method 129 – exponent 111
color maps 36 – theorem 111
conservative system 58 flow field 204
contact angle 255 flow-apart time 201
convection 211 FORTRAN 1
– equation 145, 167 fractal dimension 25, 106
– fully nonlinear problem 219 fractals 20
– linear stability analysis 215 Fredholm alternative 275
– Rayleigh–Bénard 218 Frenkel–Kotorova model 12
https://doi.org/10.1515/9783110515145-013
318 | Index
N S
Navier–Stokes equations 204 Schmidt–Gram method 104
neural networks 27 Schrödinger equation 122
Newton–Raphson 133 – nonlinear 134
No-Intersection Theorem 44 – stationary 125
normal distribution 243 – stationary two-particle 193
null space 274 – time-dependent 196
self-organized maps 34
O self-similar 23
orbit-type diagram 85 separatrix 60
Oscar II 76 shallow water equations 171
over-relaxation 158 shooting method 140
Sierpinski triangle 22
simple sampling 248
P
specific heat 92
pair correlation function 91
spectral method 178
parabolic PDE 149
spiral patterns 233
parametric instability 112
standard deviation 241
partition sum 251
Standard map 13
PDF 241
Stark effect 123, 130
perceptron 28
strange attractor 47
PGPLOT 5
stream function 205
pivoting 278
subdomain method 129
Poincaré
Swift–Hohenberg equation 235
– map 56
– Metropolis algorithm 267
– section 56, 97
symplectic method 51, 66, 89
Poincaré–Bendixson Theorem 45
Poisson bracket 51
T
Poisson equation 156
Takens, embedding theorem 110
Prandtl number 213
target patterns 233
pressure 204
Thomas algorithm 278
probability density 241
three-body problem 76
pseudospectral method 221, 231
– reduced 79
time-evolution operator 41, 197
Q transformation method 242
QR factorization 281 transport equation 212
quasilinear differential equations 40 traveling salesman problem 37
Trojans 81
R Turing instability 226
random numbers 240
Rayleigh number 213 U
reaction-diffusion systems 225 upwind scheme 168
reconstruction 109
recurrence time 197 V
regularization 82 Van der Pol oscillator 46
Reynolds number 207 variance 241
Rosenblatt rule 29 variational problem 184
Runge–Kutta method 67 velocity field 205
– with adaptive step size 71 Verlet algorithm 53
320 | Index
W
wave equation 169
wave packet 197