Benjamin A. Stickler and Ewald Schachinger

Basic Concepts in Computational Physics2nd ed. 2016

Benjamin A. Stickler

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

Ewald Schachinger

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

ISBN 978-3-319-27263-4e-ISBN 978-3-319-27265-8

https://doi.org/10.1007/978-3-319-27265-8

Library of Congress Control Number: 2015959954

Supplementary material and data can be found on extras.springer.com

© Springer International Publishing Switzerland 2016

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.

The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, express or implied, with respect to the material contained herein or for any errors or omissions that may have been made.

Printed on acid-free paper

This Springer imprint is published by Springer Nature

The registered company is Springer International Publishing AG Switzerland

Preface

Traditionally physics is divided into two fields of activities: theoretical and experimental. As a consequence of the stunning increase in computer power and of the development of more powerful numerical techniques, a new branch of physics was established over the last decades: Computational Physics. This new branch was introduced as a spin-off of what nowadays is commonly called computer simulations . They play an increasingly important role in physics and in related sciences as well as in industrial applications and serve two purposes, namely:

Direct simulation of physical processes such as

∘ Molecular dynamics or

∘ Monte Carlo simulation of physical processes

Solution of complex mathematical problems such as

∘ Differential equations

∘ Minimization problems

∘ High-dimensional integrals or sums

This book addresses all these scenarios on a very basic level. It is addressed to lecturers who will have to teach a basic course/basic courses in Computational Physics or numerical methods and to students as a companion in their first steps into the realm of this fascinating field of modern research. Following these intentions this book was divided into two parts. Part I deals with deterministic methods in Computational Physics. We discuss, in particular, numerical differentiation and integration, the treatment of ordinary differential equations, and we present some notes on the numerics of partial differential equations. Each section within this part of the book is complemented by numerous applications. Part II of this book provides an introduction to stochastic methods in Computational Physics. In particular, we will examine how to generate random numbers following a given distribution, summarize the basics of stochastics in order to establish the necessary background to understand techniques like Markov -Chain Monte Carlo. Finally, algorithms of stochastic optimization are discussed. Again, numerous examples out of physics like diffusion processes or the Potts model are investigated exhaustively. Finally, this book contains an appendix that augments the main parts of the book with a detailed discussion of supplementary topics.

This book is not meant to be just a collection of algorithms which can immediately be applied to various problems which may arise in Computational Physics. On the contrary, the scope of this book is to provide the reader with a mathematically well-founded glance behind the scene of Computational Physics. Thus, particular emphasis is on a clear analysis of the various topics and to even provide in some cases the necessary means to understand the very background of these methods. Although there is a barely comprehensible amount of excellent literature on Computational Physics, most of these books seem to concentrate either on deterministic methods or on stochastic methods. It is not our goal to compete with these rather specific works. On the contrary, it is the particular focus of this book to discuss deterministic methods on par with stochastic methods and to motivate these methods by concrete examples out of physics and/or engineering.

Nevertheless, a certain overlap with existing literature was unavoidable and we apologize if we were not able to cite appropriately all existing works which are of importance and which influenced this book. However, we believe that by putting the emphasis on an exact mathematical analysis of both the deterministic and the stochastic methods, we created a stimulating presentation of the basic concepts applied in Computational Physics.

If we assume two basic courses in Computational Physics to be part of the curriculum, nicknamed here Computational Physics 101 and Computational Physics 102 , then we would like to suggest to present/study the various topics of this book according to the following syllabus:

Computational Physics 101:

Chapter  1 : Some Basic Remarks

Chapter  2 : Numerical Differentiation

Chapter  3 : Numerical Integration

Chapter  4 : The Kepler Problem

Chapter  5 : Ordinary Differential Equations: Initial Value Problems

Chapter  6 : The Double Pendulum

Chapter  7 : Molecular Dynamics

Chapter  8 : Numerics of Ordinary Differential Equations: Boundary Value Problems

Chapter  9 : The One-Dimensional Stationary Heat Equation

Chapter  10 : The One-Dimensional Stationary Schrödinger Equation

Chapter  12 : Pseudo-random Number Generators

Computational Physics 102:

Chapter  11 : Partial Differential Equations

Chapter  13 : Random Sampling Methods

Chapter  14 : A Brief Introduction to Monte Carlo Methods

Chapter  15 : The Ising Model

Chapter  16 : Some Basics of Stochastic Processes

Chapter  17 : The Random Walk and Diffusion Theory

Chapter  18 : Markov -Chain Monte Carlo and the Potts Model

Chapter  19 : Data Analysis

Chapter  20 : Stochastic Optimization

The various chapters are augmented by problems of medium complexity which help to understand better the numerical part of the topics discussed within this book.

Although the manuscript has been carefully checked several times, we cannot exclude that some errors escaped our scrutiny. We apologize in advance and would highly appreciate reports of potential mistakes or typos to Benjamin A. Stickler (benjamin.stickler@uni-due.de).

Throughout the book SI-units are used except stated otherwise.

Benjamin A. Stickler

Ewald Schachinger

Graz, Austria

July 2015

Acknowledgements

The authors are grateful to Profs. Dr C. Lang and Dr. C. Gattringer (Karl-Franzens Universität, Graz, Austria) and to Profs. Dr. W. von der Linden, Dr. H.-G. Evertz, and Dr. H. Sormann (Graz University of Technology, Austria). They inspired this book with their lectures on various topics of Computational Physics, computer simulation, and numerical analysis. Last but not least, the authors thank Dr. Chris Theis (CERN) for meticulously reading the manuscript, for pointing out inconsistencies, and for suggestions to improve the text.

Contents

1 Some Basic Remarks 1

1.​1 Motivation 1

1.​2 Roundoff Errors 6

1.​3 Methodological Errors 7

1.​4 Stability 9

1.​5 Concluding Remarks 12

References 13

Part I Deterministic Methods

2 Numerical Differentiation 17

2.​1 Introduction 17

2.​2 Finite Differences 18

2.​3 Finite Difference Derivatives 20

2.​4 A Systematic Approach:​ The Operator Technique 23

2.​5 Concluding Discussion 26

Summary 29

Problems 29

References 30

3 Numerical Integration 31

3.​1 Introduction 31

3.​2 Rectangular Rule 32

3.​3 Trapezoidal Rule 35

3.4 The Simpson Rule 37

3.5 General Formulation: The Newton-Cotes Rules 38

3.6 Gauss-Legendre Quadrature 41

3.​7 An Example 46

3.​8 Concluding Discussion 48

Summary 50

Problems 50

References 52

4 The Kepler Problem 53

4.​1 Introduction 53

4.​2 Numerical Treatment 56

Summary 60

Problems 60

References 61

5 Ordinary Differential Equations:​ Initial Value Problems 63

5.​1 Introduction 63

5.​2 Simple Integrators 65

5.3 Runge-Kutta Methods 68

5.​4 Hamiltonian Systems:​ Symplectic Integrators 73

5.5 An Example: The Kepler Problem, Revisited 76

Summary 81

Problems 82

References 82

6 The Double Pendulum 85

6.1 Hamilton ’s Equations 85

6.​2 Numerical Solution 89

6.​3 Numerical Analysis of Chaos 94

Summary 99

Problems 100

References 101

7 Molecular Dynamics 103

7.​1 Introduction 103

7.​2 Classical Molecular Dynamics 104

7.​3 Numerical Implementation 108

Summary 113

Problems 114

References 116

8 Numerics of Ordinary Differential Equations:​ Boundary Value Problems 117

8.​1 Introduction 117

8.​2 Finite Difference Approach 119

8.​3 Shooting Methods 124

Summary 128

Problems 129

References 129

9 The One-Dimensional Stationary Heat Equation 131

9.​1 Introduction 131

9.​2 Finite Differences 132

9.​3 A Second Scenario 134

Summary 137

Problems 137

References 138

10 The One-Dimensional Stationary Schrödinger Equation 139

10.​1 Introduction 139

10.​2 A Simple Example:​ The Particle in a Box 143

10.​3 Numerical Solution 147

10.​4 Another Case 151

Summary 155

Problems 155

References 155

11 Partial Differential Equations 157

11.​1 Introduction 157

11.2 The Poisson Equation 158

11.​3 The Time-Dependent Heat Equation 163

11.​4 The Wave Equation 167

11.5 The Time-Dependent Schrödinger Equation 170

Summary 178

Problems 179

References 179

Part II Stochastic Methods

12 Pseudo-random Number Generators 183

12.​1 Introduction 183

12.​2 Different Methods 186

12.​3 Quality Tests 190

Summary 194

Problems 194

References 195

13 Random Sampling Methods 197

13.​1 Introduction 197

13.​2 Inverse Transformation Method 200

13.​3 Rejection Method 202

13.​4 Probability Mixing 206

Summary 208

Problems 208

References 209

14 A Brief Introduction to Monte-Carlo Methods 211

14.​1 Introduction 211

14.​2 Monte-Carlo Integration 213

14.3 The Metropolis Algorithm: An Introduction 219

Summary 222

References 223

15 The Ising Model 225

15.​1 The Model 225

15.​2 Numerics 236

15.​3 Selected Results 240

Summary 245

Problems 245

References 246

16 Some Basics of Stochastic Processes 247

16.​1 Introduction 247

16.​2 Stochastic Processes 248

16.3 Markov Processes 251

16.4 Markov -Chains 259

16.5 Continuous-Time Markov -Chains 266

Summary 268

Problems 269

References 269

17 The Random Walk and Diffusion Theory 271

17.​1 Introduction 271

17.​2 The Random Walk 273

17.3 The Wiener Process and Brownian Motion 279

17.​4 Generalized Diffusion Models 285

Summary 293

Problems 294

References 294

18 Markov -Chain Monte Carlo and the Potts Model 297

18.​1 Introduction 297

18.2 Markov -Chain Monte Carlo Methods 298

18.3 The Potts Model 302

18.4 Advanced Algorithms for the Potts Model 306

Summary 308

Problems 309

References 309

19 Data Analysis 311

19.​1 Introduction 311

19.​2 Calculation of Errors 311

19.​3 Auto-Correlations 315

19.​4 The Histogram Technique 319

Summary 320

Problems 321

References 321

20 Stochastic Optimization 323

20.​1 Introduction 323

20.​2 Hill Climbing 325

20.​3 Simulated Annealing 327

20.​4 Genetic Algorithms 334

20.​5 Some Further Methods 336

Summary 337

Problems 338

References 338

A The Two-Body Problem341

B Solving Non-linear Equations: The Newton Method 347

C Numerical Solution of Linear Systems of Equations349

C.1 The LU Decomposition 350

C.2 The Gauss-Seidel Method 353

D Fast Fourier Transform357

E Basics of Probability Theory363

E.1 Classical Definition363

E.2 Random Variables and Moments364

E.3 Binomial Distribution and Limit Theorems366

E.4 Poisson Distribution and Counting Experiments 367

E.5 Continuous Variables368

E.6 Bayes ’ Theorem 369

E.7 Normal Distribution370

E.8 Central Limit Theorem370

E.9 Characteristic Function371

E.10 The Correlation Coefficient371

E.11 Stable Distributions373

F Phase Transitions375

F.1 Some Basics375

F.2 Landau Theory 376

G Fractional Integrals and Derivatives in 1D379

H Least Squares Fit381

H.1 Motivation381

H.2 Linear Least Squares Fit383

H.3 Nonlinear Least Squares Fit384

I Deterministic Optimization387

I.1 Introduction387

I.2 Steepest Descent388

I.3 Conjugate Gradients390

References399

Index401

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_1

1. Some Basic Remarks

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

1.1 Motivation

Computational Physics aims at solving physical problems by means of numerical methods developed in the field of numerical analysis [1, 2]. According to I. Jacques and C. Judd [3], it is defined as:

Numerical analysis is concerned with the development and analysis of methods for the numerical solution of practical problems.

Although the term practical problems remained unspecified in this definition, it is certainly necessary to reflect on ways to find approximate solutions to complex problems which occur regularly in natural sciences. In fact, in most cases it is not possible to find analytic solutions and one must rely on good approximations. Let us give some examples.

Consider the definite integral

(1.1)

which, for instance, may occur when it is required to calculate the probability that an event following a normal distribution takes on a value within the interval [a, b], where $$a,b \in \mathbb{R}$$. In contrast to the much simpler integral

(1.2)

the integral (1.1) cannot be solved analytically because there is no elementary function which differentiates to $$\exp \left (-x^{2}\right )$$. Hence, we have to approximate this integral in such a way that the approximation is accurate enough for our purpose. This example illustrates that even mathematical expressions which appear quite simple at first glance may need a closer inspection when a numerical estimate for the expression is required. In fact, most numerical methods we will encounter within this book have been designed before the invention of modern computers or calculators. However, the applicability of these methods has increased and is still increasing drastically with the development of even more powerful machines. We give another example, namely the oscillation of a pendulum . We know from basic mechanics [4–8] that the time evolution of a frictionless pendulum of mass m and length ℓ in a gravitational field is modeled by the differential equation

(1.3)

The solution of this equation describes the oscillatory motion of the pendulum around the origin O within a two-dimensional plane (Fig. 1.1).

Fig. 1.1

Schematic illustration of the pendulum

Here $$\theta$$ is the angular displacement and g is the acceleration due to gravity. Furthermore, a common situation is described by initial conditions of the form:

(1.4)

For small initial angular displacements, $$\theta _{0} \ll 1$$, we set in Eq. (1.3) $$\sin \left (\theta \right ) \approx \theta$$ and obtain the differential equation of the harmonic oscillator:

(1.5)

Together with the initial conditions (1.4) we arrive at the solution

(1.6)

with $$\omega = \sqrt{g/\ell}$$. The period τ of the pendulum follows immediately:

(1.7)

However, if the approximation of a small angular displacement $$\theta _{0} \ll 1$$ is not applicable, expressions (1.6) and (1.7) will not be valid. Thus, it is advisable to apply energy conservation in order to arrive at analytic results. The total energy of the pendulum is given by:

(1.8)

Here v is the velocity of the point mass m and v ₀ and $$\theta _{0}$$ are defined by the initial conditions (1.4). Since $$\dot{\theta }(0) = 0$$ we have

(1.9)

where we made use of the relation: $$1 -\cos (x) = 2\sin ^{2}(x/2)$$. We use this result in Eq. (1.8) and arrive at:

(1.10)

Since $$v^{2} =\ell ^{2}\dot{\theta }^{2}$$ we have

(1.11)

Separation of variables yields

(1.12)

with $$k =\sin \left (\theta _{0}/2\right ).$$ For t = τ we have $$\theta =\theta _{0}$$ and we obtain for the period

(1.13)

Let us transform the above integral into a more convenient form with help of the substitution $$k\sin (\alpha ) =\sin \left (\varphi /2\right )$$. Thus, α ∈ [0, π∕2] and a straightforward calculation yields:

(1.14)

The function K ₁(k) introduced in (1.14) for $$k \in \mathbb{R}$$ is referred to as the complete elliptic integral of the first kind [9–12]. All these manipulations did not really result in a simplification of the problem at hand because we are still confronted with the integral in Eq. (1.14) which cannot be evaluated without the use of additional approximations which will, in the end, result in a numerical solution of the problem. A natural way to proceed would be to expand the complete elliptic integral in a power series up to order N, where N is chosen in such a way that the truncation error R N (k) becomes negligible. We can find the desired expression in any text on special functions [9, 11, 12]. It reads

(1.15)

Imagine now the inverse problem: the period τ is given and the initial angle $$\theta _{0}$$ is unknown. Again, we could expand the integrand in a power series and solve the corresponding polynomial for $$\theta _{0}$$. However, such an approach would be very inefficient due to two reasons: first of all, we are confronted with the impossibility of finding analytically the roots of a polynomial of order N > 4¹ and, secondly, at which value of N should we truncate the power series if $$\theta _{0}$$ is unknown? A glance in a book on special functions might give us a better, i.e. more convenient, alternative. Indeed, the inverse function of the elliptic integral K ₁(k) with respect to k can be given explicitly in terms of Jacobi elliptic functions [9–12]. Series expansions of these functions have been developed such that we can approximate $$\theta _{0}$$ by truncating the respective series.

This example helped to illustrate that we depend on numerical approximations of definite expressions in a multitude of cases. Even if an numerically approximate solution has been found for a particular problem it will be adamant to check quite carefully if the approach was (i) justified within the required accuracy, and (ii) if it allowed to improve the induced error of the result. The second point is known as the stability of a routine. We will discuss this topic in more detail in Sect. 1.4.

Throughout this book we will be confronted with numerous methods which will allow approximate solutions of problems similar to the two examples illustrated above. First of all, we would like to specify the properties we expect these methods to have. Primarily, the method is to be formulated as an unambiguous mathematical recipe which can be applied to the set of problems it was designed for. Its applicability should be well defined and it should allow to determine an estimate for the error. Moreover, infinite repetition of the procedure should approximate the exact result to arbitrary accuracy. In other words, we want the method to be well defined in algorithmic form. Consequently, let us define an algorithm as a sequence of logical and arithmetic operations (addition, subtraction, multiplication or division) which allows to approximate the solution of the problem under consideration within any accuracy desired. This implies, of course, that numerical errors will be unavoidable.

Let us classify the occurring errors based on the structure every numerical routine follows: We have input-errors , algorithmic-errors , and output-errors as indicated schematically in Fig. 1.2.

Fig. 1.2

Schematic classification of the errors occurring within a numerical procedure

This structural classification can be refined: input-errors are divided into roundoff errors and measurement errors contained in the input data; algorithmic-errors consist of roundoff errors during evaluation and of methodological errors due to mathematical approximations; finally, output errors are, in fact, roundoff errors. In Sects. 1.2 and 1.3 we will concentrate on roundoff errors and methodological errors. Since in most cases measurement errors cannot be influenced by the theoretical physicist concerned with numerical modeling, this particular part will not be discussed in this book. However, we will discuss the stability of numerical routines, i.e. the influence of slight modifications of the input parameters on the outcome of a particular algorithm in Sect. 1.4.

1.2 Roundoff Errors

In fact, since every number is stored in a computer using a finite number of digits, we have to truncate every non-terminating number at some point. For instance, consider $$\frac{2} {3} = 0.666666666666\ldots$$ which will be stored as 0. 6666666667 if the machine allows only ten digits. Actually, computers use binary arithmetic (for which even 0. 1₁₀ = 0. 000110011001100… ₂ is problematic²) but for the moment we shall ignore this fact since the above example suffices to illustrate the crucial point. Let Fl(x) denote the floating-point form of a number x within the numerical range of the machine. For the above example, i.e. a ten digit storage, we have

(1.16)

This has the consequence that, for instance, $$\mathrm{Fl}(\sqrt{3}) \cdot \mathrm{ Fl}(\sqrt{3})\neq \mathrm{Fl}(\sqrt{3} \cdot \sqrt{3})=3$$. However, $$\mathrm{Fl}(\sqrt{3}) \cdot \mathrm{ Fl}(\sqrt{3}) \approx 3$$ within the defined range. Before we continue our discussion on roundoff errors we have to introduce the concepts of the absolute and the relative error. We denote the true value of a quantity by y and its approximate value by $$\overline{y}$$. Then the absolute error ε a is defined as

(1.17)

while the relative error ε r is given by

(1.18)

provided that y ≠ 0. In most applications, the relative error is more significant. This is illustrated in Table 1.1, where it is intuitively obvious that in the second case the

Table 1.1

Illustration of the significance of the relative error

y

ε a

ε r

(1)

0.1

0.09

0.01

0.1

(2)

1000.0

999.99

0.01

0.00001

approximate value is much better although the absolute error is the same for both examples.

Let us have a look at the relative error of an arbitrary number stored to the k-th digit: We can write an arbitrary number y in the form $$y = 0.d_{1}d_{2}d_{3}\ldots d_{k}d_{k+1}\ldots 10^{n}$$ with d ₁ ≠ 0 and $$n \in \mathbb{Z}$$. Accordingly, we write its approximate value as $$\overline{y} = 0.d_{1}d_{2}d_{3}\ldots d_{k}10^{n}$$, where k is the maximum number of digits stored by the machine. Hence we obtain for the relative error

(1.19)

In the last steps we employed that, since d ₁ ≠ 0, we have $$0.d_{1}d_{2}d_{3}\ldots \geq 0.1$$ and accordingly $$0.d_{k+1}d_{k+2}\ldots &lt; 1$$. If the last digit would have been rounded (for d k+1 ≥ 5 we set $$d_{k} = d_{k} + 1$$ otherwise d k remains unchanged) instead of a simple truncation, the relative error of a variable y would be $$\epsilon _{r} = 0.5 \cdot 10^{-k+1}$$.

Whenever an arithmetic operation is performed, the errors of the variables involved is transferred to the result [15]. This can occur in an advantageous or disadvantageous way, where we understand disadvantageous as an increase in the relative error. Particular care is required when two nearly identical numbers are subtracted (subtractive cancellation ) or when a large number is divided by a, in comparison, small number. In such cases the roundoff error will increase dramatically. We note that it might be necessary to avoid such operations in our aim to design an algorithm which is required to produce reasonable results. An illustrative example and its remedy will be discussed in Sect. 1.3. However, before proceeding to the next section we introduce a lower bound to the accuracy which is achievable with a non-ideal computer, the machine-number . The machine-number is smallest positive number η which can be added to another number, such that a change in the result is observed. In particular,

(1.20)

For a (nonexistent) super-computer, which is capable of saving as much digits as desired, η would be arbitrarily small. A typical value for double-precision in Fortran or C is η ≈ 10⁻¹⁶.

1.3 Methodological Errors

A methodological error is introduced into the routine whenever a complex mathematical expression is replaced by an approximate, simpler one. We already came across an example when we regarded the series representation of the elliptic integral (1.12) in Sect. 1.1. Although we could evaluate the series up to an arbitrary order N, we are definitely not able to sum up the coefficients to infinite order. Hence, it is not possible to get rid of methodological errors whenever we have to deal with expressions we cannot evaluate analytically. Another intriguing example is the numerical differentiation of a given function. The standard approximation of a derivative reads

(1.21)

This approximation is referred to as finite difference and will be discussed in more detail in Chap. 2 One would, in a first guess, expect that the obtained value gets closer to the true value of the derivative f′(x ₀) with decreasing values of h. From a calculus point of view, this is correct since by definition

(1.22)

However, this is not the case numerically. In particular, one can find a value $$\hat{h}$$ for which the relative error is minimal, while for values $$h &lt;\hat{ h}$$ and $$h &gt;\hat{ h}$$ the approximation obtained is worse in comparison. The reason is that for small values of h the roundoff errors dominate the result since f(x ₀ + h) and f(x ₀) almost cancel while 1∕h is very small. For $$h &gt;\hat{ h}$$, the methodological error, i.e. the replacement of a derivative by a finite difference, controls the result.

We give one further example [16] in order to illustrate the interplay between methodological errors and roundoff errors. We regard the, apparently nonhazardous, numerical solution of a quadratic equation

(1.23)

where $$a,b,c \in \mathbb{R}$$, a ≠ 0. The well known solutions read

(1.24)

Cautious because of the above examples, we immediately diagnose the danger of a subtractive cancellation in the expression of x ₁ for b > 0 or in x ₂ for b < 0, and rewrite the above expression for x ₁:

(1.25)

For x ₂ we obtain

(1.26)

Consequently, if b > 0 x ₁ should be calculated using Eq. (1.25) and if b < 0 Eq. (1.26) should be used to calculate x ₂. Moreover, the above expressions can be cast into one expression by setting

(1.27)

with

(1.28)

Thus, Eqs. (1.27) and (1.28) can be used to calculate x ₁ and x ₂ for any sign of b.

1.4 Stability

When a new numerical method is designed stability is the third crucial point after roundoff errors and methodological errors [17]. We give an introductory definition :

An algorithm, equation or, even more general, a problem is referred to as unstable or ill-conditioned if small changes in the input cause a large change in the output.

It will be followed by a couple of elucidating examples [3].³ To be more specific, let us now, for instance, consider the following system of equations

(1.29)

These equations are easily solved and give x = 1. 0 and y = 1. 0. To make our point we consider now the case in which the right hand side of the second equation of (1.29) is subjected to a small perturbation, i.e. we consider in particular the following system of equations

(1.30)

The corresponding solution is x = 0. 0 and y = 2. 0. We observe that a relative change of 0. 05 % on the right hand side of the second equation in (1.29) resulted in a 100 % relative change of the solution. Moreover, if the coefficient of y in the second equation of (1.29) were 1. 0 instead of 1. 01, which corresponds to a relative change of 1 %, the equations would be unsolvable. This is a behavior typical for ill-conditioned problems which, for obvious reasons, should be avoided whenever possible.

We give a second example: We consider the following initial value problem

(1.31)

The general solution is readily obtained to be of the form

(1.32)

with numerical constants A and B. The initial conditions yield the unique solution

(1.33)

The initial conditions are now changed by two small parameters δ, ε > 0 to give:

(1.34)

The unique solution which satisfies these initial conditions is:

(1.35)

We calculate the relative error

(1.36)

which indicates that the problem is ill-conditioned since for large values of x the second term definitely overrules the first one.

Another, but not less serious kind of problem is induced instability :

A method is referred to as induced unstable if a small error at one point of the calculation induces a large error at some subsequent point.

Induced instability is particularly dangerous since small roundoff errors are unavoidable in most calculations. Hence, if some part of the whole algorithm is ill-conditioned, the final output will be dominated by the error induced in such a way. Again, an example will help to illustrate such behavior. The definite integral

(1.37)

is considered. Integration by parts yields

(1.38)

This expression can be used to recursively calculate I n from I ₀, where

(1.39)

Although the recursion formula (1.38) is exact we will run into massive problems using it. The reason is easily illustrated:

(1.40)

Thus, the initial roundoff error included in the numerical value of I ₀ is multiplied with n! . Note that for large n we have according to Stirling’s approximation

(1.41)

i.e. an initial error increases almost as n n .

However, Eq. (1.38) can be reformulated to give

(1.42)

and this opens an alternative method for a recursive calculation of I n . We can start with some value N ≫ n and simply set I N  = 0. The error introduced in such a way may in the end not be acceptable, nevertheless, it decreases with every iteration step due to the division by n in Eq. (1.42).

Having discussed some basic features of stability in numerical algorithms we would like to add a few remarks on Chaos Theory . Chaos theory investigates dynamical processes which are very sensitive to initial conditions. One of the best known examples for such a behavior is the weather prediction. Although, Poincaré already observed chaotic behavior while working on the three body problem, one of the pioneers of chaos theory was E.N. Lorenz [18] (not to be confused with H. Lorentz, who introduced the Lorentz transformation). In 1961 he ran weather simulations on a computer of restricted capacity. However, when he tried to reproduce one particular result by restarting the calculation with new parameters calculated the days before, he observed that the outcome was completely different [19]. The reason was that the equations he dealt with were ill-conditioned, and the roundoff error he introduced by simply typing in the numbers of the graphical output, increased drastically, and, hence, produced a completely different result. Nowadays, various physical systems are known which indeed behave in such a way. Further examples are turbulences in fluids, oscillations in electrical circuits, oscillating chemical reactions, population growth in ecology, the time evolution of the magnetic field of celestial bodies, ….

It is important to note, that chaotic behavior induced in such systems is deterministic, yet unpredictable. This is due to the impossibility of an exact knowledge of the initial conditions required to predict, for instance, the weather over a reasonably long period. A feature which is referred to as the butterfly effect: a hurricane can form because a butterfly flapped its wings several weeks before. However, these effects have nothing to do with intrinsically probabilistic properties which are solely a feature of quantum mechanics. In contrast to this, in chaos theory, the future is uniquely determined by initial conditions, however, still unpredictable. This is often referred to as deterministic chaos .

It has to be emphasized that chaos in physical systems is a consequence of the equations describing the processes and not a consequence of the numerical method used for modeling. Therefore, it is important to distinguish between the stability of a numerical method and the stability of a physical system in general.

We will come across chaotic behavior again in Sect. 6.​3 where we discuss chaotic behavior in the dynamics of the double pendulum [4–8].

1.5 Concluding Remarks

In this chapter we dealt with the basic features of numerical errors one is always confronted with when developing an algorithm. One point we neglected in our discussion is the computational cost , i.e. the time a program needs to be executed. Although this is a very important point, it is beyond the scope of this book. However, one has to find a balance between the need of achieving the most accurate result and the computing time required to achieve it. The most accurate result is useless if the programmer does not get the result within his lifetime. D. Adams [20] put in a nutshell: the super-computer Deep Thought was asked to compute the answer to “The Ultimate Question of Life, the Universe and Everything”, quote:

“How long?” he said. “Seven and a half million years.”

Another quite crucial point, which we neglected so far, is the error analysis of a computational method which is based on random numbers (in fact it is pseudo-random numbers and this point will be discussed in the second part of this book). In this case, the situation changes completely, because, similar to experimental results, the observed values are distributed around a mean with a certain variance. Such results have to be interpreted within a statistical context. However, it turns out that for many problems the computational efficiency can be significantly increased using such methods. Typical applications are estimates of integrals or solutions to optimization problems. Such topics will be treated in the second part of this book.

References

1.

Süli, E., Mayers, D.: An Introduction to Numerical Analysis. Cambridge University Press, Cambridge (2003)CrossrefMATH

2.

Gautschi, W.: Numerical Analysis. Springer, Berlin/Heidelberg (2012)CrossrefMATH

3.

Jacques, I., Judd, C.: Numerical Analysis. Chapman and Hall, London (1987)CrossrefMATH

4.

Arnol’d, V.I.: Mathematical Methods of Classical Mechanics, 2nd edn. Graduate Texts in Mathematics, vol. 60. Springer, Berlin/Heidelberg (1989)

5.

Fetter, A.L., Walecka, J.D.: Theoretical Mechanics of Particles and Continua. Dover, New York (2004)MATH

6.

Scheck, F.: Mechanics, 5th edn. Springer, Berlin/Heidelberg (2010)CrossrefMATH

7.

Goldstein, H., Poole, C., Safko, J.: Classical Mechanics, 3rd edn. Addison-Wesley, Menlo Park (2013)MATH

8.

Fließbach, T.: Mechanik, 7th edn. Lehrbuch zur Theoretischen Physik I. Springer, Berlin/Heidelberg (2015)MATH

9.

Abramovitz, M., Stegun, I.A. (eds.): Handbook of Mathemathical Functions. Dover, New York (1965)

10.

Olver, F.W.J., Lozier, D.W., Boisvert, R.F., Clark, C.W.: NIST Handbook of Mathematical Functions. Cambridge University Press, Cambridge (2010)MATH

11.

Mathai, A.M., Haubold, H.J.: Special Functions for Applied Scientists. Springer, Berlin/Heidelberg (2008)CrossrefMATH

12.

Beals, R., Wong, R.: Special Functions. Cambridge Studies in Advanced Mathematics. Cambridge University Press, Cambridge (2010)CrossrefMATH

13.

Clark, A.: Elements of Abstract Algebra. Dover, New York (1971)

14.

Chartier, T.: Devastating roundoff error. Math. Horiz. 13, 11 (2006). http://​www.​jstor.​org/​stable/​25678616 Crossref

15.

Ueberhuber, C.W.: Numerical Computation 1: Methods, Software and Analysis. Springer, Berlin/Heidelberg (1997)CrossrefMATH

16.

Burden, R.L., Faires, J.D.: Numerical Analysis. PWS-Kent Publishing Comp., Boston (1993)MATH

17.

Higham, N.J.: Accuracy and Stability of Numerical Algorithms, 2nd edn. Society for Industrial and Applied Mathematics (SIAM), Philadelphia (2002)

18.

Lorenz, E.N.: Deterministic nonperiodic flow. J. Atmos. Sci. 20, 130–141 (1963)ADSCrossref

19.

Roulstone, I., Norbury, J.: Invisible in the Storm: The Role of Mathematics in Understanding Weather. Prinecton University Press, Princeton (2013)CrossrefMATH

20.

Adams, D.: The Hitchhiker’s Guide to the Galaxy. Pan Books, London (1979)

Footnotes

1

The roots of a real valued polynomial of order N = 3 or 4 are referred to as Cardano’s or Ferrari’s solutions [13], respectively.

2

A disastrous effect of this binary approximation of 0.1 was discussed by T. Chartier [14].

3

Although unstable behavior is not desirable in the first place the discovery of unstable systems was the birth of a specific branch in physics called Chaos Theory. We briefly comment on this point at the end of this section.

Part IDeterministic Methods

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_2

2. Numerical Differentiation

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

2.1 Introduction

This chapter is the first of two systematic introductions to the numerical treatment of differential equations. Differential equations and, thus, derivatives and integrals are of eminent importance in the modern formulation of natural sciences and in particular of physics. Very often the complexity of the expressions involved does not allow an analytical approach, although modern symbolic software can ease a physicists life significantly. Thus, in many cases a numerical treatment is unavoidable and one should be prepared.

We introduce here the notion of finite differences as a basic concept of numerical differentiation [1–3]. In contrast, the next chapter will deal with the concepts of numerical quadrature. Together, these two chapters will set the stage for a comprehensive discussion of algorithms designed to solve numerically differential equations. In particular, the solution of ordinary differential equations will always be based on an integration.

This chapter is composed of four sections. The first repeats some basic concepts of calculus and introduces formally finite differences. The second formulates approximates to derivatives based on finite differences, while the third section includes a more systematic approach based on an operator technique. It allows an arbitrarily close approximation of derivatives with the advantage that the expressions discussed in this section can immediately be applied to the problems at hand. The chapter is concluded with a discussion of some additional aspects.

2.2 Finite Differences

Let us consider a smooth function f(x) on the finite interval $$[a,b] \subset \mathbb{R}$$ of the real axis. The interval [a, b] is divided into $$N - 1 \in \mathbb{N}$$ equally spaced sub-intervals of the form [x i , x i+1] where x ₁ = a, x N  = b. Obviously, x i is then given by

(2.1)

We introduce the distance h between two grid-points x i by:

(2.2)

For the sake of a more compact notation we restrict our discussion to equally spaced grid-points keeping in mind that the extension to arbitrarily spaced grid-points by replacing h by h i is straight forward and leaves the discussion essentially unchanged.

Note that the number of grid-points and, thus, their distance h, has to be chosen in such a way that the function f(x) can be sufficiently well approximated by its function values f(x i ) as indicated in Fig. 2.1. We understand by sufficiently well approximated that some interpolation

Fig. 2.1

We define equally spaced grid-points x i on a finite interval on the real axis in such a way that the function f(x) is sufficiently well approximated by its functional values f(x i ) at these grid-points

scheme in the interval [x i , x i+1] will reproduce the function f(x) within a required accuracy. In cases where the function is strongly varying within some sub-interval $$[c,d] \subset [a,b]$$ and is slowly varying within $$[a,b]\setminus [c,d]$$ it might be advisable to use variable grid-spacing in order to reduce the computational cost of the procedure.

We introduce the following notation: The function value of f(x) at the grid-point x i will be denoted by f i  ≡ f(x i ) and its n-th derivative:

(2.3)

Furthermore, we define for arbitrary $$\xi \in [x_{i},x_{i+1})$$

(2.4)

where $$f_{i+\epsilon }^{(0)} \equiv f_{i+\epsilon }$$ and ε is chosen to give:

(2.5)

Let us remember some basics from calculus: The first derivative, denoted f′(x) of a function f(x) which is smooth within the interval [a, b], i.e. $$f(x) \in \mathcal{C}^{\infty }[a,b]$$ for arbitrary x ∈ [a, b], is defined as

(2.6)

However, it is impossible to draw numerically the limit h → 0 as discussed in Sect. 1.​3, Eq. (1.​22). This manifests itself in a non-negligible error due to subtractive cancellation.

This problem is circumvented by the use of Taylor’s theorem. It states that if there is a function which is (n + 1)-times continuously differentiable on the interval [a, b] then f(x) can be expressed in terms of a series expansion at point x ₀ ∈ [a, b]:

(2.7)

Here, ζ(x) takes on a value between x and x ₀.¹ The last term on the right hand side of Eq. (2.7) is commonly referred to as truncation error . (A more general definition of this error was given in Sect. 1.​1)

We introduce now the finite difference operators

(2.8a)

as the forward difference ,

(2.8b)

as the backward difference , and

(2.8c)

as the central difference .² The derivative of f(x) can be approximated with the help of Taylor’s theorem (2.7). In a first step we consider (restricting to third order in h)

(2.9a)

with $$f_{i+1} \equiv f(x_{i} + h)$$. Here ε ζ is the fractional part ε which has to be determined according to ζ(x i + h). In analogue we find for f i−1

(2.9b)

Solving Eqs. (2.9) for the derivative f′ i leads directly to the definition of finite difference derivatives.

2.3 Finite Difference Derivatives

We define the finite difference derivative or difference approximations

(2.10a)

as the forward difference derivative ,

(2.10b)

as the backward difference derivative , and

(2.10c)

as the central difference derivative .³ A graphical interpretation of these

expressions is straight forward and is presented in Fig. 2.2.

Fig. 2.2

Graphical illustration of different finite difference derivatives. The solid line labeled f′ i represents the real derivative for comparison

Using the above definitions (2.10) together with the expansions (2.9) we obtain

(2.11)

We observe that in the central difference approximation of f′ i the truncation error scales like h ² while it scales like h in the other two approximations; thus the central difference approximation should have the smallest methodological error . Note that the error is usually not dominated by the derivatives of f(x) since we assumed that f(x) is a smooth function and sufficiently well approximated on the grid within [a, b]. Furthermore we have to emphasize that the central difference approximation is essentially a three point approximation , including f i−1, f i and f i+1, although f i cancels. Thus, we can improve our approximation by taking even more grid-points into account. For instance, we could combine the above finite difference derivatives. Let us prepare this step by expanding Eqs. (2.9) to higher order derivatives. We then obtain for the forward difference derivative

(2.12)

for the backward difference derivative

(2.13)

and, finally, for the central difference derivative

(2.14)

In order to improve the method we have to combine D ₊ f i , D ₋ f i and D c f i from different grid-points in such a way that at least the terms proportional to h ² cancel. This can be achieved by observing that⁴

(2.15)

which gives

(2.16)

Note that this simple combination yields an improvement of two orders in h ! One can even improve the approximation in a similar fashion by simply calculating the derivative from even more points, for instance f i±3.

2.4 A Systematic Approach: The Operator Technique

We would like to obtain a general expression which will allow to calculate the finite difference derivatives of arbitrary order up to arbitrary order of h in the truncation error . We achieve this goal by introducing the shift operator T and its inverse operator T ⁻¹ as⁵

(2.18)

and

(2.19)

where $$TT^{-1} ={1\!\!1}$$ is the unity operator. We can write these operators in terms of the forward and backward difference operators Δ ₊ and Δ ₋ of Eqs. (2.8), in particular

(2.20)

and

(2.21)

Moreover, if D ≡ d∕dx denotes the derivative operator and if the n-th power of this operator D is understood as the n-th successive application of it, we can rewrite the Taylor expansions  (2.9) as

(2.22)

and

(2.23)

Hence, we find that [7]⁶

(2.24)

and, accordingly, that

(2.25)

Finally, we obtain the central difference operator:

(2.26)

Equations (2.24), (2.25) and (2.26) can be inverted for hD:

(2.27)

Again, the n-th power of an operator K (with $$K =\varDelta _{+},\varDelta _{-},\varDelta _{c}$$) K n f i is understood as the n-th successive action of the operator K on f i , i.e. $$K^{n-1}\left (Kf_{i}\right )$$. Expression (2.27) allows to approximate the derivatives up to arbitrary order using finite differences. Furthermore, we can take the k-th power of Eq. (2.27) in order to get an approximate k-th derivative, (hD) k [7].

However, it turns out that the expansion (2.27) in terms of the central difference Δ c does not optimally use the grid because it contains only odd powers of Δ c . For instance, the third power Δ c ³ f i includes the function values f i±3 and f i±1 at ‘odd’ grid-points but ignores the function values f i and f i±2 at ‘even’ grid-points. Since this is true for all odd powers of Δ c we observe that the expansion (2.27) uses only half of the grid. On the other hand, if one computes the square (hD)² of (2.27) only ‘even’ grid-points are used, while the ‘odd’ grid-points are ignored. This reduces the accuracy of the method and an improvement is required. The easiest remedy is to formally introduce function values $$T^{\pm \frac{1} {2} }f_{i}\stackrel{!}{=}f_{i\pm 1/2}$$ at intermediate grid-points⁷ $$x_{i\pm 1/2} = x_{i} \pm h/2$$. This definition allows to introduce the central difference operator δ c of intermediate grid-points,

(2.28)

and the average operator:

(2.29)

The central difference operator Δ c on the grid is connected to the central difference operator δ c of intermediate grid-points by:

(2.30)

To avoid the problem of Eq. (2.27) that only odd or even grid-points are accounted for we replace all shift operators Δ c ∕2 by δ c and then multiply the right hand side of Eq. (2.27) by μ. This ensures that function values at intermediate grid-points will not appear in the final expression. Hence, we obtain for the first order derivative operator:

(2.31)

When higher order derivatives are calculated, we replace, again, Δ c ∕2 by δ c and multiply odd powers of δ c by μ. This procedure results, for instance, in the second order derivative operator:

(2.32)

In particular, we obtain for the central difference derivative

(2.33)

and

(2.34)

Here, $$\mathcal{O}(h^{2})$$ indicates that this term is of the order of h ² and we get the important result that the truncation error is of the order $$\mathcal{O}(h^{2})$$.⁸

2.5 Concluding Discussion

First of all, although Eq. (2.27) allows to approximate a derivative of any order k arbitrarily close, it is still an infinite series which leaves us with the decision at which order to truncate. This choice will highly depend on the choice of h which in turn depends on the function we would like to differentiate. Consider, for instance, the periodic function

(2.35)

where $$\omega,x \in \mathbb{R}$$ and i is the imaginary unit with $$i^{2} = -1$$. Its first derivative is

(2.36)

We now introduce grid-points by

(2.37)

where h is the grid-spacing and x ₀ is some finite starting point on the real axis. Accordingly,

(2.38)

and the exact value of the first derivative is

(2.39)

We calculate the forward, backward, and central difference derivatives according to Eqs. (2.10) and obtain

(2.40a)

with $$\text{sinc}(x) =\sin (x)/x$$ and

(2.40b)

and

(2.40c)

We divide the approximate derivatives by the true value (2.39) and take the modulus. We get

(2.41)

and

(2.42)

Since $$\vert \sin (x)\vert \leq \vert x\vert$$, $$\forall x \in \mathbb{R}$$ we obtain that in all three cases this ratio is less than one independent of h, unless ω = 0. (Please keep in mind that sinc(x) → 1 as x → 0.) Hence, the first order finite difference approximations underestimate the true value of the derivative. The reason is easily found: f(x) oscillates with frequency ω while the finite difference derivatives applied here approximate the derivative linearly. Higher order corrections will, of course, improve the approximation significantly. Furthermore, we observe that the one-sided finite difference derivatives (2.40a) and (2.40b) are exactly zero if hω = 2nπ, $$n \in \mathbb{N}$$, i.e. if the grid-spacing h matches a multiple of the frequency 2π ω of the function f(x). The same occurs when central derivatives (2.40c) are used, but now for hω = π n. This is not really a problem in our example because we choose the grid-spacing h ≪ 2π∕ω in order to approximate the function f(x) sufficiently well. However, in many cases the analytic form of the function is unknown and we only have its representation on the grid. In this case one has to check carefully by changing h whether the function is periodic or not.

We discuss, finally, how to approximate partial derivatives of functions which depend on more than one variable. Basically this can be achieved by independently discretisizing the function of interest in each particular variable and then by defining the corresponding finite difference derivatives. We will briefly discuss the case of two variables and the extension to even more variables is straight forward. We regard a function g(x, y) where (x, y) ∈ [a, b] × [c, d]. We denote the grid-spacing in x-direction by h x and in y-direction by h y . The evaluation of derivatives of the form $$\frac{\partial ^{n}} {\partial x^{n}}g(x,y)$$ or $$\frac{\partial ^{n}} {\partial y^{n}}g(x,y)$$ for arbitrary n are approximated with the help of the schemes discussed above, only the respective grid-spacing has to be accounted for. We will now briefly discuss mixed partial derivatives, in particular the derivative $$\frac{\partial ^{2}} {\partial x\partial y}g(x,y)$$. Higher orders can be easily obtained in the same fashion. Here, we will restrict to the case of the central difference derivative. Again, the extension to the other two forms of derivatives is straight forward. We would like to approximate the derivative at the point $$(a + ih_{x},c + jh_{y})$$, which will be abbreviated by (i, j). Hence, we compute

(2.43)

where we made use of the notation g i, j  ≡ g(x i , y j ). Neglecting higher order contributions yields

(2.44)

This simple approximation is easily improved with the help of methods developed in the previous sections.

It should be noted that there are also other methods to approximate derivatives. One of the most powerful methods, is the method of finite elements [8]. The conceptual difference to the method of finite differences is that one divides the domain in finite sub-domains (elements) rather than by replacing these by sets of discrete grid-points. The function of interest, say g(x, y), is then replaced within each element by an interpolating polynomial. However, this method is quite complex and definitely beyond the scope of this book. Another interesting method, which is particularly useful for the solution of hyperbolic differential equations, is the method of finite volumes. The interested reader is referred to the book by R. J. LeVeque [9].

Summary

In a first step the notion of finite differences was introduced: All functions are approximated only by their functional values at discrete grid-points and by interpolation schemes between these points. This served as a basis for the definition of finite difference derivatives. Three different types were discussed: the forward, the backward, and the central difference derivative. A more systematic approach to finite difference derivatives was then offered by the operator technique. It provided ready to use equations which allowed to approximate a particular derivative of arbitrary order to arbitrary order of grid-spacing. The two methodological errors introduced by this method, namely the subtractive cancellation error due to too dense a grid and the truncation error due to too coarse a grid were discussed in detail.

Problems

1.

Derive Eq. (2.32).

2.

Calculate numerically the derivative of the function

with ω ₂ = 0. 5 and ω ₂ = 10ω ₁. Use a non-uniform grid. Calculate locally the relative error of your approximation.

3.

Extend your code of the previous example to arbitrary ω ₁ ≤ 10ω ₂ and ω ₂ = 0. 5 by implementing an adaptive grid-spacing. In particular, write a routine which recursively finds a suitable grid-spacing.

4.

Consider the finite interval $$I = [-5,5]$$ on the real axis. Define N equally spaced grid-points $$x_{i} = x_{1} + (i - 1)h$$, i = 1, …, N. Investigate the functions

a.

Plot these functions within the interval I by defining these functions on the grid-points x i .

b.

Plot the first derivative of these functions by analytical differentiation.

c.

Calculate and plot the first derivatives of these functions by employing the first order backward, forward, and central difference derivatives. For the central difference derivative use an algorithm which is based on the grid-points x i−1 and x i+1 rather than the method based on intermediate grid-points $$x_{i\pm \frac{1} {2} }$$.

d.

Calculate and plot the first central difference derivatives of these functions by employing second order corrections. These corrections can be obtained by applying the sum representation of the derivative operator defined in Sect. 2.4, last line of Eq. (2.31), i.e. take the term proportional to δ c ³ into account!

e.

Calculate the absolute and the relative error of the above methods. Note that the exact values are known analytically.

f.

Repeat the above steps for the second derivative of the function h(x). For the second order correction of the central difference derivative take the term proportional to δ c ⁴ in Eq. (2.32) into account.

g.

Try different values of N.

5.

Consider the function:

a.

Calculate numerically its gradient ∇f(x, y) and compare with the analytical result.

b.

Demonstrate numerically that gradient fields are curl-free, i.e. ∇×∇f(x, y) = 0 for all x and y.

References

1.

Jordan, C.: Calculus of Finite Differences, 3rd edn. AMS Chelsea Publishing, Providence (1965)

2.

Süli, E., Mayers, D.: An Introduction to Numerical Analysis. Cambridge University Press, Cambridge (2003)

3.

Gautschi, W.: Numerical Analysis. Springer, Berlin/Heidelberg (2012)

4.

Weidmann, J.: Lineare Operatoren in Hilberträumen, vol. I: Grundlagen. Springer, Berlin/Heidelberg (2000)

5.

Davies, E.B.: Linear Operators and Their Spectra. Cambridge Studies in Advanced Mathematics. Cambridge University Press, Cambridge (2007)

6.

Tung, W.K.: Group Theory in Physics. World Scientific, Hackensack (2003)

7.

Lapidus, L., Pinder, G.F.: Numerical Solution of Partial Differential Equations. Wiley, New York (1982)

8.

Gockenbach, M.S.: Understanding and Implementing the Finite Element Method. Cambridge University Press, Cambridge (2006)

9.

LeVeque, R.J.: Finite Volume Methods for Hyperbolic Problems. Cambridge Texts in Applied Mathematics. Cambridge University Press, Cambridge (2002)

Footnotes

1

Note that for x ₀ = 0 the series expansion (2.7) is referred to as Mclaurin series.

2

Please note that the symbols Δ ₊, Δ ₋, and Δ c in Eqs. (2.8) are linear operators acting on f i . For a basic introduction to the theory of linear operators see for instance [4, 5].

3

The central difference derivative is related to the forward and backward difference derivatives via:

4

Please note that the Taylor expansion of $$(D_{c}f_{i-1} + D_{c}f_{i+1})/2 = (\,f_{i+2} - f_{i-2})/(4h)$$ is equivalent to the expansion (2.14) of D c f i with h replaced by 2h.

5

We note in passing that the shift operators form the discrete translational group, a very important group in theoretical physics. Let T(n) = T n denote the shift by $$n \in \mathbb{N}$$ grid-points. We then have

(2.17a)

(2.17b)

and

(2.17c)

which are the properties required to form a group. Here $$\nVdash $$ denotes unity. Moreover, we have

(2.17d)

i.e. it is an Abelian group. The group of discrete translations is usually denoted by $$\mathbb{T}^{d}$$ [6].

6

This representation of the shift operator T explains why the derivative operator D is frequently referred to as the infinitesimal generator of translations [6].

7

These intermediate grid-points are virtual, auxiliary grid-points which will be eliminated in due course.

8

The leading order of the truncation error can be determined by inserting the dominant contribution of Eqs. (2.28) and (2.29) into the remainder of Eqs. (2.31) and (2.32), respectively. For instance, it follows from Eq. (2.29) that $$\mu \sim \mathcal{O}(1)$$ and from Eq. (2.28) that $$\delta _{c} \sim \mathcal{O}(h)$$ and, hence, we find with the help of Eq. (2.31) that $$\mu \delta _{c}^{3}/h \sim \mathcal{O}(h^{2})$$. In analogue, we obtain from Eq. (2.32) that $$\delta _{c}^{4}/h^{2} \sim \mathcal{O}(h^{2})$$.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_3

3. Numerical Integration

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

3.1 Introduction

Numerical integration is certainly one of the most important concepts in computational analysis since it plays a major role in the numerical treatment of differential equations. Given a function f(x) which is continuous on the interval [a, b], one wishes to approximate the integral by a discrete sum of the form

(3.1)

where the ω i are referred to as weights and x i are the grid-points at which the function needs to be evaluated. Such methods are commonly referred to as quadrature [1, 2].

We will mainly discuss two different approaches to the numerical integration of arbitrary functions. We start with a rather simple approach, the rectangular rule. The search of an improvement of this method will lead us first to the trapezoidal rule, then to the Simpson rule and, finally, to a general formulation of the method, the Newton-Cotes quadrature. This will be followed by a more advanced technique, the Gauss-Legendre quadrature. At the end of the chapter we will discuss an elucidating example and briefly sketch extensions of all methods to more general problems, such as integration of non-differentiable functions or the evaluation of multiple integrals.

Another very important approach, which is based on random sampling methods, is the so called Monte-Carlo integration. This method will be presented in Sect. 14.​2

3.2 Rectangular Rule

The straight forward approach to numerical integration is to employ the concept of finite differences developed in Sect. 2.​2 We regard a smooth function f(x) within the interval [a, b], i.e. $$f(x) \in \mathcal{C}^{\infty }[a,b]$$. The Riemann definition of the proper integral of f(x) from a to b states that:

(3.2)

We approximate the right hand side of this relation using equally spaced grid-points $$x_{i} \in [a,b]$$ according to Eq. (2.​1) and find

(3.3)

It is clear that the quality of this approach strongly depends on the discretization chosen, i.e. on the values of x i as illustrated schematically in Fig. 3.1.

Fig. 3.1

Illustration of the numerical approximation of a proper integral according to Eq. (3.3)

Again, a non-uniform grid may be of advantage. We can estimate the error of this approximation by expanding f(x) into a Taylor series .

We note that

(3.4)

hence, the approximation (3.3) is equivalent to an estimate of the area in the unit interval, the elemental area:

(3.5)

Furthermore, we find following Eq. (2.9a):

(3.6)

In this last step we applied the first mean value theorem for integration which states that if f(x) is continuous in [a, b], then there exists a $$\zeta \in [a,b]$$ such that

(3.7)

(We shall come back to the mean value theorem in the course of our discussion of Monte-Carlo integration in Chap. 14) Consequently, the error we make with approximation (3.3) can be seen from Eq. (3.6) to be of the order $$\mathcal{O}(h^{2})$$.

This procedure corresponds to a forward difference approach and, equivalently, backward differences can be used. This results in:

(3.8)

Let us now define the forward and backward rectangular rule by

(3.9)

and

(3.10)

respectively. Thus, we obtain from Taylor’s expansion that:

(3.11)

However, the use of central differences gives more accurate results as has already been observed in Chap. 2 in which the differential operator was approximated. We make use of the concept of intermediate grid-points (see Sect. 2.​4) and consider the integral

(3.12)

expand f(x) in a Taylor series around the midpoint $$x_{i+\frac{1} {2} }$$, and obtain:

(3.13)

Thus, the error generated by this method, the central rectangular rule, scales as $$\mathcal{O}(h^{3})$$ which is a significant improvement in comparison to Eqs. (3.3) and (3.8).¹ We obtain

(3.14)

This approximation is known as the rectangular rule. It is illustrated in Fig. 3.2. Note that the boundary points x ₁ = a and x N  = b do

Fig. 3.2

Scheme of the rectangular integration rule according to Eq. (3.14). Note that boundary points do not enter the evaluation of the elemental areas

not enter Eq. (3.14). Such a procedure is commonly referred to as an open integration rule . On the other hand, if the end-points are taken into account by the method it is referred to as a closed integration rule .

3.3 Trapezoidal Rule

An elegant alternative to the rectangular rule is found when the area between two grid-points is approximated by a trapezoid as is shown schematically in Fig. 3.3. The trapezoidal rule is obtained when the function values $$f_{i+1/2}$$ at intermediate grid-points on the right hand side of the central rectangular rule (3.13) are approximated with the help of $$\mu f_{i+1/2}$$, Eq. (2.​29). Thus, the elemental area is calculated from

(3.15)

and we obtain:

(3.16)

Fig. 3.3

Sketch of how the elemental areas under the curve f(x) are approximated by trapezoids

Note that this integration rule is closed, although the boundary points f ₁ and f N enter the summation (3.16) only with half the weight in comparison to all other function values f i . This stems from the fact that the function values f ₁ and f N contribute only to one elemental area, the first and the last one. Another noticeable feature of the trapezoidal rule is that, in contrast to the rectangular rule (3.14), only function values at grid-points enter the summation, which can be desirable in some cases.

The error of this method can be estimated by inserting expansion (2.9a) into Eq. (3.16). One obtains for an elemental area:

(3.17)

On the other hand, we know from Eq. (3.6) that

(3.18)

which, when inserted into (3.17), yields

(3.19)

Hence, we observe that the error induced by the trapezoidal rule is comparable to the error of the rectangular rule, namely $$\mathcal{O}(h^{3})$$. However, since we do not have to compute function values at intermediate grid-points, this rule may be advantageous in many cases.

We remember from Chap. 2 that a more accurate estimate of a derivative was achieved by increasing the number of grid-points involved which in the case of integration leads us to the Simpson rule.

3.4 The Simpson Rule

The basic idea of the Simpson rule is to include higher order derivatives into the expansion of the integrand. These higher order derivatives, which are primarily unknown, are then approximated by expressions we obtained within the context of finite difference derivatives. Let us discuss this procedure in greater detail. To this purpose we will study the integral of f(x) within the interval $$[x_{i-1},x_{i+1}]$$ and expand the integrand around the midpoint x i :

(3.20)

Inserting Eq. (2.​34) for f i ″ yields

(3.21)

Note that in contrast to the trapezoidal rule, the procedure described here is a three point method since the function values at three different points enter the expression. We can immediately write down the resulting integral from a to b. Since,

(3.22)

where we assumed that N is even and employed the discretization $$x_{i} = x_{0} + ih$$ with x ₀ = a and x N  = b. We obtain:

(3.23)

This expression is exact for polynomials of degree n ≤ 3 since the first term in the error expansion involves the fourth derivative. Hence, whenever the integrand is satisfactorily reproduceable by a polynomial of degree three or less, the Simpson rule might give almost exact estimates, independent of the discretization h.

The arguments applied above allow for a straightforward extension to four- or even more-point rules. We find, for instance,

(3.24)

which is usually called Simpson’s three-eight rule.

It is important to note that all the methods discussed so far are special cases of a more general formulation, the Newton-Cotes rules [2] which will be discussed in the next section.

3.5 General Formulation: The Newton-Cotes Rules

We define the Lagrange interpolating polynomial p n−1(x) of degree n − 1 [3–5] to a function f(x) as²

(3.25)

where

(3.26)

An arbitrary smooth function f(x) can then be expressed with the help of a Lagrange polynomial of degree n by

(3.27)

If we neglect the second term on the right hand side of this equation and integrate the Lagrange polynomial of degree n − 1 over the n grid-points from x ₁ to x n we obtain the closed n-point Newton-Cotes formulas. For instance, if we set n = 2, then

(3.28)

with $$f_{1} \equiv f(x_{1})$$ and $$f_{2} \equiv f(x_{2})$$. Integration over the respective interval yields

(3.29)

which is exactly the trapezoidal rule . By setting n = 3 one obtains Simpson’s rule and setting n = 4 gives the Simpson’s three-eight rule .

The open Newton-Cotes rule can be obtained by integrating the polynomial $$p_{n-1}(x)$$ of degree n − 1 which includes the grid-points $$x_{1},\ldots,x_{n}$$ from x ₀ to $$x_{n+1}$$. The fact that these relations are open means that the function values at the boundary points $$x_{0} = x_{1} - h$$ and $$x_{n+1} = x_{n} + h$$ do not enter the final expressions. The simplest open Newton-Cotes formula is the central integral approximation which we encountered as the rectangular rule (3.14). A second order approximation is easily found with help of the two-point Lagrange polynomial (3.28)

(3.30)

Higher order approximations can be obtained in a similar fashion. To conclude this section let us briefly discuss an idea which is referred to as Romberg’s method [6].

So far, we approximated all integrals by expressions of the form

(3.31)

where I is the exact, unknown, value of the integral, $$\mathcal{I}^{N}$$ is the estimate obtained from an integration scheme using N grid-points, and m is the leading order of the error. Let us review the error of the trapezoidal approximation: we learned that the error for the integral over the interval $$[x_{i},x_{i+1}]$$ scales like h ³. Since we have N such intervals, we conclude that the total error behaves like (b − a)h ². Similarly, the error of the three-point Simpson rule is for each sub-interval proportional to h ⁵ and this gives in total (b − a)h ⁴. We assume that this trend can be generalized and conclude that the error of an n-point method with the estimate $$\mathcal{I}_{n}$$ behaves like h 2n−2. Since, $$h \propto N^{-1}$$ we have

(3.32)

where C N depends on the number of grid-points N. Let us double the amount of grid-points and we obtain:

(3.33)

Obviously, Eqs. (3.32) and (3.33) can be regarded as a linear system of equations in I and C if $$C_{N} \approx C_{2N} \approx C$$. Solving Eqs. (3.32) and (3.33) for I yields

(3.34)

It has to be emphasized that in the above expression I is no longer the exact value because of the approximation C N  ≈ C. However, it is an improvement of the solution and it is possible to demonstrate that this new estimate is exactly the value one would have obtained with an integral approximation of order n + 1 and 2N grid-points! Thus

(3.35)

This suggests a very elegant and rapid procedure: We simply calculate the integrals using two point rules and add the results according to Eq. (3.35) to obtain more-point results. For instance, calculate $$\mathcal{I}_{2}^{2}$$ and $$\mathcal{I}_{2}^{4}$$, add these according to Eq. (3.35) and get $$\mathcal{I}_{3}^{4}$$. Now calculate $$\mathcal{I}_{2}^{8}$$, add $$\mathcal{I}_{2}^{4}$$,

get $$\mathcal{I}_{3}^{8}$$, add $$\mathcal{I}_{3}^{4}$$ and get $$\mathcal{I}_{4}^{8}$$. This pyramid-like procedure can be continued until convergence is achieved, that is $$\vert \mathcal{I}_{m}^{N} -\mathcal{I}_{m+1}^{N}\vert &lt;\epsilon$$ where ε > 0 can be chosen arbitrarily. An illustration of this method is given in Fig. 3.4.

Fig. 3.4

Illustration of the Romberg method. Here, the $$\mathcal{I}(m,n)$$ are synonyms for integrals $$\mathcal{I}_{m}^{n}$$ where the first index m refers to the order of the quadrature while the second index n refers to the number of grid-points used. Note that we only have to use a second order integration scheme (left row inside the box), all other values are determined via Eq. (3.35) as indicated by the arrows

3.6 Gauss-Legendre Quadrature

In preparation for the Gauss-Legendre quadrature we introduce a set of orthogonal Legendre polynomials P ℓ (x) [3, 4, 7, 8] which are solutions of the Legendre differential equation

(3.36)

This equation occurs, for instance, when the Laplace equation $$\varDelta f(x) = 0$$ is transformed to spherical coordinates. Here, we will introduce the most important properties of Legendre polynomials which will be required for an understanding of the Gauss-Legendre quadrature.

Legendre polynomials are given by

(3.37)

where the coefficients $$a_{k,\ell}$$ can be determined recursively:

(3.38)

Hence, for even values of ℓ the Legendre polynomial involves only even powers of x and for odd $$\ell$$ only odd powers of x. Note also that according to Eq. (3.38) for k ≥ ℓ the coefficients are equal to zero and, thus, it follows from Eq. (3.37) that the $$P_{\ell}(x)$$ are polynomials of degree $$\ell$$. Furthermore, the Legendre polynomials fulfill the orthonomality condition

(3.39)

where $$\delta _{ij}$$ is Kronecker’s delta. One obtains, in particular,

(3.40)

and

(3.41)

Another convenient way to calculate Legendre polynomials is based on Rodrigues’ formula

(3.42)

We focus now on the core of the Gauss-Legendre quadrature and introduce the function F(x) as a transform of the function f(x)

(3.43)

in such a way that we can rewrite the integral of interest as:

(3.44)

If the function F(x) can be well approximated by some polynomial of degree 2n − 1, like

(3.45)

then this means that according to Taylor’s theorem (2.​7) the error introduced by this approximation is proportional to F (2n)(x). If the polynomial p 2n−1(x) is explicitly given then we can apply the methods discussed in the previous sections to approximate the integral (3.44). However, even if the polynomial is not explicitly given we write the integral (3.44) as

(3.46)

with weights ω i and grid-points x i , $$i = 1,\ldots,n$$ which are yet undetermined! Therefore, we will determine the weights ω i and grid-points x i in such a way, that the integral is well approximated even if the polynomial p 2n−1 in Eq. (3.45) is unknown. For this purpose we decompose p 2n−1(x) into

(3.47)

where P n (x) is the Legendre polynomial of degree n and p n−1(x) and q n−1(x) are polynomials of degree n − 1. Since p n−1(x) itself is a polynomial of degree n − 1, it can also be expanded in Legendre polynomials of degrees up to n − 1 by

(3.48)

Using Eq. (3.48) in (3.47) we obtain together with normalization relation (3.39)

(3.49)

Moreover, since $$P_{n}(x)$$ is a Legendre polynomial of degree n it has n-zeros in the interval [−1, 1] and Eq. (3.47) results in

(3.50)

where $$x_{1},x_{2},\ldots,x_{n}$$ denote the zeros of P n (x) and these zeros determine the grid-points of our integration routine. It is interesting to note, that these zeros are independent of the function F(x) we want to integrate. We also expand $$q_{n-1}(x)$$ in terms of Legendre polynomials

(3.51)

and use it in Eq. (3.50) to obtain

(3.52)

which can be written in a more compact form by defining $$p_{i} \equiv p_{2n-1}(x_{i})$$ and $$P_{ki} \equiv P_{k}(x_{i})$$:

(3.53)

It has to be emphasized again that the grid-points x i are independent of the polynomial p 2n−1(x) and, therefore, independent of F(x). Furthermore, we can replace $$p_{i} \approx F(x_{i}) \equiv F_{i}$$ according to Eq. (3.45). We recognize that Eq. (3.53) corresponds to a system of linear equations which can be solved for the weights b k . We obtain

(3.54)

where P is the matrix $$\mathbf{P} =\{ P_{ij}\}$$, which is known to be non-singular. We can now rewrite the integral (3.44) with the help of Eqs. (3.45), (3.49), and (3.51) together with the properties of the zeros of Legendre polynomials [7, 8] as

(3.55)

Since P ₀(x) = 1 according to Eq. (3.40), we deduce from Eq. (3.39)

(3.56)

Hence, Eq. (3.55) reads

(3.57)

By defining

(3.58)

we arrive at the desired expansion

(3.59)

Moreover, since we approximated F(x) by a polynomial of degree 2n − 1, the Gauss-Legendre quadrature is exact for polynomials of degree 2n − 1, i.e. the error is proportional to a derivative of F(x) of order 2n. Furthermore, expression (3.58) can be put in a more convenient form. One can show that

(3.60)

where

(3.61)

Let us make some concluding remarks. The grid-points x i as well as the weights ω i are independent of the actual function F(x) we want to integrate. This means, that one can table these values once and for all [7, 8] and use them for different types of problems. The grid-points x i are symmetrically distributed around the point x = 0, i.e. for every x j there is a $$-x_{j}$$. Furthermore, these two grid-points have the same weight $$\omega _{j}$$. The density of grid-points increases approaching the boundary, however, the boundary points themselves are not included, which means that the Gauss-Legendre quadrature is an open method. Furthermore, it has to be emphasized that low order Gauss-Legendre parameters can easily be calculated by employing relation (3.42). This makes the Gauss-Legendre quadrature the predominant integration method. In comparison to the trapezoidal rule or even the Romberg method, it needs in many cases a smaller number of grid-points, is simpler to implement, converges faster and yields more accurate results. One drawback of this method is that one has to compute the function F(x) at the zeros of the Legendre polynomial x i . This can be a problem if the integrand at hand is not known analytically.

It is important to note at this point that comparable procedures exist which use other types of orthogonal polynomials, such as Hermite polynomials. This procedure is known as the Gauss-Hermite quadrature.

Table 3.1 lists the methods, discussed in the previous sections, which allow to calculate numerically an estimate of integrals of the form:

(3.62)

Equal grid-spacing h is assumed, with the Gauss-Legendre method as the only exception. The particular value of h depends on the order of the method employed and is given in Table 3.1.

Table 3.1

Summary of the quadrature methods discussed in this chapter applied to the integral $$\int _{a}^{b}\mathrm{d}xf(x)$$. For a detailed description consult the corresponding sections. Equal grid-spacing is assumed for all methods except for the Gauss-Legendre quadrature. The explicit values of h depend on the order of the method and are listed in the table. Furthermore, we use $$x_{i} = a + ih$$ and denote $$f(x_{i}) = f_{i}$$. The function P (m)(x) which appears in the description of the Newton-Cotes rules denotes the m-th order Lagrange interpolating polynomial and P m (x) is the m-th degree Legendre polynomial

n

h

Method

Comment

1

hf ₁

Rectangular

Open

2

b − a

Trapezoidal

Closed

3

Simpson

Closed

4

Simpson $$\frac{3} {8}$$

Closed

m

Newton-Cotes

Closed

m

Newton-Cotes

Open

m

P m (x j ) = 0

Gauss-Legendre

Open

3.7 An Example

Let us discuss as an example the following proper integral:

(3.63)

We will now apply the various methods of Table 3.1 to approximate Eq. (3.63). Note that these methods could give better results if a finer grid had been chosen. However, since this is only an illustrative example, we wanted to keep it as simple as possible. The rectangular rule gives

(3.64)

the trapezoidal rule

(3.65)

and an application of the Simpson rule yields

(3.66)

Finally, we apply the Gauss-Legendre quadrature in a second order approximation. We could look up the parameters in [7, 8], however, for illustrative reasons we will calculate those in this simple case. For a second order approximation we need the Legendre polynomial of second degree. It can be obtained from Rodrigues’ formula (3.42):

(3.67)

In a next step the zeros x ₁ and x ₂ of P ₂(x) are determined from Eq. (3.67) which results immediately in:

(3.68)

The weights ω ₁ and ω ₂ can now be evaluated according to Eq. (3.60):

(3.69)

It follows from Eq. (3.67) that

(3.70)

and, thus,

(3.71)

This is used to calculate the weights from Eq. (3.69):

(3.72)

We combine the results (3.68) and (3.72) to arrive at the Gauss-Legendre estimate of the integral (3.63):

(3.73)

Obviously, a second order Gauss-Legendre approximation results already in a much better estimate of the integral (3.63) than the trapezoidal rule which is also of second order. It is also better than the estimate by the Simpson rule which is of third order.

3.8 Concluding Discussion

Let us briefly discuss some further aspects of numerical integration. In many cases one is confronted with improper integrals of the form

(3.74)

The question arises whether or not we can treat such an integral with the methods discussed so far. The answer is yes, it is possible as we will demonstrate using the integral

(3.75)

as an example; other integrals can be treated in a similar fashion. We rewrite Eq. (3.75) as

(3.76)

One now calculates I(b ₁) for some b ₁ > a and I(b ₂) for some $$b_{2} &gt; b_{1}$$. If $$\vert I(b_{2}) - I(b_{1})\vert &lt;\epsilon$$, where ε > 0 is the required accuracy, the resulting value I(b ₂) can be regarded as the appropriate estimate to I.³ However, in many cases it is easier to perform an integral transform in order to map the infinite interval onto a finite interval. For instance, consider [9]

(3.77)

The transformation

(3.78)

gives

(3.79)

Thus, we mapped the interval $$[0,\infty ) \rightarrow [0,1]$$. Integral (3.79) can now be approximated with help of the methods discussed in the previous sections. These can also be applied to approximate convergent integrals whose integrand shows singular behavior within [a, b].

If the integrand f(x) is not smooth within the interval I: x ∈ [a, b] we can split the total integral into a sum over sub-intervals. For instance, if we consider the function

we can calculate the integral over the interval $$I: x \in [-10,10]$$ as

We generalize this result and write

(3.80)

with sub-intervals $$I_{k} \in I,\forall k$$ and the integrand f(x) is assumed to be smooth within each sub-interval I k but not necessarily within the interval I. We can then apply one of the methods discussed in this chapter to calculate an estimate of the integral over any of the sub-intervals I k .

Similar to the discussion in Sect. 2.​5 about the approximation of partial derivatives on the basis of finite differences, one can apply the rules of quadrature developed here for different dimensions to obtain an estimate of multi-dimensional integrals. However, the complexity of the problem is significantly increased if the integration boundaries are functions of the variables rather than constants. For instance,

(3.81)

Such cases are rather difficult to handle and the method to choose depends highly on the form of the functions $$\varphi _{1}(x)$$, $$\varphi _{2}(x)$$ and f(x, y). We will not deal with integrals of this kind because this is beyond the scope of this book. The interested reader is referred to books by Dahlquist and Björk [10] and by Press et al. [11].

In a final remark we would like to point out that it can be of advantage to utilize the properties of Fourier transforms when integrals of the convolution type are to be approximated numerically (see Appendix D).

Summary

The starting point was the concept of finite differences (Sect. 2.​2). Based on this concept proper integrals over smooth functions f(x) were approximated by a sum over elemental areas with the elemental area defined as the area under f(x) between two consecutive grid-points. The simplest method, the rectangular rule, was based on forward/backward differences. It was a closed method, i.e. the functional values at the boundaries were included. On the other hand, a rectangular rule based on central differences was an open method, i.e. the functional values at the boundaries were not included. Application of the Taylor expansion (2.​7) revealed that the methodological error of the rectangular rule was of order $$\mathcal{O}(h^{2})$$. With the elemental area approximated by a trapezoid we arrived at the trapezoidal rule. It was a closed method and the methodological error was of order $$\mathcal{O}(h^{3})$$. The inclusion of higher order derivatives of f(x) allowed the derivation of the Simpson rules of quadrature. They resulted a remarkable reduction of the methodological error. A more general formulation of all these methods was based on the interpolation of the function f(x) using Lagrange interpolating polynomials of degree n and resulted in the class of Newton-Cotes rules. For various orders of n of the interpolating polynomial all the above rules were derived. Within this context a particularly useful method, the Romberg method, was discussed. By adding diligently only two-point rules the error of the numerical estimate of the integral has been made arbitrarily small. An even more general approach was offered by the Gauss-Legendre quadrature which used Legendre polynomials of degree ℓ to approximate the function f(x). The grid-points were defined by the zeros of the ℓ-th degree polynomial and the weights ω i in Eq. (3.1) were proportional to the square of the inverse first derivative of the polynomial. This method had the enormous advantage that the grid-points and weights were independent of the function f(x) and, thus, could be determined once and for all for any polynomial degree $$\ell$$. Error analysis proved that this method had the smallest methodological error.

Problems

We consider the interval $$I = [-5,5]$$ together with the functions g(x) and h(x):

We discretize the interval I by introducing N equally spaced grid-points. The corresponding N − 1 sub-intervals are denoted by I j , $$j = 1,\ldots N - 1$$. In the following we wish to calculate estimates of the integrals

Furthermore, we add a third integral of the form

to our discussion.

1.

Evaluate $$\mathcal{I}_{1}$$ with the help of the error function erf(x), which should be supplied by the environment you use as an intrinsic function. Note that the error function is defined as

(3.82)

Hence you should be able to express $$\mathcal{I}_{1}$$ in terms of erf(x).

2.

Calculate $$\mathcal{I}_{2}$$ and $$\mathcal{I}_{3}$$ analytically.

3.

In order to approximate $$\mathcal{I}_{1}$$, $$\mathcal{I}_{2}$$ and $$\mathcal{I}_{3}$$ with the help of the two second order methods we discussed in this chapter, employ the following strategy: First the integrals are rewritten as

where ⋅ is a placeholder for g(x), h(x) and h ²(x) and I i , $$i = 1,\ldots,N$$ are suitable intervals. In a second step the integrals are approximated with (i) the central rectangular rule and (ii) the trapezoidal rule.

4.

In addition, we approximate the integrals $$\mathcal{I}_{1}$$, $$\mathcal{I}_{2}$$ and $$\mathcal{I}_{3}$$ by employing Simpson’s rule for odd N. Here

is used as it was discussed in Sect. 3.4.

5.

Compare the results obtained with different algorithms and different numbers of grid-points, N. Plot the absolute and the relative error as a function of N.

6.

Approximate numerically the integral

7.

Calculate the integral over the function

within the intervals $$x \in [-10\pi,10\pi ]$$ and $$y \in [-10,10]$$ with the help of an approximation of your choice.

8.

Demonstrate numerically that the line integral over closed loops $$\mathcal{C}$$ of the function f(x, y) of the previous problem vanishes:

References

1.

Jordan, C.: Calculus of Finite Differences, 3rd edn. AMS Chelsea, Providence (1965)

2.

Ueberhuber, C.W.: Numerical Computation 2: Methods, Software and Analysis. Springer, Berlin/Heidelberg (1997)

3.

Mathai, A.M., Haubold, H.J.: Special Functions for Applied Scientists. Springer, Berlin/Heidelberg (2008)

4.

Beals, R., Wong, R.: Special Functions. Cambridge Studies in Advanced Mathematics. Cambridge University Press, Cambridge (2010)

5.

Fornberg, B.: A Practical Guide to Pseudospectral Methods. Cambridge Monographs on Applied and Computational Mathematics. Cambridge University Press, Cambridge (1999)

6.

Stoer, J., Bulirsch, R.: Introduction to Numerical Analysis, 2nd edn. Springer, Berlin/Heidelberg (1993)

7.

Abramovitz, M., Stegun, I.A. (eds.): Handbook of Mathemathical Functions. Dover, New York (1965)

8.

Olver, F.W.J., Lozier, D.W., Boisvert, R.F., Clark, C.W.: NIST Handbook of Mathematical Functions. Cambridge University Press, Cambridge (2010)

9.

Sormann, H.: Numerische Methoden in der Physik. Lecture Notes. Institute of Theoretical and Computational Physics, Graz University of Technology (2011)

10.

Dahlquist, G., Björk, Å.: Numerical Methods in Scientific Computing. Cambridge University Press, Cambridge (2008)

11.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)

Footnotes

1

In this context the intermediate position $$x_{i+1/2}$$ is understood as a true grid-point. If, on the other hand, the function value $$f_{i+1/2}$$ is approximated by $$\mu f_{i+1/2}$$, Eq. (2.​29), the method is referred to as the trapezoidal rule.

2

The Lagrange polynomial p n−1(x) to the function f(x) is the polynomial of degree n − 1 that satisfies the n equations $$p_{n-1}(x_{j}) = f(x_{j})$$ for $$j = 1,\ldots,n$$, where x j denotes arbitrary but distinct grid-points.

3

Particular care is required when dealing with periodic functions!

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_4

4. The Kepler Problem

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

4.1 Introduction

The Kepler problem [1–6] is certainly one of the most important problems in the history of physics and natural sciences in general. We will study this problem for several reasons: (i) it is a nice demonstration of the applicability of the methods introduced in the previous chapters, (ii) important concepts of the numerical treatment of ordinary differential equations can be introduced quite naturally, and (iii) it allows to revisit some of the most important aspects of classical mechanics.

The Kepler problem is a special case of the two-body problem which is discussed in Appendix A. Let us summarize the main results. We consider two point particles interacting via the rotationally symmetric two body potential U which is solely a function of the distance between the particles. The symmetries of this problem allow several simplifications: (i) The problem can be reduced to the two dimensional motion of a point particle with reduced mass m in the central potential U. (ii) By construction, the total energy E is conserved. (iii) The length $$\ell$$ of the angular momentum vector is also conserved because of the symmetry of the potential U. Due to this rotational symmetry it is a natural choice to describe the particle’s motion in polar coordinates $$(\rho,\varphi )$$.

The final differential equations which have to be solved are of the form

(4.1)

and

(4.2)

Here, one usually defines the effective potential

(4.3)

as the sum of the interaction potential and the centrifugal barrier $$U_{\mathrm{mom}}(\rho ) =\ell ^{2}/2m\rho ^{2}$$. Equation (4.2) can be transformed into an implicit equation for ρ

(4.4)

with $$\rho _{0} \equiv \rho (t_{0})$$ the initial condition at time t ₀. Furthermore, the angle $$\varphi$$ is related to the radius ρ by

(4.5)

with the initial condition $$\varphi _{0} \equiv \varphi (t_{0})$$.

The Kepler problem is defined by the gravitational interaction potential

(4.6)

For this case, we show in Fig. 4.1 schematically the effective potential (4.3) (solid black line), together with the gravitational potential U(ρ) (dashed-dotted line) and the centrifugal barrier U mom (dashed line). The gravitational potential (4.6) is now inserted into Eq. (4.5):

(4.7)

The substitution $$u = 1/\rho$$ simplifies Eq. (4.7) to

(4.8)

where the integration boundaries u ₁ and u ₂ are 1∕ρ ₀ and 1∕ρ, respectively. The integral can now be evaluated with the help of a simple substitution¹ and we obtain the angle $$\varphi$$ as a function of ρ:

(4.9)

This solution can conveniently be characterized by the introduction of two parameters, namely

(4.10)

and the eccentricity e

(4.11)

Hence, by neglecting the integration constant and setting $$\varphi _{0} = 0$$ we arrive at

(4.12)

as the final form of Eq. (4.9). It describes for e > 1 a hyperbola, for e = 1 a parabola, and for e < 1 an ellipse. The case e = 0 is a special case of the ellipse and describes a circle with radius ρ = a. A more detailed discussion of this result, in particular the derivation of Kepler’s laws can be found in any textbook on classical mechanics [1–6]. We discuss now some numerical aspects.

Fig. 4.1

Schematic illustration of the effective potential $$U_{\mathrm{eff}}(\rho )/U_{\mathrm{eff}}(\rho _{0})$$ vs ρ∕ρ ₀ (solid line, right hand scale). Here, ρ ₀ is the distance of the minimum in $$U_{\mathrm{eff}}(\rho )$$. U grav(ρ) (dashed-dotted line) denotes the gravitational contribution while U mom(ρ) (dashed line) denotes the centrifugal barrier. Both potentials are normalized to U eff(ρ ₀) (Left hand scale applies)

4.2 Numerical Treatment

In the previous section we solved the Kepler problem by evaluating the integrand (4.7) expressing the angle $$\varphi$$ as a function of the radius ρ. However, in this section we aim at solving the integral equation (4.4) numerically with the help of the methods discussed in the previous chapter. Remember that Eq. (4.4) expresses the time t as a function of the radius ρ. This equation has to be inverted, in order to obtain ρ(t), which, in turn, is then inserted into Eq. (4.1) in order to determine the angle $$\varphi (t)$$ as a function of time. This discussion will lead us in a natural way to the most common techniques applied to solve ordinary differential equations, which is of no surprise since Eq. (4.4) is the integral representation of Eq. (4.2).

We give a short outline of what we plan to do: We discretize the time axis in equally spaced time steps $$\varDelta t$$, i.e. $$t_{n} = t_{0} + n\varDelta t$$. Accordingly, we define the radius ρ at time t = t n as $$\rho (t_{n}) \equiv \rho _{n}$$. We can use the methods introduced in Chap. 3 to approximate the integral (4.4) from some ρ n to ρ n+1. According to this chapter the absolute error introduced will behave like $$\delta =\vert \rho _{n} -\rho _{n+1}\vert ^{K}$$ where the explicit value of K depends on the method used. However, since the radius ρ changes continuously with time t we know that for sufficiently small values of $$\varDelta t$$ the error $$\delta$$ will also become arbitrarily small. If we start from some initial values t ₀ and ρ ₀, we can successively calculate the values $$\rho _{1}$$, ρ ₂, …, by applying a small time step $$\varDelta t$$.

Let us start by rewriting Eq. (4.4) as:

(4.13)

As we discretized the time axis in equally spaced increments and defined $$\rho _{n} \equiv \rho (t_{n})$$, we can rewrite (4.13) as

(4.14)

The forward rectangular rule , (3.​9), results in the approximation

(4.15)

We solve this equation for ρ n+1 and obtain

(4.16)

where we defined

(4.17)

following Eqs. (4.2) and (4.3). As Eq. (4.4) is the integral representation of the ordinary differential equation  (4.2), approximation (4.16) corresponds to the approximation

(4.18)

where D ₊ ρ n is the forward difference derivative  (2.10a). Since the left hand side of the discretized differential equation (4.18) is independent of ρ n+1, this method is referred to as an explicit method. In particular, consider an ordinary differential equation of the form

(4.19)

Then the approximation method is referred to as an explicit Euler method if it is of the form

(4.20)

Note that y might be a vector.

Let us use the backward rectangular rule  (3.​10) to solve Eq. (4.14). We obtain

(4.21)

or equivalently

(4.22)

Again, this corresponds to an approximation of the differential equation (4.2) by

(4.23)

where $$D_{-}(\rho _{n+1})$$ is the backward difference derivative  (2.10b). In this case the quantity of interest ρ n+1 still appears in the argument of the function $$h(\rho )$$ and Eq. (4.22) is an implicit equation for $$\rho _{n+1}$$ which has to be solved. In general, if the problem (4.19) is approximated by an algorithm of the form

(4.24)

it is referred to as an implicit Euler method. Note that the implicit equation (4.24) might be analytically unsolvable. Hence, one has to employ a numerical method to solve (4.24) which will also imply a numerical error. However, in the particular case of Eq. (4.22) we can solve it analytically since it is a fourth order polynomial in $$\rho _{n+1}$$ of the form

(4.25)

The solution of this equation is quite tedious and will not be discussed here, however, the method one employs is referred to as Ferrari’s method [7].

A natural way to proceed is to regard the central rectangular rule (3.​13) in a next step. Within this approximation we obtain for Eq. (4.13)

(4.26)

which is equivalent to the implicit equation

(4.27)

It can be written as an approximation to Eq. (4.2) with help of the central difference derivative $$D_{c}\rho _{n+\frac{1} {2} }$$:

(4.28)

In general, for a problem of the form (4.19) a method of the form

(4.29)

is referred to as the implicit midpoint rule . We note that this method might be more accurate since the error of the rectangular rule scales like $$\mathcal{O}(\varDelta t^{2})$$ while the error of the forward and backward rectangular rules scale like $$\mathcal{O}(\varDelta t)$$. Nevertheless, in case of the Kepler problem, one can solve the implicit equation (4.27) analytically for $$\rho _{n+1}$$ which is certainly of advantage.

In this chapter the Kepler problem was instrumental in introducing three common methods which can be employed to solve numerically ordinary differential equations of the form (4.19). More general and advanced methods to solve ordinary differential equations and a more systematic description of these methods will be offered in the next chapter.

However, let us discuss another point before proceeding to the chapter on the numerics of ordinary differential equations. As demonstrated in Sect. 1.​3 the approximation of the integral (4.4) involves a numerical error. What will be the consequence of this error? Since we demonstrated that the approximations we discussed result in a differential equation in finite difference form, i.e. Eqs. (4.18), (4.23), and (4.27), we know that the derivative $$\dot{\rho }$$ will exhibit an error. Consequently, energy conservation [see Appendix A, Eq. (A.27)] will be violated with the implication that deviations from the trajectory (4.12) can be expected. This is definitely not desirable.

A solution is provided by a special class of methods, known as symplectic integrators , which were specifically designed for such cases. They are based on a formulation of the problem using Hamilton’s equations of motion. (See, for instance, Refs. [1–5].) In the particular case of the Kepler problem the Hamilton function is equivalent to the total energy of the system and reads (in some scaled units):

(4.30)

Here $$p = (p_{1},p_{2})$$ are the generalized momentum coordinates of the point particle in the two-dimensional plane and $$(q_{1},q_{2})$$ are the generalized position coordinates. From this Hamilton’s equations of motion

(4.31)

follow, where the functions a(q, p) and b(q, p) have been introduced for a more convenient notation. Note that these functions are two dimensional vectors in the case of Kepler’s problem. The so called symplectic Euler method is given by

(4.32)

Obviously, the first equation is explicit while the second is implicit. An alternative formulation reads

(4.33)

where the first equation is implicit and the second equation is explicit. Of course, Eq. (4.31) may be solved with the help of the explicit Euler method (4.20), the implicit Euler method (4.24) or the implicit midpoint rule (4.29). The solution should be equivalent to solving Eq. (4.4) with the respective method and then calculating (4.1) successively. Again, a more systematic discussion of symplectic integrators can be found in the following chapters.

Let us conclude this chapter with a final remark. We decided to solve Eqs. (4.4) and (4.1) because we wanted to reproduce the dynamics of the system, i.e. we wanted to obtain ρ(t) and $$\varphi (t)$$. This directed us to the numerical solution of two integrals. If we wanted to employ symplectic methods, which provide several advantages, we would have to solve four differential equations (4.31) instead of two integrals. Moreover, if we are not interested in the time evolution of the system but in the form of the trajectory in general, we could simply evaluate the integral (4.5) analytically or, if an analytical solution is not feasible for the potential U(ρ) one is interested in, numerically. Methods to approximate such an integral were extensively discussed in Chap. 3.

Summary

Kepler’s two-body problem was used as an incentive to introduce intuitively numerical methods to solve ordinary first order differential equations. To serve this purpose the basic differential equations were transformed into integral form. These integrals were then solved with the help of the rules discussed in Sect. 3.​2 Three basic methods have been identified, namely the explicit Euler method (based on the forward difference derivative), the implicit Euler method (based on the backward difference derivative), and the explicit midpoint rule (based on the central rectangular rule). Shortcomings of such methods have been discussed briefly as were remedies to overcome these.

Problems

1.

Planetary-Orbits: Apply the methods of numerical integration to the integral (4.4) and compare it to the analytical result. Identify the three different cases of elliptic, parabolic or hyperbolic orbits by varying the initial conditions.

2.

Lennard-Jones Scattering: Consider the scattering of two point particles which interact via the Lennard-Jones potential $$U(r) = 4\sigma [(\varepsilon /r)^{12} - (\varepsilon /r)^{6}]$$ with $$\sigma,\varepsilon &gt; 0$$ (see Chapter 7). Calculate the orbit $$\varphi (\rho )$$.

3.

Harmonic-Motion: Consider the motion of a point particle in the radial harmonic oscillator $$U(\rho ) = m\omega ^{2}\rho ^{2}/2$$. According to Bertrand’s theorem (see Refs. [1–3]) the particle’s trajectories should be closed orbits. Demonstrate this numerically as well as analytically.

References

1.

Arnol’d, V.I.: Mathematical Methods of Classical Mechanics, 2nd edn. Graduate Texts in Mathematics, vol. 60. Springer, Berlin/Heidelberg (1989)

2.

Fetter, A.L., Walecka, J.D.: Theoretical Mechanics of Particles and Continua. Dover, New York (2004)

3.

Scheck, F.: Mechanics, 5th edn. Springer, Berlin/Heidelberg (2010)

4.

Goldstein, H., Poole, C., Safko, J.: Classical Mechanics, 3rd edn. Addison-Wesley, Menlo Park (2013)

5.

Fließbach, T.: Mechanik, 7th edn. Lehrbuch zur Theoretischen Physik I. Springer, Berlin/Heidelberg (2015)

6.

Ó’Mathúna, D.: Integrable Systems in Celestial Mechanics. Progress in Mathematical Physics, vol. 51. Birkhäuser Basel, Basel (2008)

7.

Clark, A.: Elements of Abstract Algebra. Dover, New York (1971)

Footnotes

1

In particular, we substitute

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_5

5. Ordinary Differential Equations: Initial Value Problems

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

5.1 Introduction

This chapter introduces common numeric methods designed to solve initial value problems. The discussion of the Kepler problem in the previous chapter allowed the introduction of three concepts, namely the implicit Euler method, the explicit Euler method, and the implicit midpoint rule. Furthermore, we mentioned the symplectic Euler method. In this chapter we plan to put these methods into a more general context and to discuss more advanced techniques.

Let us define the problem: We consider initial value problems of the form

(5.1)

where y(t) ≡ y is an n-dimensional vector and y ₀ is referred to as the initial value of y. Some remarks about the form of Eq. (5.1) are required:

(i)

We note that by posing Eq. (5.1), we assume that the differential equation is explicit in $$\dot{y}$$, i.e. initial value problems of the form

(5.2)

are only considered if $$G(\dot{y})$$ is analytically invertible. For instance, we will not deal with differential equations of the form

(5.3)

(ii)

We note that Eq. (5.1) is a first order differential equation in y. However, this is in fact not a restriction since we can transform every explicit differential equation of order n into a coupled set of explicit first order differential equations. Let us demonstrate this. We regard an explicit differential equation of the form

(5.4)

where we defined $$y^{(k)} \equiv \frac{\mathrm{d}^{k}} {\mathrm{d}t^{k}}y$$. This equation is equivalent to the set

(5.5)

which can be written as Eq. (5.1). Hence, we can attenuate the criterion discussed in point (i), that the differential equation has to be explicit in $$\dot{y}$$, to the criterion that the differential equation of order n has to be explicit in the n-th derivative of y, namely y (n).

There is another point required to be discussed before moving on. The numerical treatment of initial value problems is of eminent importance in physics because many differential equations, which appear unspectacular at first glance, cannot be solved analytically. For instance, consider a first order differential equation of the type:

(5.6)

Although this equation appears to be simple, one has to rely on numerical methods to obtain a solution. However, Eq. (5.6) is not well posed since the solution is ambiguous as long as no initial values are given. A numerical solution is only possible if the problem is completely defined. In many cases, one uses numerical methods although the problem is solvable with the help of analytic methods, simply because the solution would be too complicated. A numerical approach might be justified, however, one should always remember that, quote [1]:

Numerical methods are no excuse for poor analysis.

This chapter will be augmented by a chapter on the double pendulum, which will serve as a demonstration of the applicability of Runge-Kutta methods and by a chapter on molecular dynamics which will demonstrate the applicability of the leap-frog algorithm.

5.2 Simple Integrators

We start by reintroducing the methods already discussed in the previous chapter. Again, we discretize the time coordinate t via the relation $$t_{n} = t_{0} + n\varDelta t$$ and define f n  ≡ f(t n ) accordingly. In the following we will refrain from noting the initial condition explicitly for a more compact notation. We investigate Eq. (5.1) at some particular time t n :

(5.7)

Integrating both sides of (5.7) over the interval [t n , t n+1] gives

(5.8)

Note that Eq. (5.8) is exact and it will be our starting point in the discussion of several paths to a numeric solution of initial value problems. These solutions will be based on an approximation of the integral on the right hand side of Eq. (5.8) with the help of the methods already discussed in Chap. 3

In the following we list four of the best known simple integration methods for initial value problems:

(1)

Applying the forward rectangular rule  (3.​9) to Eq. (5.8) yields

(5.9)

which is the explicit Euler method we encountered already in Sect. 4.​2 This method is also referred to as the forward Euler method . In accordance to the forward rectangular rule, the leading term of the error of this method is proportional to Δ t ² as was pointed out in Sect. 3.​2

(2)

We use the backward rectangular rule  (3.​10) in Eq. (5.8) and obtain

(5.10)

which is the implicit Euler method, also referred to as backward Euler method . As already highlighted in Sect. 4.​2, it may be necessary to solve Eq. (5.10) numerically for y n+1. (Some notes on the numeric solution of non-linear equations can be found in Appendix B.)

(3)

The central rectangular rule  (3.​13) approximates Eq. (5.8) by

(5.11)

and we rewrite this equation in the form:

(5.12)

This method is sometimes referred to as the leap-frog routine or Störmer-Verlet method . We will come back to this point in Chap. 7 Note that the approximation

(5.13)

in Eq. (5.11) gives the implicit midpoint rule as it was introduced in Sect. 4.​2

(4)

Employing the trapezoidal rule  (3.​15) in an approximation to Eq. (5.8) yields

(5.14)

This is an implicit method which has to be solved for y n+1. It is generally known as the Crank-Nicolson method [2] or simply as trapezoidal method .

Methods (1), (2), and (4) are also known as one-step methods, since only function values at times t n and t n+1 are used to propagate in time. In contrast, the leap-frog method is already a multi-step method since three different times appear in the expression. Basically, there are three different strategies to improve these rather simple methods:

Taylor series methods: Use more terms in the Taylor expansion of y n+1.

Linear Multi-Step methods: Use data from previous time steps y k , k < n in order to cancel terms in the truncation error .

Runge-Kutta method: Use intermediate points within one time step.

We will briefly discuss the first two alternatives and then turn our attention to the Runge-Kutta methods in the next section.

Taylor Series Methods

From Chap. 2 we are already familiar with the Taylor expansion (2.​7) of the function y n+1 around the point y n ,

(5.15)

We insert Eq. (5.7) into Eq. (5.15) and obtain

(5.16)

So far nothing has been gained since the truncation error is still proportional to Δ t ². However, calculating $$\ddot{y}_{n}$$ with the help of Eq. (5.7) gives

(5.17)

and this results together with Eq. (5.16) in:

(5.18)

This manipulation reduced the local truncation error to orders of Δ t ³. The derivatives of f(y n , t n ), f′(y n , t n ) and $$\dot{f}(y_{n},t_{n})$$ can be approximated with the help of the methods discussed in Chap. 2, if an analytic differentiation is not feasible. The above procedure can be repeated up to arbitrary order in the Taylor expansion (5.15).

Linear Multi-step Methods

A k-th order linear multi-step method is defined by the approximation

(5.19)

of Eq. (5.8). The coefficients a j and b j have to be determined in such a way that the local truncation error is reduced. Two of the best known techniques are the so called second order Adams-Bashford method

(5.20)

and the second order rule (backward differentiation formula)

(5.21)

(For details please consult Refs. [3–5].)

We note in passing that the backward differentiation formula of arbitrary order can easily be obtained with the help of the operator technique introduced in Sect. 2.​4, Eq. (2.​27). One simply inserts the backward difference series (2.​27) to arbitrary order into the right hand side of the differential equation (5.7).

In many cases, multi-step methods are based on the interpolation of previously computed values y k by Lagrange polynomials . This interpolation is then inserted into Eq. (5.8) and integrated. However, a detailed discussion of such procedures is beyond the scope of this book. The interested reader is referred to Refs. [6, 7].

Nevertheless, let us make one last point. We note that Eq. (5.19) is explicit for b ₀ = 0 and implicit for b ₀ ≠ 0. In many numerical realizations one combines implicit and explicit multi-step methods in such a way that the explicit result [solve Eq. (5.19) with b ₀ = 0] is used as a guess to solve the implicit equation [solve Eq. (5.19) with b ₀ ≠ 0]. Hence, the explicit method predicts the value y n+1 and the implicit method corrects it. Such methods yield very good results and are commonly referred to as predictor–corrector methods [8].

5.3 Runge-Kutta Methods

In contrast to linear multi-step methods, the idea in Runge-Kutta methods (see, for instance, Ref. [6]) is to improve the accuracy by calculating intermediate grid-points within the interval [t n , t n+1]. We note that the approximation (5.11) resulting from the central rectangular rule is already such a method since the function value $$y_{n+1/2}$$ at the grid-point $$t_{n+1/2} = t_{n} +\varDelta t/2$$ is taken into account. We investigate this in more detail and rewrite Eq. (5.11):

(5.22)

We now have to find appropriate approximations to $$y_{n+1/2}$$ which will increase the accuracy of Eq. (5.11). Our first choice is to replace $$y_{n+1/2}$$ with the help of the explicit Euler method, Eq. (5.9),

(5.23)

which, inserted into Eq. (5.22) yields

(5.24)

We note that Eq. (5.24) is referred to as the explicit midpoint rule. In analogy we could have approximated $$y_{n+1/2}$$ with the help of the averaged function value $$\mu y_{n+1/2}$$ which results in

(5.25)

This equation is referred to as the implicit midpoint rule. Let us explain how we obtain an estimate for the error in Eqs. (5.24) and (5.25). In case of Eq. (5.24) we investigate the term

The Taylor expansion of y n+1 and f(⋅ ) around the point Δ t = 0 yields

(5.26)

We observe that the first term cancels because of Eq. (5.7). Consequently, the error is of order Δ t ². A similar argument holds for Eq. (5.25).

Let us introduce a more convenient notation for the above examples before we concentrate on a more general topic. It is presented in algorithmic form, i.e. it defines the sequence in which one should calculate the various terms. This is convenient for two reasons, first of all it increases the readability of complex methods such as Eq. (5.25) and, secondly, it is easy to identify which part of the method involves an implicit step and which part has to be solved separately for the corresponding variable. For this purpose let us introduce variables Y i of some index i ≥ 1 and we use a simple example to illustrate this notation. Consider the explicit Euler method  (5.9). It can be written as

(5.27)

In a similar fashion we write the implicit Euler method  (5.10) as

(5.28)

It is understood that the first equation of (5.28) has to be solved for Y ₁ first and this result is then plugged into the second equation in order to obtain y n+1. One further example: the Crank-Nicolson  (5.14) method can be rewritten as

(5.29)

where the second equation is to be solved for Y ₂ in the second step.

In analogy, the algorithmic form of the explicit midpoint rule  (5.24) is defined as

(5.30)

and we find for the implicit midpoint rule (5.25):

(5.31)

The above algorithms are all examples of the so called Runge-Kutta methods. We introduce the general representation of a d-stage Runge-Kutta method:

(5.32)

We note that Eq. (5.32) it is completely determined by the coefficients a ij , b j and c j . In particular a = { a ij } is a d × d matrix, while b = { b j } and c = { c j } are d dimensional vectors.

Butcher tableaus are a very useful tool to characterize such methods. They provide a structured representation of the coefficient matrix a and the coefficient vectors b and c:

(5.33)

We note that the Runge-Kutta method (5.32) or (5.33) is explicit if the matrix a is zero on and above the diagonal, i.e. a ij  = 0 for j ≥ i. Let us rewrite all the methods described here in the form of Butcher tableaus:

Explicit Euler:

(5.34)

Implicit Euler:

(5.35)

Crank-Nicolson:

(5.36)

Explicit Midpoint:

(5.37)

Implicit Midpoint:

(5.38)

With the help of Runge-Kutta methods of the general form (5.32) one can develop methods of arbitrary accuracy. One of the most popular methods is the explicit four stage method (we will call it e-RK-4) which is defined by the algorithm:

(5.39)

This method is an analogue to the Simpson rule of numerical integration as discussed in Sect. 3.​4 However, a detailed compilation of the coefficient array a and coefficient vectors b, and c is quite complicated. A closer inspection reveals that the methodological error of this method behaves as Δ t ⁵. The algorithm e-RK-4, Eq. (5.39), is represented by a Butcher tableau of the form

(5.40)

Another quite popular method is given by the Butcher tableau

(5.41)

We note that this method is implicit and mention that it corresponds to the two point Gauss-Legendre quadrature of Sect. 3.​6

A further improvement of implicit Runge-Kutta methods can be achieved by choosing the Y i in such a way that they correspond to solutions of the differential equation (5.7) at intermediate time steps. The intermediate time steps at which one wants to reproduce the function are referred to as collocation points . At these points the functions are approximated by interpolation on the basis of Lagrange polynomials , which can easily be integrated analytically. However, the discussion of such collocation methods [8] is far beyond the scope of this book.

In general Runge-Kutta methods are very useful. However one always has to keep in mind that there could be better methods for the problem at hand. Let us close this section with a quote from the book by Press et al. [9]:

For many scientific users, fourth-order Runge-Kutta is not just the first word on ODE integrators, but the last word as well. In fact, you can get pretty far on this old workhorse, especially if you combine it with an adaptive step-size algorithm. Keep in mind, however, that the old workhorse’s last trip may well take you to the poorhouse: Bulirsch-Stoer or predictor-corrector methods can be very much more efficient for problems where high accuracy is a requirement. Those methods are the high-strung racehorses. Runge-Kutta is for ploughing the fields.

5.4 Hamiltonian Systems: Symplectic Integrators

Let us define a symplectic integrator as a numerical integration in which the mapping

(5.42)

is symplectic. Here Φ Δ t is referred to as the numerical flow of the method. If we regard the initial value problem (5.1) we can define in an analogous way the flow of the system $$\varphi _{t}$$ as

(5.43)

For instance, if we consider the initial value problem

(5.44)

where $$y \in \mathbb{R}^{n}$$ and $$A \in \mathbb{R}^{n\times n}$$, then the flow $$\varphi _{t}$$ of the system is given by:

(5.45)

On the other hand, if we regard two vectors $$v,w \in \mathbb{R}^{2}$$, we can express the area ω of the parallelogram spanned by these vectors as

(5.46)

where we put v = (a, b) T and w = (c, d) T . More generally, if $$v,w \in \mathbb{R}^{2d}$$, we have

(5.47)

where I is the d × d dimensional unity matrix. Hence (5.47) represents the sum of the projected areas of the form

(5.48)

If we regard a mapping $$M: \mathbb{R}^{2d}\mapsto \mathbb{R}^{2d}$$ and require that

(5.49)

i.e. the area is preserved, we obtain the condition that

(5.50)

which is equivalent to $$\det (M) = 1$$. Finally, a differentiable mapping $$f: \mathbb{R}^{2d}\mapsto \mathbb{R}^{2d}$$ is referred to as symplectic if the linear mapping f′(x) (Jacobi matrix) conserves ω for all $$x \in \mathbb{R}^{2d}$$. One can easily prove that the flow of Hamiltonian systems is symplectic, i.e. area preserving in phase space. Every Hamiltonian system is characterized by its Hamilton function H(p, q) and the corresponding Hamilton equations of motion [10–14]:

(5.51)

We define the flow of the system via

(5.52)

where

(5.53)

Hence we rewrite (5.51) as

(5.54)

and note that x ≡ x(t, x ₀) is a function of time and initial conditions. In a next step we define the Jacobian of the flow via

(5.55)

and calculate

(5.56)

Hence, P t is given by the solution of the equation

(5.57)

Symplecticity ensures that the area

(5.58)

which can be verified by calculating $$\frac{\mathrm{d}} {\mathrm{d}t}\left (P_{t}^{T}JP_{ t}\right )$$ where we keep in mind that $$J^{T} = -J$$. Hence,

(5.59)

even if the Hamilton function is not conserved. This means that the flow of a Hamiltonian system is symplectic, i.e. area preserving in phase space [10, 11, 13].

Since this conservation law is violated by methods like e-RK-4 or explicit Euler, one introduces so called symplectic integrators, which have been particularly designed as a remedy to this shortcoming. A detailed investigation of these techniques is far too engaged for this book. The interested reader is referred to Refs. [12, 15–17].

However, we provide a list of the most important integrators.

Symplectic Euler

(5.60a)

(5.60b)

Here a(p, q) = ∇ p H(p, q) and $$b(p,q) = -\nabla _{q}H(p,q)$$ have already been defined in Sect. 4.​2

Symplectic Runge-Kutta

It can be demonstrated that a Runge-Kutta method is symplectic if the coefficients fulfill

(5.61)

for all i, j [16, 18]. This is a property of the collocation methods based on Gauss points c i .

5.5 An Example: The Kepler Problem, Revisited

It has already been discussed in Sect. 4.​2 that the Hamilton function of this system takes on the form [19]

(5.62)

and Hamilton’s equations of motion read

(5.63a)

(5.63b)

(5.63c)

(5.63d)

We now introduce the time instances $$t_{n} = t_{0} + n\varDelta t$$ and define q i n  ≡ q i (t n ) and p i n  ≡ p i (t n ) for i = 1, 2. In the following we give the discretized recursion relation for three different methods, namely explicit Euler, implicit Euler, and symplectic Euler.

Explicit Euler

In case of the explicit Euler method we have simple recursion relations

(5.64a)

(5.64b)

(5.64c)

(5.64d)

Implicit Euler

We obtain the implicit equations

(5.65a)

(5.65b)

(5.65c)

(5.65d)

These implicit equations can be solved, for instance, by the use of the Newton method discussed in Appendix B.

Symplectic Euler

Employing Eqs. (5.60) gives

(5.66a)

(5.66b)

(5.66c)

(5.66d)

These implicit equations can be solved analytically and we obtain

(5.67a)

(5.67b)

(5.67c)

(5.67d)

A second possibility of the symplectic Euler is given by Eq. (4.​33). It reads

(5.68a)

(5.68b)

(5.68c)

(5.68d)

The trajectories calculated using these four methods are presented in Figs. 5.1 and 5.2, the time evolution of the total energy of the system is plotted in Fig. 5.3. The initial conditions were [16]

(5.69)

and

(5.70)

with e = 0. 6 which gives $$H = -1/2$$. Furthermore, we set Δ t = 0. 01 for the symplectic Euler methods and Δ t = 0. 005 for the forward and backward Euler methods in order to reduce the methodological error. The implicit equations were solved with help of the Newton method as discussed in Appendix B. The Jacobi matrix was calculated analytically, hence no methodological error enters because approximations of derivatives were unnecessary.

Fig. 5.1

Kepler trajectories in position space for the initial values defined in Eqs. (5.69) and (5.70). They are indicated by a solid square. Solutions have been generated (a) by the explicit Euler method (5.64), (b) by the implicit Euler method (5.65), (c) by the symplectic Euler method (5.67), and (d) by the symplectic Euler method (5.68)

Fig. 5.2

Kepler trajectories in momentum space for the initial values defined in Eqs. (5.69) and (5.70). They are indicated by a solid square. Solutions have been generated (a) by the explicit Euler method (5.64), (b) by the implicit Euler method (5.65), (c) by the symplectic Euler method (5.67), and (d) by the symplectic Euler method (5.68)

Fig. 5.3

Time evolution of the total energy H calculated with the help of the four methods discussed in the text. The initial values are given by Eqs. (5.69) and (5.70). Solutions have been generated (i) by the explicit Euler method (5.64) (dashed line), (ii) by the implicit Euler method (5.65) (dotted line), (iii) by the symplectic Euler method (5.67) (solid line), and (iv) by the symplectic Euler method (5.68) (dashed-dotted line)

According to theory [19] the q-space and p-space projections of the phase space trajectory are ellipses. Furthermore, energy and angular momentum are conserved. Thus, the numerical solutions of Hamilton’s equations of motion (5.63) should reflect these properties. Figures 5.1a, b and 5.2a, b present the results of the explicit Euler method, Eqs. (5.64), and the implicit Euler method, Eqs. (5.65), respectively. Obviously, the result does not agree with the theoretical expectation and the trajectories are open instead of closed. The reason for this behavior is the methodological error of the method which is accumulative and, thus, causes a violation of energy conservation . This violation becomes apparent in Fig. 5.3 where the total energy H(t) is plotted vs time t. Neither the explicit Euler method (dashed line) nor the implicit Euler method (short dashed line) conform to the requirement of energy conservation. We also see step-like structures of H(t). At the center of these steps an open diamond symbol and in the case of the implicit Euler method an additional open circle indicate the position in time of the perihelion of the point-mass (point of closest approach to the center of attraction). It is indicated by the same symbols in Fig. 5.1a, b. At this point the point-mass reaches its maximum velocity, the pericenter velocity, and it covers the biggest distances along its trajectory per time interval Δ t. Consequently, the methodological error is biggest in this part of the trajectory which manifests itself in those steps in H(t). As the point-mass moves ‘faster’ when the implicit Euler method is applied, again, the distances covered per time interval are greater than those covered by the point-mass in the explicit Euler method. Thus, it is not surprising that the error of the implicit Euler method is bigger as well when H(t) is determined.

These results are in strong contrast to the numerical solutions of Eqs. (5.63) obtained with the help of symplectic Euler methods which are presented in Figs. 5.1c, d and 5.2c, d. The trajectories are almost perfect ellipses for both symplectic methods which follow Eqs. (5.67) and (5.68). Moreover, the total energy H(t) (solid and dashed-dotted lines in Fig. 5.3) varies very little as a function of t. Deviations from the mean value can only be observed around the perihelion which is indicated by a solid square. Moreover, these deviations compensate because of the symplectic nature of the method. This demonstrates that symplectic integrators are the appropriate technique to solve the equations of motion of Hamiltonian systems.

Summary

We concentrated on numerical methods to solve the initial value problem of ordinary differential equations. The methods discussed here rely heavily on the various methods developed for numerical integration because we can always find an integral representation of this kind of equations. The simple integrators known from Chap. 4 were augmented by the more general Crank-Nicholson method which was based on the trapezoidal rule introduced in Sect. 3.​3 The simple single-step methods were improved in their methodological error by Taylor series methods, linear multi-step methods, and by the Runge-Kutta method. The latter took intermediate points within the time interval [t n , t n+1] into account. In principle, it is possible to achieve almost arbitrary accuracy with such a method. Nevertheless, all those methods had the disadvantage that because of their methodological error energy conservation was violated when applied to Hamiltonian systems. As this problem can be remedied by symplectic integrators a short introduction into this topic was provided and the most important symplectic integrators were presented. The final discussion of Kepler’s two-body problem elucidated the various points discussed throughout this chapter.

Problems

1.

Write a program to solve numerically the Kepler problem. The Hamilton function of the problem is defined as

and the initial conditions are given by

where e = 0. 6. Derive Hamilton’s equations of motion and implement an algorithm which solves these equations based on the following methods

(a)

Explicit Euler,

(b)

Symplectic Euler.

2.

Plot the trajectories and the total energy as a function of time. You can use the results presented in Figs. 5.1 and 5.2 to check your code. Modify the initial conditions and discuss the results! Try to confirm Kepler’s laws of planetary motion with the help of your algorithm.

3.

Use a symplectic integrator to study Lennard-Jones scattering; see Problems of Chap. 4

4.

Solve the differential equation (5.6) numerically with different methods. Use also the Taylor series method (5.18).

References

1.

Dorn, W.S., McCracken, D.D.: Numerical Methods with Fortran IV Case Studies. Wiley, New York (1972)MATH

2.

Crank, J., Nicolson, P.: A practical method for numerical evaluation of solutions of partial differential equations of the heat-conduction type. Proc. Camb. Philos. Soc. 43, 50–67 (1947). doi:10.1017/S0305004100023197ADSMathSciNetCrossrefMATH

3.

Hairer, E., Wanner, G.: Solving Ordinary Differential Equations II. Springer Series in Computational Mathematics, vol. 14. Springer, Berlin/Heidelberg (1991)

4.

Hairer, E., Nørsett, S.P., Wanner, G.: Solving Ordinary Differential Equations I, 2nd edn. Springer Series in Computational Mathematics, vol. 8. Springer, Berlin/Heidelberg (1993)

5.

Süli, E., Mayers, D.: An Introduction to Numerical Analysis. Cambridge University Press, Cambridge (2003)CrossrefMATH

6.

Collatz, L.: The Numerical Treatment of Differential Equations. Springer, Berlin/Heidelberg (1960)CrossrefMATH

7.

van Winckel, G.: Numerical methods for differential equations. Lecture Notes, Karl-Franzens Universität Graz (2012)

8.

Ascher, U.M., Petzold, L.R.: Computer Methods for Ordinary Differential Equations and Differential-Algebraic Equations. Society for Industrial and Applied Mathematics, Philadelphia (1998)CrossrefMATH

9.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)MATH

10.

Arnol’d, V.I.: Mathematical Methods of Classical Mechanics, 2nd edn. Graduate Texts in Mathematics, vol. 60. Springer, Berlin/Heidelberg (1989)

11.

Fetter, A.L., Walecka, J.D.: Theoretical Mechanics of Particles and Continua. Dover, New York (2004)MATH

12.

Scheck, F.: Mechanics, 5th edn. Springer, Berlin/Heidelberg (2010)CrossrefMATH

13.

Goldstein, H., Poole, C., Safko, J.: Classical Mechanics, 3rd edn. Addison-Wesley, Menlo Park (2013)MATH

14.

Fließbach, T.: Mechanik, 7th edn. Lehrbuch zur Theoretischen Physik I. Springer, Berlin/Heidelberg (2015)MATH

15.

Guillemin, V., Sternberg, S.: Symplectic Techniques in Physics. Cambridge University Press, Cambridge (1990)MATH

16.

Hairer, E.: Geometrical Integration – Symplectic Integrators. Lecture Notes, TU München (2010)

17.

Levi, D., Oliver, P., Thomova, Z., Winteritz, P. (eds.): Symmetries and Integrability of Difference Equations. London Mathematical Society Lecture Note Series. Cambridge University Press, Cambridge (2011)

18.

Feng, K., Qin, M.: Symplectic Runge-Kutta methods. In: Feng, K., Qin, M. (eds.) Symplectic Geometric Algorithms for Hamiltonian Systems, pp. 277–364. Springer, Berlin/Heidelberg (2010)Crossref

19.

Ó’Mathúna, D.: Integrable Systems in Celestial Mechanics. Progress in Mathematical Physics, vol. 51. Birkhäuser Basel, Basel (2008)

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_6

6. The Double Pendulum

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

6.1 Hamilton’s Equations

We investigate the dynamics of the double pendulum in two spacial dimensions as illustrated schematically in Fig. 6.1. It is the aim of this section to derive Hamilton’s equations of motion for this system. In a first step we introduce generalized coordinates and determine the Lagrange function of the system from its kinetic and potential energy [1–5]. We then introduce generalized momenta and, finally, derive the Hamilton function from which Hamilton’s equations of motion follow. They will serve as a starting point for the formulation of a numerical method.

Fig. 6.1

Schematic illustration of the double pendulum. m are the point-masses, 2ℓ is the total length of the pendulum and $$\varphi _{1}$$, $$\varphi _{2}$$ are the corresponding angles

From Fig. 6.1 we find the coordinates of the two point masses m:

(6.1)

and

(6.2)

Here, 2ℓ is the pendulum’s total length. The angles $$\varphi _{i}$$, i = 1, 2 are defined in Fig. 6.1.

We note that ℓ = const and obtain the time derivatives of the coordinates (6.1) and (6.2):

(6.3)

(6.4)

(6.5)

(6.6)

The Lagrange function of the system is defined by

(6.7)

with the kinetic energy T and the potential U. The kinetic energy T is given by¹

(6.8)

The potential energy U is determined by the gravitational force

(6.9)

where g is the acceleration due to gravity. Hence, we get for the Lagrange function L:

(6.10)

We find a description of the motion in phase space by calculating the generalized momenta p i , i = 1, 2 as

(6.11)

and

(6.12)

The aim is now to express the kinetic energy (6.8) in terms of generalized momenta p ₁ and p ₂. To accomplish this we solve in a first step Eq. (6.12) for $$\dot{\varphi }_{2}$$ and obtain

(6.13)

This is used to rewrite Eq. (6.11). Solving for $$\dot{\varphi }_{1}$$ gives:

(6.14)

The trigonometric identity $$\cos ^{2}(x) +\sin ^{2}(x) = 1$$ changes Eq. (6.14) into

(6.15)

This is then used to transform Eq. (6.13) into

(6.16)

Hence, with help of Eqs. (6.15) and (6.16) we can reevaluate the kinetic energy  (6.8) to give

(6.17)

The Hamilton function $$H(p_{1},p_{2},\varphi _{1},\varphi _{2})$$ is the sum of the kinetic energy (6.17) and the potential energy (6.9) and we get:

(6.18)

Thus, we are now, finally, in a position to formulate Hamilton’s equations of motion from

(6.19)

and the dynamics of the double pendulum are determined by the solutions of the following set of differential equations:

(6.20a)

(6.20b)

(6.20c)

and

(6.20d)

The following section is dedicated to the numerical solution of Eqs. (6.20) with the help of the explicit Runge-Kutta algorithm e-RK-4 introduced in Sect. 5.​3

6.2 Numerical Solution

In a first step we recognize that Eqs. (6.20) are of the form

(6.21)

where $$y \in \mathbb{R}^{4}$$. Let us define

(6.22)

and consequently

(6.23)

We introduce time instances t n  = nΔt, $$n \in \mathbb{N}$$ and use the notation y n  ≡ y(t n ) = (y ₁ n , y ₂ n , y ₃ n , y ₄ n ) T . Furthermore, F(y) is not an explicit function of time t and we reformulate the e-RK-4 algorithm of Eq. (5.​39) as:

(6.24)

Hence, the only remaining challenge is to correctly implement the function $$F(y) = \left [\,f_{1}(y),f_{2}(y),f_{3}(y),f_{4}(y)\right ]^{T}$$ according to Eqs. (6.20).

The following graphs discuss the dynamics (trajectories in $$\varphi$$- and p-space, as well as in configuration space) of the pendulum and for this purpose we defined the parameters $$m =\ell= 1$$ and g = 9. 8067. The time step was chosen to be Δ t = 0. 001 and we calculated N = 60, 000 time steps.

We start with Fig. 6.2. The two masses numbered 1 and 2 are initially in

Fig. 6.2

Numerical solution of the double pendulum with initial conditions $$\varphi _{1}(0) =\varphi _{2}(0) = 0.0$$, p ₁(0) = 4. 0 and p ₂(0) = 2. 0. (a) Trajectory in $$\varphi$$-space, (b) trajectory in p-space, and (c) trajectory in local (x, z)-space. The solid circles numbered 1 and 2 represent the two masses in their initial configuration

the equilibrium position (solid circles). Both masses are pushed to the right but the push on mass 1 [p ₁(0) = 4. 0] is much stronger than the one mass 2 experiences [p ₂(0) = 2. 0]. Thus, mass 2 is ‘dragged’ along in the process. This is made transparent by two ‘snapshots’ indicated by solid light gray circles and solid gray circles. The motion of the whole system is quite regular.

We proceed with Fig. 6.3. In this case mass 1 is displaced from its

Fig. 6.3

Numerical solution of the double pendulum with initial conditions $$\varphi _{1}(0) = 1.0,\varphi _{2}(0) = 0.0$$, p ₁(0) = 0. 0 and p ₂(0) = 3. 0. (a) Trajectory in $$\varphi$$-space, (b) trajectory in p-space, and (c) trajectory in local (x, z)-space. The solid circles numbered 1 and 2 represent the two masses in their initial configuration

position by the initial angular displacement $$\varphi _{1} = 1.0$$. This initial configuration is indicated by the solid circles numbered 1 and 2 representing the two point-masses. Mass 2 is then pushed to the right with p ₂(0) = 3. 0. Again, mass 1 remains on a trajectory centered around the point (0, ​2) in configuration space. But in contrast to the previous situation it follows now mass 2. Mass 2, on the other hand, develops a very lively trajectory, Fig. 6.3c. Two snapshots indicated by solid light gray circles and solid gray circles illustrate configurations of particular interest.

The dynamics depicted in Fig. 6.4 is quite similar to the one already

Fig. 6.4

Numerical solution of the double pendulum with initial conditions $$\varphi _{1}(0) =\varphi _{2}(0) = 0.0$$, p ₁(0) = 0. 0 and p ₂(0) = 4. 0. (a) Trajectory in $$\varphi$$-space, (b) trajectory in p-space, and (c) trajectory in local (x, z)-space. The solid circles numbered 1 and 2 represent the two masses in their initial configuration

discussed in Fig. 6.2. Initially both masses are in the equilibrium position and then mass 2 is pushed to the right [p ₂(0) = 4. 0]. Thus, mass 1 is trailing behind. In contrast to the previous Fig. 6.3 the trajectory of mass 2 will now be symmetric around the z-axis given enough time. Again, snapshots indicated by solid light gray circles and solid gray circles indicate interesting configurations.

The initial condition which resulted in the trajectory shown in Fig. 6.5 differs only for mass 2 from the initial conditions which lead to the trajectory in Fig. 6.4.

Fig. 6.5

Numerical solution of the double pendulum with initial conditions $$\varphi _{1}(0) =\varphi _{2}(0) = 0.0$$, p ₁(0) = 0. 0 and p ₂(0) = 5. 0. (a) Trajectory in $$\varphi$$-space, (b) trajectory in p-space, and (c) trajectory in local (x, z)-space. The solid circles numbered 1 and 2 represent the two masses in their initial configuration (The angles $$\varphi _{2}&gt;\pi$$ correspond to complete rotations of the pendulum)

Mass 2 is now pushed even more strongly to the right [p ₂(0) = 5. 0]. Of course, mass 1 is again dragging behind mass 2. In contrast to Fig. 6.4 the initial momentum of mass 2 is now sufficient to allow mass 2 to pass through the center of the inner mass’ circular trajectory. Snapshots indicated by light gray solid circles and solid gray circles emphasize interesting configurations.

The situation shown in Fig. 6.6 differs from the one of Fig. 6.5

Fig. 6.6

Numerical solution of the double pendulum with initial conditions $$\varphi _{1}(0) =\varphi _{2}(0) = 0.0$$, p ₁(0) = 0. 0 and p ₂(0) = 6. 5. (a) Trajectory in $$\varphi$$-space, (b) trajectory in p-space, and (c) trajectory in configuration space. The solid circles numbered 1 and 2 represent the two masses in their initial configuration (The angles $$\varphi _{2}&gt;\pi$$ correspond to complete rotations of the pendulum)

only by the initial condition for mass 2. It is now pushed even more strongly to the right [p ₂(0) = 6. 5] and this initial momentum is sufficient to cause mass 1 to rotate around the point (0, ​2). Nevertheless, mass 1 is permanently dragging behind mass 2. Two interesting configurations are depicted by snapshots (solid light gray circles and solid gray circles).

A comparison between trajectories as a result of different initial conditions reveals that the physical system is highly sensitive to the choice of the initial conditions $$y_{0} = [\varphi _{1}(0),\varphi _{2}(0),p_{1}(0),p_{2}(0)]^{T}$$. For instance, consider Figs. 6.4, 6.5, and 6.6. In all three cases we chose y ₀ in such a way that the initial angles $$\varphi _{1}(0) =\varphi _{2}(0) = 0$$ and the generalized momentum coordinate p ₁(0) = 0. The only difference is that we used different values for the initial value of the second momentum coordinate p ₂. However, the resulting dynamics of $$\varphi _{1}$$ vs. $$\varphi _{2}$$ as well as p ₁ vs. p ₂ are entirely different and so are the local (x, z)-space trajectories. Hence, the system is chaotic . In the following section we will briefly discuss a method designed to characterize chaotic behavior of physical systems [6–10].

6.3 Numerical Analysis of Chaos

It is the aim of this section to analyze in more detail the chaotic behavior observed in the dynamics of the double pendulum. This requires the introduction of some basic notations. We consider a physical system with f degrees of freedom where q ₁(t), …, q f (t) denote the generalized coordinates and p ₁(t), …, p f (t) denote the corresponding generalized momenta. Together, both fully characterize the state of the system at time t. Consequently, the f-dimensional vector q(t) = [q ₁(t), q ₂(t), …, q f (t)] T describes a point in configuration space of the physical system. In case of a pendulum consisting of f point-masses connected in a similar fashion as the double pendulum discussed above, which corresponds to the particular case f = 2, the configuration space is constrained to values $$\varphi _{i} \in (-\pi,\pi ]$$, i = 1, …, f. This resembles an f-dimensional torus.

The 2f-dimensional vector x(t) = [q ₁(t), …, q f (t), p ₁(t), …, p f (t)] T describes a point in the phase space of the physical system at some particular time t. The time evolution of a physical system is represented by its phase space trajectory. Of course, the phase space trajectories x(t) are differentiable with respect to t.²

We define an autonomous system as a system which is time-invariant, i.e. the Hamilton function H(x, t) does not depend explicitly on time t, H(x, t) ≡ H(x). Hence, a physical system is referred to as autonomous if the Hamilton function H(x, t) of the system obeys

(6.25)

Thus, the total energy is conserved.

An autonomous system is referred to as integrable if it has f independent invariants I ₁, …, I f

(6.26)

One of these is the energy. Each particular invariant I j reduces the dimension of the manifold on which the phase space trajectories can propagate. Hence, an integrable system propagates on an f-dimensional subspace of the 2f-dimensional phase space. We note that a one-dimensional autonomous system is integrable since the conservation of energy delivers the required invariant.

On the other hand, non-integrable systems can show chaotic behavior. In this case the trajectories develop a strong dependence on the initial conditions which makes an analytic calculation of the dynamics extremely difficult. However, since the trajectories can be computed without problems by numeric means, we discuss now how to characterize chaotic behavior on the computer.

For this sake we investigate the dynamics of an autonomous Hamiltonian system starting with one of two initial conditions, namely x ₀ and x′₀. Then the system arrives at time t at the phase space points $$x(t) =\varphi _{t}(x_{0})$$ and $$x'(t) =\varphi _{t}(x'_{0})$$, respectively, as a solution of Hamilton’s equations of motion. Here $$\varphi _{t}(x_{0})$$ denotes the flow of the system as defined in Sect. 5.​4 Since the trajectories in a chaotic system strongly depend on the initial conditions x ₀ and x′₀ we introduce the separation between the two trajectories $$\varphi _{t}(x_{0})$$ and $$\varphi _{t}(x'_{0})$$ at time t as $$d(t) =\vert \varphi _{t}(x_{0}) -\varphi _{t}(x'_{0})\vert$$ where $$\vert \cdot \vert$$ denotes some suitable norm. This length can now, for instance, be used to characterize the stability of the trajectory $$\varphi _{t}(x_{0})$$ [11]. In particular, a solution $$\varphi _{t}(x_{0})$$ is referred to as stable if

(6.27)

In words: We speak of a stable solution if the trajectory $$\varphi _{t}(x_{0}')$$ which corresponds to the perturbed initial condition x ₀′ stays within a tube of radius ε around the unperturbed trajectory $$\varphi _{t}(x_{0})$$ for all t > 0. Alternatively, a solution is referred to as asymptotically stable if the distance to adjacent trajectories tends to zero, i.e. d(t) → 0 as $$t \rightarrow \infty$$. Such solutions tend to attract trajectories from their neighborhood and, hence, they are referred to as attractors. Finally, a periodic orbit is defined as a trajectory for which one can find a time τ such that:

(6.28)

To find an easy answer to the question whether or not a particular solution of a non-integrable system is stable, the clear, topological method of Poincaré maps was introduced. The idea was to reduce the investigation of the complete 2f-dimensional phase space trajectory $$x(t) =\varphi _{t}(x_{0})$$ to the investigation of its intersection points through a plane $$\varSigma$$ which is transverse to the flow of the system. This plane is a subspace of dimension 2f − 1 and is commonly referred to as Poincaré section [3]. The transversality of the Poincaré section $$\varSigma$$ means that periodic flows intersect this section and never flow parallel to or within it.

Consider a trajectory which is bound to a finite domain, i.e. it does not tend to infinity in any phase space coordinate. In this case it is possible to define the Poincaré section in such a way that the trajectory will intersect this section not only once but several times. Thus, a Poincaré map is then the mapping of one intersection point P onto the next intersection point P′.

Let us substantiate this idea: we consider the initial condition x ₀ for which a trajectory Γ is periodic. We choose the initial time t = 0 in such a way that $$x_{0} \in \varSigma$$, where $$\varSigma$$ is the Poincaré section, Fig. 6.7. We suppose that after a time τ(x ₀) the trajectory intersects this Poincaré section again.³ Since we demanded that the trajectory which started in x ₀ is periodic, we deduce that it intersects the Poincaré section again at some point $$\varphi _{\tau (x_{0})}(x_{0}) = x_{0}$$. We consider now a slightly perturbed initial condition x′ ∈ U ₀(x ₀), where U ₀(x ₀) is referred to as the neighborhood of x ₀. In this case the trajectory will in general not be periodic, and the next

Fig. 6.7

Schematic illustration of the neighborhood U ₀(x ₀) and the neighborhood of first return U ₁(x ₀) of a periodic trajectory Γ. The intersection point x ₀ of Γ with $$\varSigma$$ is a fixed point of this mapping

intersection point $$\varphi _{\tau (x')}(x')\neq x'$$. The mapping from one intersection point x′ onto the next intersection point $$\varphi _{\tau (x')}(x')$$ is called the Poincaré map $$P(x') =\varphi _{\tau (x')}(x')$$. We note that the particular point x ₀ is a fixed point of this mapping, P(x ₀) = x ₀. Furthermore, we note that if x′ ∈ U ₀(x ₀) we will have P(x′) ∈ U ₁(x ₀), where U ₁(x ₀) is the neighborhood of first return. This is indicated schematically in Fig. 6.7.

We utilize now these concepts and analyze the dynamics of the double pendulum. We have four generalized coordinates which, with the help of conservation of energy, are constrained to a three-dimensional manifold within the four-dimensional phase space. Since the investigation of these three-dimensional trajectories is very complex we consider a two-dimensional Poincaré section. For instance, the coordinates $$[\varphi _{1}(t),p_{1}(t)]^{T}$$ can be ‘measured’ whenever $$\varphi _{2}(t) = 0$$ and p ₂ > 0. Thus, the system’s state is registered whenever mass 2 crosses the vertical plane from the left-hand side.

We discuss now some of the most typical scenarios for Poincaré plots. (Such a plot represents the Poincaré section together with all intersection points of a particular trajectory.) Note that this discussion is, of course, not restricted to the case of the double pendulum. Two different scenarios can be distinguished for integrable systems: (i) the set of intersection points (η ₁, η ₂, …, η N ) is finite. (ii) In the more general case, the dimension N of the set of intersection points is infinite. In both cases the intersection points form one-dimensional lines which do not have to be connected. Figure 6.8a, b discuss this schematically. However, if the system is non-integrable, a third scenario is possible: chaotic behavior. In this case the intersection points appear to be randomly distributed on the two-dimensional Poincaré section and one observes space-filling behavior. This is illustrated schematically in Fig. 6.8c. Whether one observes chaotic behavior or not depends on the choice of the initial conditions.

Fig. 6.8

Schematic illustration of the three types of Poincaré plots as discussed in the text. (a) Finite number of intersection points, (b) infinite number of intersection points which, however, form closed lines, (c) space-filling and, consequently, chaotic behavior

In Figs. 6.9, 6.10, and 6.11 we present Poincaré plots of the double pendulum. The graphs were obtained with help of the method discussed above, i.e. $$\varphi _{2} = 0$$ and p ₂ > 0. Again, we set $$m =\ell= 1$$ and g = 9. 8067. The time step was chosen to be Δ t = 0. 001 and we calculated N = 36 × 10⁴ time steps. In Figs. 6.9 and 6.10 we observe regular behavior as it was illustrated in Fig. 6.8b. In Fig. 6.11 the points are space filling and, consequently, chaotic behavior is observed in this particular case. Keeping in mind that this particular Poincaré plot refers to the initial value problem of Fig. 6.4 we conclude that all problems of this series, i.e. Figs. 6.4, 6.5, and 6.6, are non-integrable and chaotic.

Fig. 6.9

Poincaré plot of the double pendulum with initial conditions $$\varphi _{1}(0) =\varphi _{2}(0) = 0.0$$, p ₁(0) = 4. 0 and p ₂(0) = 2. 0. It corresponds to the situation discussed in Fig. 6.2

Fig. 6.10

Poincaré plot of the double pendulum with initial conditions $$\varphi _{1}(0) = 1.0,\varphi _{2}(0) = 0.0$$, p ₁(0) = 0. 0 and p ₂(0) = 3. 0. It corresponds to the situation discussed in Fig. 6.3

Fig. 6.11

Poincaré plot of the double pendulum with initial conditions $$\varphi _{1}(0) =\varphi _{2}(0) = 0.0$$, p ₁(0) = 0. 0 and p ₂(0) = 4. 0. It corresponds to the situation discussed in Fig. 6.4

Summary

The dynamics of the double pendulum is described by a system of four ordinary first order differential equations. It is a typical initial value problem and, thus, the methods introduced in Chap. 5 are all candidates to find a numerical solution. Here we concentrated on the explicit Runge-Kutta algorithm e-RK-4 of Sect. 5.​3 Solutions were studied in detail for several classes of initial conditions. One of the results was that rather small changes of the initial conditions could result in rather strong, chaotic reactions of the outer mass. This triggered the obvious question about the stability of a numerical analysis and of physical dynamics in general. While the stability of numerical methods has already been discussed in Chap. 1 we focused here on the chaotic behavior of Hamiltonian systems. Consequently, a short section on the numerical analysis of chaos was added. It contained the most important concepts and in particular the concept of the stability of a phase space trajectory against variation of initial conditions. Finally, the importance of Poincaré plots in recognizing whether a system is integrable or non-integrable was explained. Non-integrable systems can develop chaotic behavior. Thus, Poincaré plots are an important tool to study chaos in mechanics.

Problems

1.

Verify Hamilton’s equations of motion derived in Sect. 6.1. Implement the e-RK-4 algorithm discussed in Sects. 5.​3 and 6.2 to integrate the equations of motion. Plot the trajectories for various initial conditions. Use the examples illustrated in Sect. 6.2 to check the code.

2.

Produce Poincaré plots by plotting $$(\varphi _{1},p_{1})$$ whenever $$\varphi _{2} = 0$$ and p ₂ > 0. The condition $$\varphi _{2} = 0$$ is substituted by $$\vert \varphi _{2}\vert &lt;\epsilon$$ in the numerically realization. Note that if the points are space filling the dynamics are chaotic, as discussed in Sect. 6.3. Try to find different initial conditions which result in regular behavior and different initial conditions which produce chaotic dynamics.

3.

Let $$x(t) = [\varphi _{1}(t),\varphi _{2}(t),p_{1}(t),p_{2}(t)]^{T}$$ and $$x'(t) = [\varphi _{1}'(t),\varphi _{2}'(t),p_{1}'(t),p_{2}'(t)]^{T}$$ be two trajectories which correspond to different initial conditions x ₀ and x ₀′. In this case the distance between trajectories is defined as

Plot the distance d(t) as a function of time t for two different initial conditions.

4.

Extend the code of the double pendulum of equal mass and equal length to cover the case when the lengths and masses of the individual pendula are different, ℓ ₁ ≠ ℓ ₂ and m ₁ ≠ m ₂. What happens? For instance, one can choose a certain initial condition and keep ℓ ₁ and ℓ ₂ fixed. What is the influence of ℓ ₁ and ℓ ₂ on the dynamics?

5.

Show that the dynamics become integrable in the absence of a gravitational force, i.e. g = 0. What are the conserved quantities? How do the Poincaré plots look like? Again, try different initial conditions.

References

1.

Arnol’d, V.I.: Mathematical Methods of Classical Mechanics, 2nd edn. Graduate Texts in Mathematics, vol. 60. Springer, Berlin/Heidelberg (1989)

2.

Fetter, A.L., Walecka, J.D.: Theoretical Mechanics of Particles and Continua. Dover, New York (2004)

3.

Scheck, F.: Mechanics, 5th edn. Springer, Berlin/Heidelberg (2010)

4.

Goldstein, H., Poole, C., Safko, J.: Classical Mechanics, 3rd edn. Addison-Wesley, Menlo Park (2013)

5.

Fließbach, T.: Mechanik, 7th edn. Lehrbuch zur Theoretischen Physik I. Springer, Berlin/Heidelberg (2015)

6.

Arnol’d, V.I.: Catastrophe Theory. Springer, Berlin/Heidelberg (1992)

7.

McCauley, J.L.: Chaos, Dynamics and Fractals. Cambridge University Press, Cambridge (1994)

8.

Devaney, R.L.: An Introduction to Chaotic Dynamical Systems, 2nd edn. Westview, Boulder (2003)

9.

Schuster, H.G., Just, W.: Deterministic Chaos, 4th edn. Wiley, New York (2006)

10.

Teschl, G.: Ordinary Differential Equations and Dynamical Systems. Graduate Studies in Mathematics, vol. 140. American Mathematical Society, Providence (2012)

11.

Lyapunov, A.M.: The General Problem of Stability of Motion. Taylor & Francis, London (1992)

Footnotes

1

We make use of the relation:

2

The symplectic mapping $$\varphi _{t}: x_{0}\mapsto x(t)$$ from the initial conditions x ₀ to the phase space point x(t) at time t is referred to as Hamiltonian flow of the system. This was discussed in Sect. 5.​4

3

Note that we denoted τ ≡ τ(x ₀) in order to emphasize that the recurrence time τ will depend on the initial condition x ₀.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_7

7. Molecular Dynamics

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

7.1 Introduction

It is the aim of many branches of research in physics to describe macroscopic properties of matter on the basis of microscopic dynamics. However, a description of the simultaneous motion of a large number of interacting particles is in most cases not feasible by analytic methods. Moreover, a description is particularly difficult if the interaction between the particles is strong. Within the framework of statistical mechanics one tries to remedy these difficulties by employing some simplifying assumptions and by treating the system from a statistical point of view [1–4]. However, most of these simplifying assumptions are only justified within certain limits, such as the weak coupling limit or the low density limit. Nevertheless, it is not easy to establish how the solutions acquired are influenced by these limits and how the physics beyond these limits can be perceived. This makes the necessity of numerical solutions quite apparent. There are essentially two methods to determine physical quantities over a restricted set of states, namely molecular dynamics [5–7] and Monte Carlo methods. The technique of molecular dynamics will be discussed within this chapter while an introduction into some basic features of Monte Carlo algorithms is postponed to the second part of this book.

We strictly focus on a particular sub-field of molecular dynamics, namely on classical molecular dynamics , i.e. the treatment of classical physical systems. Extensions to quantum mechanical systems, which are commonly referred to as quantum molecular dynamics [8], will not be discussed here.

7.2 Classical Molecular Dynamics

The classical model system for molecular dynamics consists of N particles with positions r i  ≡ r i (t), velocities $$v_{i} \equiv v_{i}(t) =\dot{ r}_{i}(t)$$ and masses m i , where i = 1, 2, …, N. We note that r i and v i are vectors of the same dimension. We can write Newton’s equations of motion as

(7.1)

where we introduced the forces f i  ≡ f i (r ₁, r ₂, …, r N ). Again, we note that the forces f i are vectors of the same dimension as r i and v i . We specify the forces f i by demanding them to be conservative. Thus, we write

(7.2)

where ∇ i is the gradient pertaining to the spatial components of the i-th particle and U(r ₁, r ₂, …, r N ) is some potential which we will abbreviate by dropping its arguments: U ≡ U(r ₁, r ₂, … r N ). We then specify this potential U as the sum of two-particle interactions U ij and some external potential U ext as, for instance, the gravitational field or a static electric potential applied to the system:

(7.3)

In our discussion of the two-body problem (Appendix A) and, in particular, of the Kepler problem in Chap. 4 we considered a central potential, which was proportional to $$-1/r$$. Due to the conservation of angular momentum, it was convenient to introduce an effective potential U eff as the sum of an attractive and repulsive part as it was defined in Eq. (4.​3) and illustrated in Fig. 4.​1 In contrast, in molecular dynamics the most prominent two-body interaction potential is known as the Lennard-Jones potential [9]. It is of the form

(7.4)

where ε and $$\sigma$$ are real parameters and $$\vert r\vert$$ is the distance between two particles. The significance of the parameters ε and $$\sigma$$ as well as the form of $$U(\vert r\vert )$$ defined by Eq. (7.4) is illustrated in Fig. 7.1. The Lennard-Jones potential was particularly developed to model the interaction between neutral atoms or molecules. The repulsive term, which is proportional to $$\vert r\vert ^{-12}$$, describes the Pauli repulsion while the attractive $$\vert r\vert ^{-6}$$ term accounts for attractive van der Waals forces.

Fig. 7.1

Illustration of the Lennard-Jones potential, Eq. (7.4). $$\sigma$$ describes the depth of the potential well and ε is the position of the root of the Lennard-Jones potential

We introduce the distance between particles i and j via

(7.5)

and define the two-body potential

(7.6)

where U is approximated by the Lennard-Jones potential (7.4). Furthermore, we deduce from Eq. (7.4) that

(7.7)

where we keep in mind that r is a vector. Hence, we write the forces f i which appear in Newton’s equations of motion  (7.1) with the help of (7.3) in the form

(7.8)

where we implicitly defined the external force $$f_{\mathrm{ext}}^{i}$$ acting on particle i and the two-particle forces f ij acting between particle i and j. We want to make the road visible, which guides us to a numerical solution of Newton’s equations of motion (7.1), and introduce the vectors R = (r ₁, r ₂, …, r N ) T , $$V = (v_{1},v_{2},\ldots,v_{N})^{T} =\dot{ R}$$, and $$F = (\,f_{1}/m_{1},f_{2}/m_{2},\ldots,f_{N}/m_{N})^{T}$$. This transforms Eq. (7.1) into the very compact form

(7.9)

which is equivalent to a set of two first order ordinary differential equations:

(7.10)

This set is already of the standard form (5.​1) of initial value problems.

We are now in a position to proceed with a discussion of some numerical methods which have been developed in Chap. 5 to solve this initial value problem. For this sake, we regard discrete time instances t k  = kΔt, where $$k \in \mathbb{N}$$ and function values at these discrete time instances t k are denoted by a subscript k, as for instance R k  ≡ R(t k ).

(i)

In a first approximation we apply the symplectic Euler method [see Eq. (4.​33)] to Eq. (7.10) and obtain

(7.11)

Inserting the second into the first equation results in

(7.12)

The velocity V k at time t k is then approximated by the backward difference derivative  (2.10b) and we find the recursion relation:

(7.13)

We note that it is only valid for k ≥ 1. The initialization step necessary to complete the analysis is found by expanding R ₁ in a Taylor series up to second order:

(7.14)

This method is referred to as the Störmer-Verlet algorithm [10]. Note that Eq. (7.14) serves as the initialization of the sequence of time steps. Furthermore, we remark that Eq. (7.13) could have also been obtained using the central difference derivative to approximate the second time derivative in Eq. (7.1):

(7.15)

In summary, the Verlet or Störmer-Verlet algorithm is defined by the following set of equations:

(7.16)

(ii)

We employ the central rectangular rule of integration (Sect. 3.​2) in order to obtain approximations which are formally equivalent to Eq. (5.​11). In particular, we obtain from Eq. (7.10):

(7.17)

We note that the value of $$V _{k+1/2}$$ is yet undetermined. However, it can be determined in a similar fashion via

(7.18)

This method is referred to as the leap-frog algorithm and is initialized by the relation

(7.19)

This equation can also be obtained by expanding V 1∕2 in a Taylor series up to first order around the point t ₀ = 0 and by noting that $$\dot{V }_{k} = F_{k}$$. In summary we write the leap-frog algorithm as

(7.20)

(iii)

A third, very elegant alternative is the so-called velocity Verlet algorithm. We expand R k+1:

(7.21)

This allows to calculate the spatial coordinates at time t k+1 if R k and V k are given. Note that F k  ≡ F(R k ) is completely determined by the positions R k . Nevertheless, we need one more relation in order to determine the velocities at times t k+1. Again, we expand V k+1 in a Taylor series . However, we approximate the remainder by the arithmetic mean between t k and t k+1:

(7.22)

The strategy is clear: we calculate the positions R k+1 from Eq. (7.21) for given values of R k and V k . With the help of R k+1 we compute F k+1, which is then inserted into Eq. (7.22) which determines V k+1. In summary, the complete algorithm of the velocity Verlet method is defined by the steps:

(7.23)

We note some properties of these methods. The Störmer-Verlet algorithm of Eq. (7.16) is time-reversal symmetric (invariant under the transformation Δ t → −Δ t), hence reversible. This is a direct consequence of its relation to the symplectic Euler method. Moreover, the positions R k obtained with this method are highly accurate, however, the procedure suffers under an inaccurate approximation of the velocities V k . This shortcoming is clearly remedied by the leap-frog algorithm (7.20) or the velocity Verlet algorithm (7.23). However, these methods are not time-reversal invariant. Hence, one has to decide whether or not very accurate values for the velocities are required for the problem at hand. In many cases the velocity Verlet algorithm is the most popular choice.

7.3 Numerical Implementation

The rough structure of a molecular dynamics code consists of three crucial steps, namely

Initialization,

start simulation and equilibrate,

continue simulation and store results.

In the following we discuss some of the most important subtleties associated with these three parts. In particular we will focus on the choice of appropriate boundary conditions and on the choice of the scales of characteristic quantities.

Boundary Conditions

Basically, there are two possibilities: (i) The system is of finite size and the implementation of boundary conditions might be straightforward. For instance, let us assume that we regard N particles within a finite box of reflecting boundaries, we simply propagate the particle-coordinates in time and if a particle tries to leave the box, we correct its trajectory according to a reflection law. The velocity is adjusted accordingly. This is illustrated in Fig. 7.2 for a two-dimensional case and the particular situation that the particle is reflected from the right hand boundary of the box. The corresponding equations read

(7.24)

and

(7.25)

Here, L denotes the length of the box and $$\tilde{x}_{k+1}$$, $$\tilde{y}_{k+1}$$, $$\tilde{v}_{k+1,x}$$ and $$\tilde{v}_{k+1,y}$$ are the positions and velocities one would have obtained in the absence of the boundary, see Fig. 7.2.

Fig. 7.2

Illustration of the reflection principle for a box of finite dimension with reflecting boundaries

(ii) The system is not confined. Then the situation is entirely different. Of course, one could approximate the infinite volume by a large but finite volume. In such a case the influence of a constraint to finite size is usually not negligible. The induced errors are referred to as finite volume effects . A very popular choice are so called periodic boundary conditions which means that a finite system is surrounded by an infinite number of completely identical replicas of the system, where the forces are allowed to act across the boundaries. Because of this, calculating the force on one particle requires the evaluation of an infinite sum. This is numerically not manageable and we have to find ways to truncate the sum. For instance, it might be a good approximation to restrict the sum to nearest-neighbor cells. However, the applicability of such an approach highly depends on the properties of the system under investigation and, in particular, on the range of the interaction potential. In case of a Lennard-Jones potential the quantity defining the range of the interaction potential is ε, see Fig. 7.1.

If a particle leaves the box, it enters the box at the same time on the opposite side. More generally, due to the requirement of identical replicas, we have for all observables O(r) that $$O(r + nK) = O(r)$$, where r lies within the central box, K is a lattice vector pointing to one of the neighboring cells and $$n \in \mathbb{Z}$$.

There is another crucial point concerning periodic boundary conditions. In case of a closed system, the system is definitely at rest. However, if periodic boundary conditions are imposed it is possible that the particles move with constant velocity from one cell to another, which, in our case, resembles circling trajectories. This is definitely not desirable since the total velocity is a measure of the kinetic energy and, therefore, of the temperature of the system. However, one can shift the total velocity in order to remedy this problem. In particular, if

(7.26)

the shift

(7.27)

yields the desired result. We note that in a case where all masses are identical, i.e. $$m_{1} = m_{2} =\ldots = m_{N} \equiv m$$, this is equivalent to $$p_{\mathrm{tot}} = mv_{\mathrm{tot}} = 0$$.

In conclusion, we remark that the choice of boundary conditions is not the only item to be considered in the definition of the system. Another quite crucial point might be the size of the box. If an infinite system is modeled using finite systems, the dimension of the box must fairly exceed the mean free path of the particles. Otherwise, the influence of the boundaries is going to perturb significantly the outcome of the numerical experiment.

Initialization and Equilibration

We remember from statistical physics [1–4] that every degree of freedom in the system (7.1) contributes just k B T∕2 to the total kinetic energy because of the equipartition theorem. Here k B is Boltzmann’s constant and T is the temperature. If we regard N particles, which move in a d-dimensional space, we have d(N − 1) degrees of freedom, if we demand that v tot = 0. Hence, we have

(7.28)

which gives a relation from which we can determine the temperature of the system :

(7.29)

However, in many applications the system is supposed to be simulated at a given temperature, i.e. the temperature T is an input rather than an output parameter and is supposed to stay constant during the simulation. We can control the temperature by rescaling the velocities and this might be necessary at several times during the simulation in order to guarantee a constant temperature . We define

(7.30)

where $$\lambda$$ is a rescaling parameter. The temperature associated with the velocities v i ′ is given by

(7.31)

This allows to determine how to choose $$\lambda$$ in order to obtain a certain temperature T′:

(7.32)

We note that if the total velocity, which is the sum of all velocities v i , is zero, the total velocity corresponding to the rescaled velocities v i ′ is also equal to zero since

(7.33)

This ensures that rescaling of the velocities does not induce a bias.

The choice of the initial conditions highly influences the time the system needs to reach thermal equilibrium . For instance, if a gas is to be simulated at a given temperature T it might be advantageous to choose the initial velocities according to a Maxwell-Boltzmann distribution. The Maxwell-Boltzmann distribution states that the probability [more precisely: the pdf (probability density function describing the probability, see Appendix E)] that a particle with mass m has velocity v is proportional to

(7.34)

Another intriguing question is how to check whether or not thermal equilibrium has been reached. In statistical mechanics one is usually confronted with expectation values of observables O(t) as a function of time. The expectation value $$\left \langle O\right \rangle$$ is defined as

(7.35)

Since O(t) is not known analytically one replaces the mean value by its arithmetic mean

(7.36)

If n and k are sufficiently large, the average value can be regarded as converged. In particular, one has to choose n reasonably large and then find k in such a way, that for all values k′ ≥ k the same result for $$\overline{O}$$ is obtained. Hence, equilibrium has been reached after k time-steps and it is now possible to ‘measure’ the observables by calculating their mean values. A more detailed discussion of such a procedure, as, for instance, the influence of time correlations or a discussion of more advanced techniques is postponed to Chap. 19

There is one last point: In many cases the natural units of the physical system might be disadvantageous because they are likely to induce numerical instabilities. In such cases a common technique is to switch to rescaled variables by introducing new units, which are characteristic quantities for the system and all physical quantities are expressed in these new units. For instance one might introduce the length L of the box as the unit of space. The new spatial coordinates would then be given by

(7.37)

Hence all coordinates take on values within the interval r′ ∈ [0, 1]. However, one cannot introduce an arbitrary set of characteristic quantities due to the physical relations they have to obey. For instance, one might introduce a characteristic energy E ₀, a characteristic length $$\lambda$$, and a characteristic mass m. In this case the characteristic temperature $$\tilde{T}$$ is determined via

(7.38)

Moreover the characteristic time τ is fixed to the value

(7.39)

which results from the relation between the kinetic energy and the velocity.

To illustrate a molecular dynamics simulation we study a set of N = 100 particles of mass m = 1 which are subject to a Lennard-Jones potential (7.4) characterized by $$\epsilon =\sigma = 1$$ and to a gravitational force mg, g = 9. 81. At initialization the particles are placed in a 10 × 10 lattice starting with the lower left hand edge at x = 10. 5 and y = 10. The particles are equally spaced with $$\varDelta x =\varDelta y =\epsilon$$. This initial configuration is shown in Fig. 7.3a. Furthermore, the left hand side, the right hand side, and the bottom of the confinement (L = 30) are described by reflecting boundary conditions, Eqs. (7.24) and (7.25). The confinement is open at the top, i.e. it extends to infinity. The time step is given by $$\varDelta t = 10^{-3}$$. Figure 7.3b–d demonstrate how the system developed after 1200, 1800, and 3000 time steps, respectively.

Fig. 7.3

(a) Initial configuration: the particles are placed in a 10 × 10 equally spaced lattice starting with x = 10. 5 and y = 10. 0; g = 9. 81. The initial velocities are equal to zero. (b) Configuration after 1200 time steps. (c) Configuration after 1800 time steps. (d) Configuration after 3000 time steps

This chapter closes our discussion of the numerics of initial value problems. In the following chapters we will introduce some of the basic concepts developed to solve boundary value problems with numerical methods.

Summary

This chapter dealt with the classical dynamics of many particles (not necessarily identical particles) which are confined in a box of finite dimension or which are allowed to roam freely in infinite space. The particles are subject to a particle-particle interaction and to an external force. The discussion was restricted to classical molecular dynamics. From Newton’s equations of motion for N interacting particles numerical methods were developed which allowed the simulation of the particles’ dynamics. Based on the symplectic Euler method the Störmer-Verlet algorithm was derived. Another approach was based on the central rectangular rule and resulted in the leap-frog algorithm. Finally, the velocity Verlet algorithm was introduced. All three methods do have their merits. The first gives very accurate results for the particles’ positions but calculates inaccurate velocities. It has the advantage that it is time reversible. The other two methods lack this property but give very accurate estimates of the particles’ velocities. The final part of this chapter was dedicated to the discussion of various subtleties of the numerical implementation of these algorithms as there were: (i) definition of boundary conditions, (ii) initialization of the algorithm, (iii) equilibration to a given temperature, (iv) ensuring constant temperature throughout the simulation, and (v) transformation to rescaled variables.

Problems

1.

We investigate the pendulum of Chap. 1 and write its equation of motion as

with $$\omega = \sqrt{g/\ell}$$. The Störmer-Verlet algorithm is applied to simulate the pendulum’s motion and to compare the numerical results with the exact solution. Demonstrate that the result is very sensitive to the choice of the time step Δ t and, in particular, of the product ω Δ t. Note that in this particular case the Störmer-Verlet algorithm can also be studied analytically! What happens for the choice ω Δ t = 1 or ω Δ t ≥ 2? Which conclusions can be drawn from this example for a proper choice of the time discretization?

Try the other two methods to simulate the pendulum’s dynamics.

2.

Write a molecular dynamics code with the help of the following instructions. You can use either the leap-frog or the velocity Verlet algorithm. We consider the following system:

There are N = 100 particles in a two-dimensional box with side length L = 30. The boundaries at the bottom, at the left- and at right-hand side are considered as reflecting, as in Fig. 7.2. The top of the box is regarded as open (no periodic boundary condition or reflecting boundary is imposed).

The particles interact through a Lennard-Jones potential of the form (7.4) where ε and $$\sigma$$ define the interaction.

Furthermore, a gravitational force $$F_{\mathrm{ext}} = -mge_{y}$$ acts on each particle, where m is the particle’s mass, g is the acceleration due to gravity, and e y denotes the unit vector in y-direction.

As an initial condition, the particles can be placed within the box on a regular lattice, where the distance between the particles is the characteristic distance according to the Lennard-Jones potential, i.e. ε. The form and position of this lattice is arbitrary. This is illustrated in Fig. 7.3.

We measure the velocities and the positions of all particles. Since the particle’s velocities and positions are to be analyzed with the help of an extra program, the data are written to external files (it is not necessary to save all time steps!).

Perform the following analysis:

Determine the temperature T from the kinetic energy as discussed in in this chapter. Note that in this particular case we do not demand that v tot  = 0!

Try different initial conditions. For instance, set the initial velocity equal to zero and stack the particles in different geometric configurations (rectangle, triangle, …, one can also use more than one configurations at the same time!). The nearest neighbor distance between the particles can be set equal to ε. Choose one configuration and place it at different positions in the box. What happens?

Set $$\epsilon =\sigma = m = 1$$ (we change the units) and set in the initial condition to the inter-atomic distance of $$2^{\frac{1} {6} }\epsilon$$. (Why?) Vary the gravitational acceleration g (different systems of units) in order to simulate different states of matter. The reference program developed solid behavior for g ≈ 0, liquid behavior for g ≈ 0. 1 and gaseous behavior for g > 1. Explain this behavior!

Measure the particle density ρ(h) as a function of the height h. You should be able to reproduce the barometric formula :

Determine the momentum distribution (p i  = mv i ) of the particles and demonstrate that it follows a Maxwell-Boltzmann distribution

with $$\vert v\vert = \sqrt{v_{x }^{2 } + v_{y }^{2}}$$, the Euclidean norm.

Illustrate the results of the simulation graphically.

References

1.

Mandl, F.: Statistical Physics, 2nd edn. Wiley, New York (1988)

2.

Schwabl, F.: Statistical Mechanics. Advanced Texts in Physics. Springer, Berlin/Heidelberg (2006)MATH

3.

Halley, J.W.: Statistical Mechanics. Cambridge University Press, Cambridge (2006)Crossref

4.

Hardy, R.J., Binek, C.: Thermodynamics and Statistical Mechanics: An Integrated Approach. Wiley, New York (2014)CrossrefMATH

5.

Hoover, W.G.: Molecular Dynamics. Springer, Berlin/Heidelberg (1986)MATH

6.

Griebel, M., Knapek, S., Zumbesch, G.: Numerical Simulation in Molecular Dynamics. Texts in Computational Science and Engeneering, vol. 5. Springer, Berlin/Heidelberg (2007)

7.

Marx, D., Hutter, J.: Ab Initio Molecular Dynamics. Cambridge University Press, Cambridge (2012)

8.

Gatti, F. (ed.): Molecular Quantum Dynamics. Springer, Berlin/Heidelberg (2014)

9.

Jones, J.E.: On the determination of molecular fields. II. From the equation of state of a gas. Proc. R. Soc. A 106, 463–477 (1924). doi:10.1098/rspa.1924.0082Crossref

10.

Hairer, E., Lubich, C., Wanner, G.: Geometric numerical integration illustrated by the Störmer-Verlet method. Acta Numer. 12, 399–450 (2003). doi:10.1017/S0962492902000144ADSMathSciNetCrossrefMATH

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_8

8. Numerics of Ordinary Differential Equations: Boundary Value Problems

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

8.1 Introduction

It is the aim of this chapter to introduce some of the basics methods developed to solve boundary value problems. Since a treatment of all available concepts is far too extensive, we will concentrate on two approaches, namely the finite difference approach and shooting methods [1–5]. Furthermore, we will strictly focus on linear boundary value problems defined on a finite interval $$[a,b] \subset \mathbb{R}$$. A boundary value problem is referred to as linear if both the differential equation and the boundary conditions are linear. Such a problem of order n is of the form

(8.1)

Here, L[y] is a linear operator

(8.2)

where y (k)(x) denotes the k-th spatial derivative of y(x), i.e. y (k) ≡ d k y(x)∕dx k and f(x) as well as the a k (x) are given functions which we assume to be continuous. Accordingly, linear boundary conditions U ν [y] can be formulated as

(8.3)

where the α ν k , β ν k and $$\lambda _{\nu }$$ are given constants. The question in which cases a solution to the boundary value problem (8.1) exists and whether or not this solution will be unique [6], will not be discussed here.

Let us introduce some further conventions: The differential equation in the first line of Eq. (8.1) is referred to as homogeneous if the function f(x) = 0 for all x ∈ [a, b]. In analogy, the boundary conditions are referred to as homogeneous if the constants $$\lambda _{\nu } = 0$$ for all ν = 1, …, n. Finally, the boundary value problem (8.1) is referred to as homogeneous if the differential equation is homogeneous and the boundary conditions are homogeneous as well. In all other cases it is referred to as inhomogeneous. Moreover, the boundary conditions are said to be decoupled if the function values at the two different boundaries do not mix.

One of the most important types of boundary value problems in physics are linear second order boundary value problems with decoupled boundary conditions. They are of the form:

(8.4a)

(8.4b)

(8.4c)

This chapter focuses mainly on problems of this kind.

In particular, for second order differential equations, boundary conditions of the form

(8.5)

are referred to as boundary conditions of the first kind or Dirichlet boundary conditions. On the other hand, boundary conditions of the form

(8.6)

are referred to as boundary conditions of the second kind or Neumann boundary conditions and boundary conditions of the form (8.4) are referred to as boundary conditions of the third kind or Sturm boundary conditions .

We note, that the particular case of decoupled boundary conditions does not include problems like

(8.7)

We encountered such a condition in Sect. 7.​3 where we introduced boundary conditions of this form as periodic boundary conditions.

In the following section the method of finite differences will be applied to solve boundary value problems of the form (8.4). On the other hand, shooting methods, in particular the method developed by Numerov (see, for instance, [7] and references therein), will be the topic of the third section.

A common alternative in the case of constant coefficients is to solve the differential equation with the help of Fourier transform techniques. A brief introduction to the numerical implementation of the Fourier transform is given in Appendix D.

8.2 Finite Difference Approach

For illustrative purposes, we regard a boundary value problem of the form (8.4). The extension to more complex problems might be tedious but follows the same line of arguments. We discretize the interval [a, b] according to the recipe introduced in Chap. 2: the positions x k are given by $$x_{k} = a + (k - 1)h$$, where the grid-spacing h is determined via the maximum number of grid-points N as $$h = (b - a)/(N - 1)$$. Hence, we have x ₁ = a and x N  = b. Furthermore, we use the notation y k  ≡ y(x k ) for all k = 1, …, N. It will be used for all functions which appear in Eqs. (8.4).

Let us now employ the central difference derivative (2.10c) in order to approximate

(8.8)

for $$k = 2,\ldots,N - 1$$ and

(8.9)

The boundary points x ₁ and x N will be treated in a separate step. In order to abbreviate the notation we will rewrite the differential equation (8.4) without the indices as

(8.10)

Equations (8.8) and (8.9) are then applied and we arrive at the difference equation

(8.11)

where $$k = 2,\ldots,N - 1$$. Sorting the y k yields

(8.12)

and this equation is only valid for $$k = 2,\ldots,N - 1$$ because we defined N grid-points within the interval [a, b].

A final step is necessary in which the boundary conditions are incorporated. This will then enable us to reduce the whole problem to a system of linear equations. Decoupled boundary conditions of a second order differential equation for the left-hand boundary (8.4b) are of the general form:

(8.13)

In analogy, we find for the right-hand boundary (8.4c):

(8.14)

We discretize y′(a) as

(8.15)

and set y ₁ = y(a). Note that the function value y ₀ in Eq. (8.15) is unknown since the virtual point $$x_{0} = a - h$$ is not within our interval [a, b]. Nevertheless, we use Eq. (8.15) in Eq. (8.13) and obtain:

(8.16)

We solve now Eq. (8.16) for y ₀ under the premise that α ₁ ≠ 0,

(8.17)

rewrite Eq. (8.12) for k = 1,

(8.18)

and insert (8.17) into (8.18):

(8.19)

On the other hand, in the specific case of α ₁ = 0 we immediately obtain from Eq. (8.16):

(8.20)

The same strategy can be applied to incorporate the right-hand side boundary condition, Eq. (8.14): We discretize Eq. (8.14) by introducing the function value y N+1 at the virtual grid-point $$x_{N+1} = N + h$$ outside the interval [a, b] via:

(8.21)

This equation is solved for y N+1 under the premise that β ₁ ≠ 0

(8.22)

and insert this into Eq. (8.12) for k = N. This results in:

(8.23)

In the specific case β ₁ = 0, the value y N is fixed at the boundary and one obtains from Eq. (8.14):

(8.24)

All these manipulations reduced the boundary value problem to a system of inhomogeneous linear equations, namely Eqs. (8.12), (8.19), and (8.23). It can be written as

(8.25)

where we introduced the vector y = (y ₁, y ₂, …, y N ) T , the vector F

(8.26)

and the tridiagonal matrix A:

(8.27)

Here we defined

(8.28)

(8.29)

and, finally,

(8.30)

The remaining task is now to solve this linear system of equations (8.25). (A brief introduction to the numerical treatment of linear systems of equations can be found in Appendix C.) Very effective methods exist for cases where the matrix A is tridiagonal [8] as it is the case here. Although we discussed the method of finite differences for the particular case of a second order differential equation with decoupled boundary conditions, the same strategy can be employed to derive similar methods for higher order boundary value problems. However, these methods will, in general, be more complex. Furthermore, we note that in cases where $$\alpha _{1} =\beta _{1} = 0$$ the function values at the boundaries y ₁ and y N are fixed and the corresponding system of linear equations reduces to (N − 2) equations.

Let us briefly investigate the differential equation which corresponds to the problem (8.4) together with periodic boundary conditions of the form (8.7). In this case we have to consider that

(8.31)

and, for a solution to exist, we have necessarily

(8.32)

The finite difference approximations (8.8) and (8.9) are again applied to derive Eqs. (8.12) for $$k = 2,\ldots,N - 1$$. For k = 2 Eq. (8.12) becomes

(8.33)

and we have for $$k = N - 1$$

(8.34)

Since y ₁ = y N this can be rewritten as

(8.35)

Finally, Eq. (8.12) results for k = 1 in

(8.36)

where we identified $$y_{0} = y(x_{1} - h) \equiv y(x_{N} - h) = y_{N-1}$$. All this results in a closed system of N − 1 equations, which is of the form (8.25)

(8.37)

where $$y = (y_{1},y_{2},\ldots,y_{N-1})^{T}$$,

(8.38)

and the $$(N - 1) \times (N - 1)$$ matrix A is given by

(8.39)

Here, we defined

(8.40)

(8.41)

and

(8.42)

In contrast to the matrix (8.27) the matrix (8.39) is not tridiagonal since the matrix elements (A)1, N−1 and (A) N−1, 1 are non-zero. Nevertheless, it was possible to reduce the boundary value problem to a system of linear equations which can be solved iteratively.

8.3 Shooting Methods

For illustrative purposes, we restrict here the discussion to a second order boundary value problem with decoupled boundary conditions of the form (8.4). The essential idea of shooting methods is to treat the boundary value problem as an initial value problem. The resulting equations can then be solved with the help of methods discussed in Chap. 5 Of course, such an approach is ill-defined because no initial conditions but only boundary conditions are given. The trick is, that one modifies the initial conditions iteratively in such a way that in the end the boundary conditions are fulfilled. Let us put this train of thoughts into a mathematical form: We rewrite the second order differential equation (8.4a) as

(8.43)

which can be reduced to a set of first order differential equations as was demonstrated in Chap. 5 We note that Eq. (8.43) is not yet well posed since the initial conditions have not been defined. The boundary condition on the left-hand side reads:

(8.44)

We now assume that y′(a) = z, where z is some number. This gives the well posed initial value problem

(8.45)

under the assumption that α ₀ ≠ 0. The solution of this problem will be written as y(x; z) in order to indicate its dependence on the particular choice y′(a) = z. We remember, that the boundary condition at the right-hand boundary is defined as:

(8.46)

Let us introduce the function:

(8.47)

We observe that the solution of the equation

(8.48)

gives the desired solution to the boundary value problem (8.4), because in this case the second boundary condition (8.46) is fulfilled. In practice, one tries several values of z until relation (8.48) is fulfilled. However, from a numerical point of view this method is very inefficient since usually several initial value problems have to be solved until the correct value of z is found. Nevertheless, in some cases shooting methods proved to be very useful [7].

For instance, shooting methods are particularly effective if a solution to an eigenvalue problem of the form

(8.49a)

in combination with homogeneous boundary conditions,

(8.49b)

and

(8.49c)

is to be found. We note that Eq. (8.49a) has the trivial solution y(x) ≡ 0 for all values of $$\lambda$$. However a non-trivial solution will only exist for particular values of $$\lambda$$. These particular values will be indexed by $$\lambda _{n}$$ and are referred to as eigenvalues of Eq. (8.49a) [9]. The corresponding functions y n (x) are referred to as eigenfunctions. We note that the differential equation (8.49a) in combination with the boundary conditions (8.49b) and (8.49c) define a homogeneous boundary value problem . Such a problem is commonly referred to as an eigenvalue problem [9]. Furthermore, we note the following property of homogeneous boundary value problems: Suppose that y(x) is a solution of the boundary value problem (8.49), then $$\tilde{y}(x) =\gamma y(x)$$, with γ = const will also be a solution of (8.49). Hence, the solution of a homogeneous boundary value problem is not unique but invariant under multiplication by a constant γ. Typically, the multiplicative factor γ is fixed by some additional condition, such as a normalization condition of the form

(8.50)

We now employ this property and choose y(a) = 1. Inserting this choice into (8.49b) yields

(8.51)

Note that for α ₀ = 0 or α ₁ = 0, we are restricted to the choices y′(a) = 0 and y(a) is arbitrary or y(a) = 0 and y′(a) is arbitrary, respectively. If we assume that a(x) ≠ 0 for all x ∈ [a, b], we can solve the initial value problem

(8.52)

The solutions are denoted by $$y(x;\lambda )$$ in order to emphasize that they will highly depend on the choice of the parameter $$\lambda$$. The strategy is to solve the initial value problem (8.52) for several values of $$\lambda$$ and whenever one finds that

(8.53)

is satisfied, an eigenvalue $$\lambda _{n}$$ with the corresponding eigenfunction $$y_{n}(x) = y(x;\lambda _{n})$$ of the eigenvalue problem (8.49) has been found.

However, this strategy is also very time consuming. The most common application of the shooting method is its combination with a very fast and accurate solution of initial value problems. This method is known as the Numerov method [7] . It is applicable whenever one is confronted with a differential equation of the form

(8.54)

in combination with homogeneous boundary conditions. Here k(x) is some function. If we are particularly interested in eigenvalue problems then k(x) has the form $$k(x) = q(x)-\lambda$$, where q(x) is some function and $$\lambda$$ is the eigenvalue [see the discussion after Eq. (8.49)]. For instance, consider the one-dimensional stationary Schrödinger equation [10–12],

(8.55)

where ψ(x) is the wave-function, m is the mass, $$\hslash $$ denotes the reduced Planck constant, E is the energy, and V (x) is some potential. In this case we identify

(8.56)

We note that Eq. (8.55) together with its boundary conditions defines an eigenvalue problem with eigenvalues E n , the possible energies of the system. We remember from Chap. 2, Eq. (2.​34), that

(8.57)

Here we made use of Eq. (8.54) and introduced k j  ≡ k(x j ). Furthermore, we write the fourth derivative of y(x) at point x = x j as

(8.58)

where we employed Eq. (8.54). Truncating (8.57) after the fourth order derivative y j ⁽⁴⁾, inserting relation (8.58), and solving for y j+1 yields

(8.59)

This gives a very fast algorithm to solve the differential equation (8.54) with some initial values of the form (8.52). The remaining strategy is the same as discussed above, i.e. one screens the parameter $$\lambda$$ in order to find the eigenvalues $$\lambda _{n}$$ and eigenfunctions y n (x). In case of the Schrödinger equation, one can screen the energy E in order to obtain the energy eigenvalues E n which satisfy a condition of the form (8.53).

Before we present two illustrating examples in the next two chapters let us conclude this section with two important remarks on the Numerov method. We note from Eq. (8.59) that in order to compute y ₃ one already needs the function values y ₁ and y ₂. Usually, one obtains these values from the boundary conditions in combination with some additional condition for the problem at hand. Such an additional condition might be, for instance, the normalization of the function y(x), like Eq. (8.50). We also emphasized that one has to run the Numerov algorithm several times for different trial values of the parameter $$\lambda$$. In order to reduce the computational cost of the method it is in many cases advantageous to store the function values q i , where $$k_{i} = q_{i}-\lambda$$, in an array which is then regarded as an input argument of the Numerov algorithm.

Summary

We focused on linear boundary value problems defined on a finite interval $$[a,b] \subset \mathbb{R}$$. Most important for physics are second order boundary value problems with decoupled boundary conditions, i.e. the boundary conditions at the two different boundaries do not mix. The numerical treatment of the second order differential equation together with its boundary conditions concentrated either on the application of finite differences or on shooting methods. In the finite difference approach the methods developed in Chap. 2 were applied and the boundary conditions were incorporated directly. This resulted in a set of linear algebraic equations which was to be solved for each grid-point of the discretisized interval [a, b]. The case of periodic boundary conditions was also discussed in detail.

The shooting methods, on the other hand, try to link the decoupled boundary value problem to an initial value problem. This allowed the application of the methods discussed in Chap. 5 The idea was to start with some initial value at one of the two boundaries, solve the differential equation numerically and to modify the initial value iteratively until it agreed with the original boundary condition within some predefined error. Such a procedure is rather time consuming. Nevertheless, shooting methods, in particular its Numerov variation, proved to be very useful in the numerical solution of eigenvalue problems. This was demonstrated using the homogeneous boundary value problem of the one-dimensional stationary Schrödinger equation as an example.

Problems

1.

Solve the linear second order boundary value problem

for x ∈ [0, π∕2] with the boundary conditions y(0) = 0 and $$y(\pi /2) = 1$$ analytically and then numerically with the help of finite differences.

2.

Solve the linear, second order boundary value problem

on the interval $$[-\pi /2,\pi /2]$$ and with the boundary conditions $$y(\pm \pi /2) = 1$$. Use the finite difference method.

Comment: The solution can be expressed analytically in terms of so-called Mathieu functions [13, 14] which might be intrinsically available from your computing environment. If this happens to be the case, it might be a good idea to compare the numerical solution with the analytical result.

References

1.

Collatz, L.: The Numerical Treatment of Differential Equations. Springer, Berlin/Heidelberg (1960)

2.

Lapidus, L., Pinder, G.F.: Numerical Solution of Partial Differential Equations. Wiley, New York (1982)

3.

Stoer, J., Bulirsch, R.: Introduction to Numerical Analysis, 2nd edn. Springer, Berlin/Heidelberg (1993)

4.

Asher, U.M., Mattheij, R.M.M., Russell, R.D.: Numerical Solution of Boundary Value Problems for Ordinary Differential Eqautions. Classics in Applied Mathematics, vol. 13. Cambridge University Press, Cambridge (1995)

5.

Powers, D.L.: Boundary Value Problems, 6th edn. Academic, San Diego (2009)

6.

Polyanin, A.D., Zaitsev, V.F.: Boundary Value Problems, 2nd edn. Chapman & Hall/CRC, Boca Raton (2003)

7.

Hairer, E., Nørsett, S.P., Wanner, G.: Solving Ordinary Differential Equations I, 2nd edn. Springer Series in Computational Mathematics, vol. 8. Springer, Berlin/Heidelberg (1993)

8.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)

9.

Courant, R., Hilbert, D.: Methods of Mathematical Physics, vol. 1. Wiley, New York (1989)

10.

Baym, G.: Lectures on Quantum Mechanics. Lecture Notes and Supplements in Physics. The Benjamin/Cummings, London/Amsterdam (1969)

11.

Cohen-Tannoudji, C., Diu, B., Laloë, F.: Quantum Mechanics, vol. I. Wiley, New York (1977)

12.

Sakurai, J.J.: Modern Quantum Mechanics. Addison-Wesley, Menlo Park (1985)

13.

Abramovitz, M., Stegun, I.A. (eds.): Handbook of Mathemathical Functions. Dover, New York (1965)

14.

Olver, F.W.J., Lozier, D.W., Boisvert, R.F., Clark, C.W.: NIST Handbook of Mathematical Functions. Cambridge University Press, Cambridge (2010)

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_9

9. The One-Dimensional Stationary Heat Equation

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

9.1 Introduction

This is the first of two chapters which illustrate the applicability of the methods introduced in Chap. 8 Within this chapter the finite difference approach is employed to solve the stationary heat equation. Let us motivate briefly this particular problem. We consider a rod of length L which is supposed to be kept at constant temperatures T ₀ and T N at its ends as illustrated in Fig. 9.1.

Fig. 9.1

We consider a rod of length L. Its ends are kept at constant temperatures T ₀ and T N , respectively

The homogeneous heat equation is a linear partial differential equation of the form

(9.1)

Here T(x, t) is the temperature as a function of space $$x \in \mathbb{R}^{3}$$ and time $$t \in \mathbb{R}$$, $$\varDelta = \nabla ^{2} = \partial _{x}^{2} + \partial _{y}^{2} + \partial _{z}^{2}$$ is the Laplace operator , and κ = const is the thermal diffusivity .

We remark, that Eq. (9.1) is a partial differential equation together with initial and boundary conditions. Moreover, we note in passing that the heat equation is equivalent to the diffusion equation [1]

(9.2)

with particle density ρ(x, t) and the diffusion coefficient D = const. Here we restrict ourselves to a simplified situation in order to test the validity of the finite difference approach discussed in Sect. 8.​2 The general solution of the heat or diffusion equation will be discussed in Sect. 11.​3 (The problem of the one-dimensional heat equation was studied in all conceivable detail by J. R. Cannon [2].)

If we assume that the cylindrical surface of the rod is perfectly isolated, we can restrict the problem to a one-dimensional problem. Furthermore, we assume that the steady-state has been reached, i.e. $$\frac{\partial } {\partial t}T(x,t) = 0$$. Hence, the remaining boundary value problem is of the form

(9.3)

The solution can easily be found analytically and one obtains

(9.4)

In the following section we will apply the approach of finite differences to the boundary value problem (9.3) as discussed in Sect. 8.​2

9.2 Finite Differences

We discretize the interval [0, L] according Chap. 2 by the introduction of N + 1 grid-points x n  = nh, with $$h = L/N$$, x ₀ = 0, and x N  = L. Furthermore, T n  ≡ T(x n ) and, in particular, we refer to the boundary conditions (9.3) as T ₀ and T N , respectively.

On the basis of this discretization, we approximate Eq. (9.3) by

(9.5)

or equivalently

(9.6)

We can rewrite this as a matrix equation,

(9.7)

where the boundary conditions have already been included. In Eq. (9.7) the vector $$T = (T_{1},T_{2},\ldots,T_{N-1})^{T}$$. Furthermore, the tridiagonal matrix A is given by

(9.8)

and the vector F by

(9.9)

It is an easy task to solve Eq. (9.7) analytically. It follows from Eq. (9.6) that

(9.10)

We insert n = 1, 2, 3 in order to obtain

(9.11)

(9.12)

(9.13)

We recognize the pattern and conclude that T n has the general form

(9.14)

which we prove by complete induction:

(9.15)

Hence, expression (9.14) is valid for all n = 1, …, N. However, since T N is kept constant according to the boundary condition, we can determine T ₁ from

(9.16)

which yields

(9.17)

Inserting (9.17) into (9.14) gives

(9.18)

which is exactly the discretized version of Eq. (9.4). Hence the finite difference approach to the boundary value problem (9.3) is exact and independent of the grid-spacing h. This is not surprising since we proved already in Chap. 2 that finite difference derivatives are exact for linear functions.

9.3 A Second Scenario

We consider the inhomogeneous heat equation

(9.19)

Here Γ(x, t) ≡ Γ(x) is some heat source or heat drain , which is assumed to be independent of time t. Again, we consider the one dimensional, stationary case, i.e.

(9.20)

with the same boundary conditions as in Eq. (9.4). Furthermore, we assume Γ(x) to be of the form

(9.21)

i.e. Γ(x) has the form of a Gauss peak which is centered at $$x = L/2$$ and has a width determined by the parameter ℓ and a maximum height given by the constant $$\varTheta$$. Such a situation might occur, for instance, when the rod is heated with some kind of a heat gun or cooled by a cold spot. (In cases where the diffusion equation (9.2) is used to describe the random motion of electrons in some device, one can imagine, that the density of electrons ρ is constant at the contacts at x = 0 and x = L. The source/drain term Γ(x) then accounts for a constant generation or recombination rate of electrons, for instance, through incoming light or intrinsic traps, respectively [3].)

Furthermore, we note that in the limiting case ℓ → 0 we have

(9.22)

where δ(⋅ ) is the Dirac δ-distribution; in this case the spatial extension of the source/drain term Γ(x) is infinitesimal.

We now employ the results of Sect. 8.​2 and rewrite the system of equations in the familiar form¹

(9.23)

where A has already been defined in Eq. (9.8), $$T = (T_{1},T_{2},\ldots,T_{N-1})^{T}$$, and F is given by

(9.24)

Here we used the notation Γ n  ≡ Γ(x n ).

The system is solved numerically quite easily using methods discussed by

Press et al. [4] for the solution of sets of algebraic equations of the kind (9.24) with tridiagonal matrix A. We chose L = 10, κ = 1, $$\varTheta = -0.4$$, ℓ = 1, T ₀ = 0 and T N  = 2. The resulting temperature profiles T(x) (solid line) for different values of N can be found in Figs. 9.2, 9.3, and 9.4 as well

Fig. 9.2

Temperature profile T(x) (solid line, left hand scale) and the source function Γ(x) (dashed line, right hand scale) for N = 5

Fig. 9.3

Temperature profile T(x) (solid line, left hand scale) and the source function Γ(x) (dashed line, right hand scale) for N = 10

Fig. 9.4

Temperature profile T(x) (solid line, left hand scale) and the source function Γ(x) (dashed line, right hand scale) for N = 100

as the respective form of the function Γ(x) (dashed line). With increasing number of steps we see, as it was to be expected, a refinement of the temperature profile. Its maximum does not quite agree with the minimum of Γ(x), it is shifted slightly towards the end of the rod because of the boundary conditions, i.e. T ₀ < T N .

Summary

The methods of Sect. 8.​2 were applied to find the numerical solution of the stationary heat equation with Dirichlet boundary conditions. We studied the particular case of an isolated rod of length L. This reduced the dimensionality of the differential equation to one. The length of the rod was then divided into N discrete grid-points. Using finite differences the one-dimensional ordinary second order differential equation which described this particular problem was transformed into a set of linear algebraic equations which determined the temperatures at each grid-point. This set of algebraic equations was characterized by a tridiagonal coefficient matrix. Solutions have been studied without and with a heat source which was described as a ‘point’ source characterized by a Gaussian of given width and amplitude. In the first case analytic solutions were easily derived. They described a linear temperature profile increasing (decreasing) from T ₀ to T N . In the latter case solutions were generated numerically using specific algorithms designed for sets of algebraic equations with a tridiagonal coefficient matrix A.

Problems

1.

Calculate the stationary temperature profile across the cylindrical rod of Fig. 9.1 which is exposed to a heat sink centered around $$x = L/2$$. This heat sink is described by a function Γ(x) which is of rectangular shape of width a and depth $$\theta$$. Both ends of the rod are kept at constant temperatures T ₀ and T N , respectively.

2.

Investigate the three cases T ₀ > T N , T ₀ < T N , T ₀ = T N  > 0, and study the influence of the width a of the heat sink on the temperature profile.

3.

Consider the one-dimensional drift-diffusion equation [5]

where D ₁ is the drift constant and D ₂ the diffusion constant. For instance, if we want to model the electron density in an electronic device, the drift constant would be in the simplest case D ₁ = μ E, where μ is the charge carrier mobility and E is the x-component of the electric field.

Discretize the above equation for the stationary case and solve it numerically for different values of D ₁. The boundary conditions are ρ(0) > 0 and ρ(L) > ρ(0), where L denotes the length of the device. Solve it numerically and analytically for Γ(x) = 0 and compare the results. Investigate also a scenario with a generation rate Γ given by an exponential function like $$\varGamma (x) =\varGamma _{0}\exp \left (-\lambda x\right )$$ with $$\lambda&gt; 0$$.

References

1.

Cussler, E.L.: Diffusion. Cambridge University Press, Cambridge (2009)

2.

Cannon, J.R.: The One-Dimensional Heat Equation. Encyclopedia of Mathematics and Its Applications. Cambridge University Press, Cambridge (1985)

3.

Glicksman, M.E.: Diffusion in Solids. Wiley, New York (1999)

4.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)

5.

Jüngel, A.: Drift-Diffusion Equations. Lecture Notes in Physics, vol. 773. Springer, Berlin/Heidelberg (2009)

Footnotes

1

We note that Eq. (9.20) can also be solved with the help of Fourier transforms, see Appendix D.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_10

10. The One-Dimensional Stationary Schrödinger Equation

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

10.1 Introduction

The numerical solution of the stationary Schrödinger equation is discussed to illustrate the application of Numerov’s shooting method introduced in Sect. 8.​3

We start the discussion with a brief survey of basic quantum mechanics. Of course, this chapter is not supposed to give a self-contained introduction into this field and the reader not familiar with quantum mechanics should, therefore, regard the following discussion from a purely mathematical point of view. For more in-depth reading on quantum mechanics we refer to the books [1–4] to name a few.

A quantum-mechanical wave-function $$\varPsi \equiv \varPsi (x,t) \in \mathbb{C}$$ is a function of time $$t \in \mathbb{R}^{+}$$ and space $$x \in \mathbb{R}^{3}$$ and obeys the Schrödinger equation:

(10.1)

Here, $$\hslash = h/(2\pi )$$ is the reduced Planck constant, i is the imaginary unit, and H is the Hamilton operator or Hamiltonian . If H ≠ H(t), i.e. the Hamiltonian is independent of time t, we can employ a product ansatz

(10.2)

where E is the energy and ψ(x) is the time-independent part of the wave-function. This ansatz transforms Eq. (10.1) into

(10.3)

and ψ(x) is determined by the eigenvalue problem [5]

(10.4)

augmented by appropriate boundary conditions. We already came across Eq. (10.4) when we discussed shooting methods in Sect. 8.​3

The one-particle Hamiltonian is of the general form

(10.5)

with the kinetic energy operator T, the potential operator V, the momentum operator P, and the particle’s mass m. If the system is not exposed to an external magnetic field, P can be expressed in position space by

(10.6)

and the potential operator V by V (x). Thus we get for Eq. (10.5):

(10.7)

Hence, we have to solve the linear, second order partial differential equation:

(10.8)

This equation will certainly not have solutions for arbitrary values of the energy E. The particular values E = E n ¹ for which it has a solution are referred to as eigenenergies and the corresponding solution ψ n (x) is referred to as eigenfunction to the eigenenergy E n [1–3, 5]. To emphasize this point we rewrite Eq. (10.8) as:

(10.9)

It is the purpose of this chapter to develop a numerical procedure which will, in the end, allow to calculate numerically the eigenvalues E n and eigenfunctions ψ n (x) as solutions of this equation.

We proceed in our analysis by defining the scalar product between two functions χ(x) and $$\varphi (x)$$

(10.10)

where χ ∗(x) denotes the complex conjugate of χ(x). The corresponding L ²-norm reads

(10.11)

The expectation value of an operator O in the quantum mechanical state Ψ is given by

(10.12)

It follows from Eq. (10.4) that the energy is the expectation value of the Hamiltonian H

(10.13)

We quote now some important properties; a detailed discussion can be found in any textbook on quantum mechanics.

The expectation value $$\left \langle O\right \rangle$$ of a Hermitian operator O, O † = O, is real, i.e. $$\left \langle O\right \rangle = \left \langle O\right \rangle ^{{\ast}}$$. Here O † denotes the adjoint of O, i.e. O † = (O ∗) T .

Every real expectation value can be described by a Hermitian operator.

All observables can be described by Hermitian operators, in particular, the Hamiltonian has to be a Hermitian operator to ensure that the eigenenergies E n are real, $$E_{n} \in \mathbb{R}$$.

It follows from the hermiticity of H that the eigenfunctions ψ n (x) form a complete, orthogonal basis in Hilbert space [5]. Furthermore, the functions can be normalized and the relation

(10.14)

holds, with δ nm the Kronecker-δ.

Thus, with the help of Eq. (10.14) we rewrite the expectation value (10.12) of a Hermitian operator O as:

(10.15)

In a next step we define the wave function Ψ n (x, t) following the ansatz (10.2)

(10.16)

and the total wave-function Ψ(x, t) is then a superposition of wave-functions Ψ n (x, t)

(10.17)

because the Ψ n (x, t) constitute a complete, orthogonal basis.² Furthermore, we demand Ψ(x, t) to be normalized for all t. Employing Eq. (10.14) in Eq. (10.17) yields

(10.18)

We quote Born’s interpretation of the squared modulus of the total wave-function (referred to as Born’s rule):

(10.19)

This interpretation justifies the requirement of a normalization of the wave-function Ψ(x, t)

(10.20)

because, by definition, the particle has to be found somewhere anytime.

Suppose we start with an initial state $$\chi (x) =\varPsi (x,t = 0)$$. Since the functions ψ n (x) form a complete basis in Hilbert space, χ(x) may be written with the help of Eq. (10.17) as

(10.21)

We deduce from Eq. (10.14) that

(10.22)

Consequently, $$\vert c_{m}\vert ^{2}$$ is the probability that the particle was initially in state m. This allows us to interpret Eq. (10.17) in the following way: The coefficients c m determine the composition of the initial state. The exponential factor describes an oscillation and we note that different eigenfunctions, which correspond to different eigenenergies, oscillate with different frequencies. This can, for instance, induce the diffluence of a wave packet.

10.2 A Simple Example: The Particle in a Box

We concentrate on the one-dimensional Schrödinger equation and discuss a simple problem which will then be solved numerically in Sect. 10.3. We rewrite the one-dimensional Schrödinger equation (10.7), with $$x \in \mathbb{R}$$, as

(10.23)

and specify

(10.24)

together with the boundary conditions

(10.25)

and the normalization condition

(10.26)

We note that the boundary conditions are dictated by the particular form of the potential (10.24) which requires that ψ n (x) = 0 for x ∉ [0, L]. This problem is commonly referred to as the particle in a one-dimensional box.

Let us introduce dimensionless variables in order to simplify the numerics of Eq. (10.23). We define new variables

(10.27)

where L is the length scale and $$\overline{E}$$ is the energy scale. The energy scale $$\overline{E}$$ is fully determined by the relation

(10.28)

We note that s ∈ [0, 1], hence the rescaled wave-function is given by

(10.29)

which satisfies the normalization condition

(10.30)

The rescaled Schrödinger equation can be obtained by multiplying Eq. (10.23) with $$1/\overline{E}$$:

(10.31)

Here we introduced the rescaled potential v(s)

(10.32)

Hence, the rescaled wave-function (10.29) is a solution of the differential equation:

(10.33)

The form (10.32) of the potential implies that $$\varphi _{n}(s) = 0$$ for all s ∉ [0, 1] and the complete boundary value problem is defined as:

(10.34)

It is an easy task to solve this boundary value problem analytically. For s ∈ [0, 1] we choose the ansatz

(10.35)

where A n and B n are some constants and k n is given by

(10.36)

From the boundary conditions we obtain

(10.37)

and

(10.38)

Thus,

(10.39)

and the eigenenergies $$\varepsilon _{n}$$ are quantized:

(10.40)

The corresponding eigenfunctions $$\varphi _{n}(s)$$ are then given by:

(10.41)

The constants A n are determined from the normalization condition (10.30)³

(10.43)

and:

(10.44)

Finally, we apply the relations (10.27), (10.28), and (10.29) and obtain

(10.45)

and

(10.46)

In most cases expectation values of some observables are to be determined. We might, for instance, be interested in the expectation value $$\left \langle x\right \rangle$$ of the position operator x or its variance $$\text{var}\left (x\right ) = \left \langle (x -\left \langle x\right \rangle )^{2}\right \rangle$$ (see also Appendix E). It follows from Eq. (10.27) that

(10.47)

Definition (10.15) gives together with solution (10.41) the expectation value $$\left \langle s\right \rangle$$:

(10.48)

Thus, the expectation value of the position operator is independent of the quantum number n. Furthermore, we obtain for $$\left \langle s^{2}\right \rangle$$:

(10.49)

Hence, the variance $$\text{var}\left (s\right )$$ is determined by

(10.50)

We note that the variance increases with increasing n.

In the next section these results are reproduced numerically by the Numerov shooting method . (See Sect. 8.​3 and, for instance, Ref. [6].) Moreover, this numerical formulation will allow us to find solutions for more complex potentials V (x).

10.3 Numerical Solution

The following discussion is based on the scaled Schrödinger equation (10.33), but we consider now a more general potential of the form

(10.51)

which results in the boundary value problem:

(10.52)

As our numerical treatment will be based on shooting methods, discussed in Sect. 8.​3, the second order differential equation in Eq. (10.52) will be transformed into a form which corresponds to Eq. (8.​54), namely:

(10.53)

The interval [0, 1] is discretized using N + 1 grid-points $$s_{\ell} =\ell /N$$, ℓ = 0, 1, 2, …, N ($$h = 1/N$$) and we denote with $$\varphi _{n}(s_{\ell})$$ and $$\tilde{v}(s_{\ell}) \equiv v_{\ell}$$ the values of $$\varphi _{n}(s)$$ and $$\tilde{v}(s)$$ at those grid-points. Thus, Eq. (8.​59) can immediately be applied and we get:

(10.54)

We use the initial conditions $$\varphi _{n}(s_{0}) = 0$$ and $$\varphi _{n}'(s_{0}) = 1$$, which is always possible, since (10.52) is a homogeneous boundary value problem . This gives

(10.55)

The normalization of the wave-function (10.30) is then approximated with the help of the forward rectangular rule (3.​9):

(10.56)

Consistently, we approximate the expectation value $$\left \langle s\right \rangle$$ via

(10.57)

The Numerov shooting algorithm is then defined by the following steps:

1.

Choose two trial energies $$\varepsilon _{a}$$ and $$\varepsilon _{b}$$ and define the required accuracy η.

2.

Calculate $$\varphi (s_{N};\varepsilon _{a}) \equiv \varphi _{a}$$ and $$\varphi (s_{N};\varepsilon _{b}) \equiv \varphi _{b}$$ using Eq. (10.54).

3.

If $$\varphi _{a}\varphi _{b}&gt; 0$$, choose new values for $$\varepsilon _{a}$$ or $$\varepsilon _{b}$$ and go to step 1.

4.

If $$\varphi _{a}\varphi _{b} &lt;0$$, calculate $$\varepsilon _{c} = \left (\varepsilon _{a} +\varepsilon _{b}\right )/2$$ and determine $$\varphi (s_{N};\varepsilon _{c}) \equiv \varphi _{c}$$ using Eq. (10.54).

5.

If $$\varphi _{a}\varphi _{c} &lt;0$$, set $$\varepsilon _{b} =\varepsilon _{c}$$ and go to step 4.

6.

If $$\varphi _{c}\varphi _{b} &lt;0$$, set $$\varepsilon _{a} =\varepsilon _{c}$$ and go to step 4.

7.

Terminate the loop when $$\vert \varepsilon _{a} -\varepsilon _{b}\vert &lt;\eta$$.

These steps have been carried out for 100 grid-points, a potential $$\tilde{v} = 0$$, and a required accuracy of $$\eta = 10^{-10}$$. The first ten eigenenergies

Table 10.1

Comparison between analytic and numerical eigenenergies for the particle in a box for N = 100

n

$$\varepsilon _{n}$$-analytic

$$\varepsilon _{n}$$-numeric

1

4.934802

4.934802

2

19.739209

19.739208

3

44.413219

44.413205

4

78.956835

78.956753

5

123.370055

123.369742

6

177.652879

177.651943

7

241.805308

241.802947

8

315.827341

315.822077

9

399.718978

399.708300

10

493.480220

493.460113

are given in Table 10.1 and are compared with analytic results (10.40).

In addition, Fig. 10.1 presents the first five eigenvalues $$\varepsilon _{n}$$ (right

Fig. 10.1

The first five numerically determined eigenvalues $$\varepsilon _{n}$$ of Table 10.1 are presented as horizontal lines (left hand scale). Aligned with these eigenvalues are the corresponding eigenfunctions $$\varphi _{n}(s)$$ vs s for N = 100 (right hand scales)

hand scale) as horizontal straight lines. Aligned with these eigenvalues we find on the right hand side of this figure the corresponding normalized eigenfunctions calculated using N = 100 grid-points. The agreement with the analytic result of Eq. (10.41) is excellent.

10.4 Another Case

Here we discuss briefly some results achieved with the help of Numerov’s shooting algorithm. In particular, we discuss the particle in the box for three different potentials $$\tilde{v}(s)$$

(10.58)

The potentials are illustrated in Fig. 10.2. All calculations were carried out with N = 100 grid-points and an accuracy $$\eta = 10^{-10}$$. The first five eigenenergies $$\varepsilon _{n}$$ are shown in Figs. 10.3, 10.4, and 10.5, respectively,

Fig. 10.2

The three different potentials $$\tilde{v}(s)$$ defined in Eq. (10.58)

Fig. 10.3

Numerically determined eigenvalues $$\varepsilon _{n}$$ (left hand scale) and eigenfunctions $$\varphi _{n}(s)$$ vs s (right hand scales) for the potential $$\tilde{v}_{1}(s)$$. The first five eigenvalues are presented as straight horizontal lines. Aligned with these lines the eigenfunctions are shown on the right hand side of this figure. The dotted lines indicate the eigenfunctions of the particle in the box with $$\tilde{v}(s) = 0$$ (see Fig. 10.1)

Fig. 10.4

Numerically determined eigenvalues $$\varepsilon _{n}$$ (left hand scale) and eigenfunctions $$\varphi _{n}(s)$$ vs s (right hand scales) for the potential $$\tilde{v}_{2}(s)$$. The first five eigenvalues are presented as straight horizontal lines. Aligned with these lines the eigenfunctions are shown on the right hand side of this figure. The dotted lines indicate the eigenfunctions of the particle in the box with $$\tilde{v}(s) = 0$$ (see Fig. 10.1)

Fig. 10.5

Numerically determined eigenvalues $$\varepsilon _{n}$$ (left hand scale) and eigenfunctions $$\varphi _{n}(s)$$ vs s (right hand scales) for the potential $$\tilde{v}_{3}(s)$$. The first five eigenvalues are presented as straight horizontal lines. Aligned with these lines the eigenfunctions are shown on the right hand side of this figure. The dotted lines indicate the eigenfunctions of the particle in the box with $$\tilde{v}(s) = 0$$ (see Fig. 10.1)

as horizontal lines (left hand scale). The numerically determined normalized eigenfunctions $$\varphi _{n}(s)$$ vs s (solid lines) are presented on the right hand side of these figures and are aligned with their respective eigenvalues. They are also compared with the eigenfunctions (dotted lines) of the particle in a box, i.e. $$\tilde{v}(s) = 0$$. In all cases the eigenfunctions reflect the symmetry of the various potentials $$\tilde{v}(s)$$ which becomes particularly transparent in Fig. 10.3 for the potential $$\tilde{v}_{1}(s)$$. The eigenfunctions develop an additional node in comparison to the eigenfunctions calculated for $$\tilde{v}(s) = 0$$. In the other two cases only the very first eigenfunctions n ≥ 3 appear to be affected by the potential. Moreover, in all three cases, the respective eigenvalues are shifted towards higher values which is consistent with a general result of quantum mechanical perturbation theory.

Summary

The quantum-mechanical problem of a particle in a box was described by a homogeneous boundary value problem which could be solved analytically if the box’ potential $$\tilde{v}(s) = 0$$. On the other hand, Numerov’s shooting algorithm was particularly designed to treat effectively homogeneous boundary value problems. Consequently, the problem of the particle in the box was used to design a Numerov shooting algorithm which was then tested against the analytic results. The agreement between numerics and analytical results turned out to be excellent and proved the quality of the method. For illustrative purposes the problem of the particle in the box was then solved numerically for three different, more complex, box-potentials $$\tilde{v}(s)$$.

Problems

1.

Solve the one-dimensional stationary Schrödinger equation in an infinitely deep potential well by employing the shooting method according to Numerov of Sect. 8.​3 The total potential v(s) is assumed to be of the form (10.51). Choose different potentials $$\tilde{v}(s)$$ within the well.

You can check your code by reproducing the results presented in Sects. 10.3 and 10.4. In addition, determine numerically the expectation value $$\left \langle x\right \rangle$$ and the variance $$\text{var}\left (x\right )$$ of the position operator x for the first five eigenfunctions. This can be achieved by employing the rectangular rule of Chap. 3, as illustrated in Eq. (10.57).

2.

Solve the Schrödinger equation for some potential $$\tilde{v}(s)$$ of your choice and plot the first five eigenfunctions. This potential should not be equal to one of the potentials discussed in this chapter. Again, calculate $$\left \langle x\right \rangle$$ and $$\text{var}\left (x\right )$$ for the first five eigenfunctions.

3.

Solve the stationary Schrödinger equation (10.4) for the harmonic potential $$V (x) = m\omega ^{2}x^{2}/2$$. The algorithm discussed in this chapter can be applied by choosing the box length L sufficiently large, so that the harmonic oscillator potential is well within the box for all energies of interest.

4.

Solve the Schrödinger equation for a double well potential which can be obtained by adding two mutually displaced harmonic potentials.

References

1.

Baym, G.: Lectures on Quantum Mechanics. Lecture Notes and Supplements in Physics. The Benjamin/Cummings Publ. Comp., Inc., London/Amsterdam (1969)

2.

Cohen-Tannoudji, C., Diu, B., Laloë, F.: Quantum Mechanics, vol. I. Wiley, New York (1977)

3.

Sakurai, J.J.: Modern Quantum Mechanics. Addison-Wesley, Menlo Park (1985)

4.

Ballentine, L.E.: Quantum Mechanics. World Scientific, Hackensack (1998)

5.

Courant, R., Hilbert, D.: Methods of Mathematical Physics, vol. 1. Wiley, New York (1989)

6.

Hairer, E., Nørsett, S.P., Wanner, G.: Solving Ordinary Differential Equations I. Springer Series in Computational Mathematics, vol. 8, 2nd edn. Springer, Berlin/Heidelberg (1993)

Footnotes

1

It depends on the problem on hand whether or not the index n will be continuous or discrete. For simplicity, we assume here n to be discrete.

2

This is only possible because the Schrödinger equation is linear.

3

Here we make use of

(10.42)

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_11

11. Partial Differential Equations

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

11.1 Introduction

This section discusses some fundamental aspects of the numerics of partial differential equations and it will be restricted to methods already encountered in previous chapters, i.e. on finite difference methods. These are particularly useful to find solutions of linear partial differential equations (PDEs). Nonlinear PDEs, such as the Navier-Stokes equations, require more advanced techniques as there are finite element methods or finite volume methods for conservation laws. A detailed discussion of a wide spectrum of methods can be found in many textbooks on the numerics of PDEs the interested reader is referred to [1–7].

Since we already introduced the concepts of finite difference derivatives in Chap. 2 and their application to boundary value problems of ordinary differential equations in Sect. 8.​2, we concentrate mainly on the application of these methods to specific types of PDEs. In detail, we investigate the Poisson equation as an example for elliptic PDEs , the time dependent heat equation as an example for parabolic PDEs, and the wave equation as an example for hyperbolic PDEs . The concepts presented here are, of course, also applicable to other problems. However, in contrast to the numerics of ordinary differential equations, there exists no general recipe for the solution of PDEs.

Another important point to note is that, as in the theory of ordinary differential equations, the problem is only fully determined when initial and/or boundary conditions have been defined. For instance, in the case of the Poisson equation only boundary conditions are required, while for the time-dependent heat equation initial conditions are required as well. In general, pure boundary value problems are easier from a numerical point of view because the question whether or not the algorithm is stable does not play such an important role. For combined boundary and initial value problems it is essential to check carefully that the discretization of the time axis is not in conflict with the discretization of the space domain. This is of particular importance in the numerical treatment of hyperbolic PDEs, where the so called Courant-Friedrichs-Lewy (CFL) condition determines the stability of the algorithm. We shall come back to this point in Sects. 11.3 and 11.4. Finally, we conclude this chapter with a discussion of the numerical solution of the time-dependent Schrödinger equation.

11.2 The Poisson Equation

We consider the Poisson equation as a model for an elliptic PDE [8, 9]. Nevertheless, we review briefly some basics of electrodynamics [10, 11]. The force F(r, t) as a function of position $$r \in \mathbb{R}^{3}$$ and time $$t \in \mathbb{R}^{+}$$ acting on a particle with charge q, which moves with velocity v within an electromagnetic field described by the electric field E(r, t) and the magnetic field B(r, t), is determined from:

(11.1)

We consider here the electrostatic case which is characterized by a zero magnetic field [B(r, t) = 0] and a time independent electric field. The electric field E itself is described by the equation

(11.2)

where the charge density ρ(r, t) acts as the source of the electric field E(r, t). Here ε ₀ is the dielectric permittivity of vacuum. Furthermore, the electric field E is connected to the electrostatic potential $$\varphi (r)$$ via

(11.3)

Thus, Eq. (11.2) is reformulated as:

(11.4)

This equation is referred to as the Poisson equation and in the particular case of ρ(r) = 0 it is referred to as the Laplace equation [12].

We focus now on the numerical solution of the two dimensional Poisson equation (11.4) on a rectangular domain Ω = [0, L x ] × [0, L y ] together with boundary conditions $$\varphi (x,y) = g(x,y)$$ on ∂ Ω. In detail, we want to solve the two-dimensional boundary value problem

(11.5)

where we absorbed ε ₀ into the charge density ρ(x, y). Note that a treatment of the three dimensional case can be carried out in analogue.

We employ a finite difference approximation to the derivatives which appear in Eq. (11.5) (see Chap. 2) and we define grid-points in x and y direction via

(11.6a)

(11.6b)

where h x and h y denote the grid-spacing in x- and y-direction, respectively. As discussed in Chap. 2 we consider only equally spaced grid-points. An extension to non-uniform grids is straight forward.

We define the function values on the grid-points as

(11.7)

and similarly ρ i, j  ≡ ρ(x i , y j ). Consequently, we find the finite difference approximation of Eq. (11.5):

(11.8)

The boundary conditions (11.5) can be written as

(11.9a)

(11.9b)

(11.9c)

(11.9d)

Equation (11.8) is multiplied by $$-h_{x}^{2}h_{y}^{2}/2$$ and we obtain after rearranging terms

(11.10)

for i = 1, …, n and j = 1, …, m. There are different strategies how this set of equations might be solved. The common strategy is to employ the assignments

(11.11)

where ℓ = nm. Equation (11.10) is then rewritten as a matrix equation with a vector of unknowns $$\varphi = (\varphi _{1},\varphi _{2},\ldots,\varphi _{\ell})^{T}$$ according to Eq. (11.11). The boundary conditions are to be included in the matrix. This matrix equation is then solved either by direct or iterative methods as they are discussed in Appendix C.

It is our plan to solve Eq. (11.10) iteratively. This requires the introduction of a superscript iteration index t and $$\varphi _{i,j}^{t}$$ denotes the function value $$\varphi (x_{i},y_{j})$$ after t-iteration steps. There are two different implementations of an iterative solution, namely the Gauss-Seidel or the Jacobi method (Appendix C). They differ only in the update procedure of the function values $$\varphi _{i,j}^{t}$$ at the grid-points. The basic idea is to develop an update algorithm which expresses the function values $$\varphi _{i,j}^{t}$$ with the help of function values at already updated grid-points and of function values $$\varphi _{i,j}^{t-1}$$ determined in the preceding iteration step [Appendix, Eq. (C.27)].

We formulate this iteration rule as

(11.12)

where we abstained from incorporating a relaxation parameter (see Appendix C). Note that by using the iteration rule (11.12) the boundary conditions have to be accounted for in an additional step.

Let us specify the boundary conditions for a concrete problem: We we want to determine the electrostatic potential of an electric monopole, dipole, and quadrupole, respectively. They are placed inside a grounded box of dimensions L x and L y . Thus, we have to impose Dirichlet boundary conditions $$\varphi (0,y) =\varphi (L_{x},y) = 0$$ in x-direction and $$\varphi (x,0) =\varphi (x,L_{y}) = 0$$ in y-direction. In this particular case the boundary conditions can be made part of Eq. (11.12) by restricting the loop over the x-grid (y-grid) to $$i = 2,\ldots,N - 1$$ which leaves the boundary points $$\varphi (0,y)$$ [$$\varphi (x,0)$$] and $$\varphi (L_{x},y)$$ [$$\varphi (x,L_{y})$$] unchanged. Furthermore we set $$L_{x} = L_{y} = 10$$, the number of grid-points on both axes to $$n = m = 100$$, and define the domains:

(11.13a)

(11.13b)

(11.13c)

(11.13d)

The charge density ρ(x, y) is described by three different scenarios, namely the electric monopole

(11.14a)

the electric dipole

(11.14b)

and the electric quadrupole:

(11.14c)

These charge densities are illustrated in Fig. 11.1.

Fig. 11.1

The electric monopole, dipole, and quadrupole charge densities (a) ρ ₁(x, y), (b) ρ ₂(x, y), and (c) ρ ₃(x, y), respectively, as defined in Eq. (11.14)

The solution of Eq. (11.12) is regarded to be converged if the potential $$\varphi (x,y)$$ does not change significantly between two consecutive iteration steps, i.e.

(11.15)

where $$\eta = 10^{-4}$$ is the required accuracy. A criterion to check the relative change can be formulated in a similar fashion. The resulting potential profiles $$\varphi (x,y)$$ are presented in Fig. 11.2. They reflect perfectly the symmetries of the charge densities ρ ₁(x, y), ρ ₂(x, y), and ρ ₃(x, y), respectively. Finally, standard finite difference methods can be applied to calculate, based on Eq. (11.3), the electric field E(x, y) from the potential profiles $$\varphi (x,y)$$.¹

Fig. 11.2

Potential profile $$\varphi (x,y)$$ obtained for charge density (a) ρ ₁(x, y), (b) ρ ₂(x, y), and (c) ρ ₃(x, y)

11.3 The Time-Dependent Heat Equation

We discuss here the numerical solution of the time-dependent heat equation [13, 14] which is a representative of parabolic PDEs. This equation has already been introduced in Sect. 9.​1, Eq. (9.​1), and is, reduced to the one-dimensional case, of the form

(11.16)

with the thermal diffusivity κ. It is augmented by appropriate boundary and initial conditions. Again, we will not discuss the extension to higher dimensions since it is straight forward, however, maybe tedious in the general case. We approximate the right hand side of Eq. (11.16) with the help of the central finite difference approximation (Sect. 2.​2) and obtain

(11.17)

with the usual discretization $$x_{k} = x_{0} + kh$$, $$k = 0,\ldots,N$$, in combination with the notation T k (t) ≡ T(x k , t).

The time derivative in Eq. (11.17) can be approximated with the help of methods already discussed in Chap. 5 In particular, one has to decide whether the solution of Eq. (11.17) should be approximated by an explicit or an implicit integrator. In order to emphasize the differences between the two methods, the application of the explicit Euler and of the implicit Euler method will be studied. However, more complex integrators may be applied as well. In particular, the Crank-Nicolson method [15] proved to be very useful for the solution of parabolic differential equations.

We define $$t_{n} = t_{0} + n\varDelta t$$ and T k n  ≡ T k (t n ) and employ the explicit Euler scheme (5.​9) in Eq. (11.17) to get

(11.18)

with the solution:

(11.19)

The right hand side of this equation depends only on temperatures of the previous time step, since we used an explicit method. Although this might seem advantageous on a first glance, it turns out that the above scheme is not stable for arbitrary choices of Δ t and h. In particular, it is possible to prove that the above discretization is stable only for

(11.20)

A detailed discussion and proof of this property can be found in any advanced textbook on numerics of PDEs [1–5].

On the other hand, if we apply the implicit Euler method  (5.​10) to solve Eq. (11.17) we obtain

(11.21)

which is unconditionally stable. However, Eq. (11.21) is an implicit equation, i.e. the function values $$T_{k+1}^{n+1}$$ and $$T_{k-1}^{n+1}$$ are required in order to evaluate $$T_{k}^{n+1}$$. Hence, Eq. (11.21) has to be solved as a system of linear equations. This system may be written as

(11.22)

with the vector T n  = (T ₀ n , T ₁ n , …, T N n ) T and the tridiagonal matrix A:

(11.23)

The boundary conditions are incorporated in the matrix A and in the vector F. (See Sects. 9.​2 and 9.​3) The linear system of equations (11.22) can be solved numerically using a direct or an iterative method. Employing an iterative method, imposes a third index t on the function values of the temperature T which accounts for the iteration step.

Let us give a brief numerical example. We consider the time-dependent homogeneous heat equation (11.16) on a finite interval [0, L] together with the boundary conditions of Sect. 9.​1:

(11.24)

In addition we introduce the initial condition

(11.25)

Figure 11.3 presents the time evolution of T(x, t) at six different time-steps as it was obtained with the explicit Euler method (11.19). Here we chose T ₀ = 0, T N  = 2, N = 20, L = 10, κ = 1 as well as Δ t ≈ 0. 5. Note that for this choice of parameters, the condition (11.20) is fulfilled since h ≈ 1. 05 and therefore

(11.26)

Figure 11.4 corresponds to Fig. 11.3 but now Δ t was chosen to be approximately 0. 7 and:

(11.27)

Thus, the stability criterion was violated and the solutions became unstable. Finally, Fig. 11.5 presents results obtained with the same parameters as for Fig. 11.4 but with the help of the implicit Euler method  (11.21). Obviously, this procedure provides a stable solution of the problem.

Fig. 11.3

Solutions of the time-dependent heat equation T(x) vs x generated by the explicit Euler method. The stability criterion (11.20) is fulfilled. Results after n = 25, 50, 100, 150, and 300 time steps are presented. n = 0 represents the initial conditions

Fig. 11.4

Solutions of the time-dependent heat equation T(x) vs x generated by the explicit Euler method. The stability criterion (11.20) is not fulfilled and, therefore, the solution is apparently unstable. Results after n = 25, 50, 100, 150, and 200 time steps are presented. n = 0 represents the initial conditions

Fig. 11.5

Solutions of the time-dependent heat equation T(x) vs x generated by the implicit Euler method. Results after n = 25, 50, 100, 150, and 300 time steps are presented. n = 0 represents the initial conditions

11.4 The Wave Equation

As a model hyperbolic PDE we consider briefly the wave equation [16]. Again, we regard only the one-dimensional case:

(11.28)

Here, c is the speed at which the wave u(x, t) propagates. Equation (11.28) is to be augmented by appropriate boundary and initial conditions. A finite difference approach similar to the one discussed in Sect. 11.3 will be employed and the discussion will be restricted to the explicit Euler approximation. Consequently, Eq. (11.28) is replaced by

(11.29)

We define the parameter $$\lambda = \frac{c\varDelta t} {h}$$ and solve Eq. (11.29) for u k n+1:

(11.30)

We note two important points: (i) The solution for time step n + 1 can only be determined if the solutions for the time steps n and n − 1 are known. In particular, the solutions for n = 0 and n = 1 are required to obtain the solution for n = 2. The function values for n = 1 can be obtained from the initial conditions which must include a first order time derivative of u(x, t) since Eq. (11.28) is a second order differential equation with respect to time t. (ii) As in the case of parabolic problems, the explicit Euler approximation (11.30) will not be stable for arbitrary values of $$\lambda$$. It is only stable for

(11.31)

This condition is referred to as the Courant-Friedrichs-Lewy or CFL condition [17, 18]. Its importance stems from the fact, that this condition is not limited to the wave equation but holds for hyperbolic problems in general. In particular, since the wave equation can always be viewed as a combination of a right- and a left-going advection equation, i.e.

(11.32)

we gain the very important property that explicit time integrators applied to solve equations of the type (11.32) are only stable if relation (11.31) is obeyed.

Let us return to the discretization (11.30). Suppose we have initial conditions of the form

(11.33)

They can be approximated by

(11.34)

and the solution of the second relation in (11.34) yields the desired function values for n = 1:

(11.35)

However, in many cases it is beneficial to take higher order terms into account. This can be achieved by employing a Taylor expansion of the form (Chap. 2):

(11.36)

We make now use of the initial conditions (11.33), employ the wave equation (11.28), and solve for u k ¹. This gives

(11.37)

Here we assumed that the second spatial derivative $$f''_{k} = \frac{\partial ^{2}} {\partial x^{2}} f(x_{k})$$ of the initial condition f(x) exists. It may then be approximated by a finite difference approach.

To be specific we consider a vibrating string of length L, which is fixed at its ends, i.e. $$u(0,t) = u(L,t) = 0$$. Furthermore, we assume that the string was initially at rest, i.e.

(11.38)

and impose initial conditions

(11.39)

Figure 11.6 presents results obtained with $$L = 1,c = 2$$, N = 100. Δ t was chosen in such a way that $$\lambda = 0.5$$. On the other hand, Fig. 11.7 presents calculations performed with the same parameters but now $$\lambda$$ was set to 1. 01. Thus, the CFL condition (11.31) was violated and the solutions become unstable.

Fig. 11.6

Solutions of the wave equation u(x) vs x generated by the explicit Euler method with $$\lambda = 0.5$$. Results after n = 25, 50, 100, 150, and 200 time steps are presented. n = 0 represents the initial conditions

Fig. 11.7

Solutions of the wave equation u(x) vs x generated by the explicit Euler method with $$\lambda = 1.01$$. Results after n = 25, 50, 100, 150, and 200 time steps are presented. n = 0 represents the initial conditions

In general, the numerical solution of hyperbolic PDEs can be very difficult to obtain since in many cases these equations represent conservation laws. A very popular class of methods in this context is referred to as finite volume methods. A detailed discussion of these methods can be found in the book by R. J. LeVeque [6].

11.5 The Time-Dependent Schrödinger Equation

We already came across the time-dependent Schrödinger equation in Chap. 10 It reads

(11.40)

where $$\hslash $$ is the reduced Planck constant, Ψ(x, t) is the wave function, and H is the Hamilton operator. Since the Schrödinger equation contains a complex coefficient, it cannot be categorized as a PDE of one of the familiar types, i.e. elliptic, parabolic or hyperbolic. In fact, the Schrödinger equation shows parabolic as well as hyperbolic behavior (it is of the form of the diffusion equation but allows for wave solutions). We discuss here briefly a very elegant method developed to numerically approximate solutions of the time-dependent Schrödinger equation, A prominent alternative method, the split operator technique, is briefly explained in Appendix D.

We note that Eq. (11.40) has the formal solution

(11.41)

where we assumed that H is independent of time t. We note that the operator U(t) on the right hand side of Eq. (11.41) propagates the solution in time. Furthermore, it is a unitary operator and therefore preserves the norm of the wave-function Ψ(x, t). U(t) is usually referred to as the unitary time-evolution operator [19]. ²

We employ relation (11.41) and obtain

(11.42)

Expanding the exponential in this equation in its series representation and truncating the series after the second term results in the approximation

(11.43)

Again, we introduce grid-spacing $$x_{k} = k\varDelta x,k \in \mathbb{N}$$ and the correspondingly indexed functions Ψ k n  ≡ Ψ(x k , nΔt) which results in

(11.44)

Using Eq. (10.​23) for the Hamiltonian in its position space representation in the one-dimensional case and by approximating the second derivative with the help of the central difference approximation we arrive at

(11.45)

where we defined V k  ≡ V (x k ).

The iteration scheme (11.45) resembles the explicit Euler approximation  (11.18) of the heat equation with the difference that we have here an imaginary coefficient. An implicit procedure for the time-dependent Schrödinger equation (11.40) can be obtained by inversion of Eq. (11.42):

(11.46)

A series expansion of the exponential results in the desired relation:

(11.47)

We emphasize that the unitarity of the time-evolution operator is of fundamental importance since it preserves the norm of the wave-function. However, in truncating the series representation of the unitary time evolution operator U(Δ t) we certainly violate the unitarity of U(Δ t). This problem can be remedied by imposing unitarity of the time evolution as an additional requirement. This requirement can be incorporated by normalizing the wave-function after each time step.

We demonstrate now that the Crank-Nicolson scheme [15] can be applied successfully to solve Eq. (11.40) numerically for a particular potential. The Crank-Nicolson scheme can be obtained by realizing that

(11.48)

Hence, we obtain from Eq. (11.45)

(11.49)

or by expanding U in a series and truncating after the second term

(11.50)

Inserting the finite difference approximation of the Hamiltonian H and rearranging terms yields

(11.51)

where we defined $$\hat{\varOmega }_{k}^{n}$$ as

(11.52)

Both sides of Eq. (11.51) are now multiplied by $$i4m\varDelta x^{2}/(\hslash \varDelta t)$$ and this gives

(11.53)

where

(11.54)

We recognize that Eq. (11.53) establishes a system of linear equations and rewrite it in matrix form:

(11.55)

Here, we defined the vectors $$\varPsi ^{n}\,=\,\left (\varPsi _{0}^{n},\varPsi _{1}^{n},\ldots,\varPsi _{N}^{n}\right )^{T}$$, $$\varOmega ^{n}=\left (\varOmega _{0}^{n},\varOmega _{1}^{n},\ldots,\varOmega _{N}^{n}\right )^{T}$$ and the tridiagonal matrix

(11.56)

with Γ k for k = 1, 2, …, N given by

(11.57)

according to Eq. (11.53).

The system (11.56) is solved iteratively. However, in this case we employ a more elegant ansatz which is allowed for tridiagonal matrices. We set

(11.58)

and apply it to Eq. (11.53). After rearranging terms we arrive at:

(11.59)

We define

(11.60)

and obtain from Eq. (11.59)

(11.61)

However, due to the ansatz (11.58) we also have

(11.62)

which results in the relations

(11.63)

and

(11.64)

Equation (11.63) leads to the recursion relation

(11.65)

and we derive from Eq. (11.64):

(11.66)

The remaining question is how to choose a ₀ and b ₀ n . We impose the boundary conditions Ψ ₀ n  = 0 and Ψ N n  = 0 and derive from Eq. (11.53):

(11.67)

A comparison of this equation with the ansatz (11.58), i.e. $$\varPsi _{2}^{n+1} = a_{1}\varPsi _{1}^{n+1} + b_{1}^{n}$$, reveals that

(11.68)

and

(11.69)

These expressions are equivalent to $$a_{0} = \infty $$ and it is, thus, impossible to calculate $$\varPsi _{1}^{n+1}$$ from $$\varPsi _{0}^{n+1}$$. However, we can determine the function values $$\varPsi _{k}^{n+1}$$ via a backward recursion

(11.70)

which is initialized with the boundary condition $$\varPsi _{N}^{n+1} = 0$$. We can now summarize the algorithm:

1.

Choose the initial conditions Ψ k ⁰, k = 0, 1, …, N which satisfy the boundary conditions Ψ ₀ ⁰ = 0 and Ψ N ⁰ = 0.

2.

Set

(11.71)

and calculate for $$k = 2,\ldots,N - 1$$

(11.72)

3.

Start the time loop: n = 0, 1, …, M, with M the maximum number of time steps.

4.

Calculate for $$k = 1,2,\ldots,N - 1$$

(11.73)

5.

Set

(11.74)

and calculate for $$k = 2,\ldots,N - 1$$

(11.75)

6.

Calculate for $$k = N - 1,N - 2,\ldots,1$$

(11.76)

where the boundary conditions $$\varPsi _{0}^{n} =\varPsi _{ N}^{n} = 0$$ are to be considered.

7.

Set $$n = n + 1$$ and go to step 4.

The application of this algorithm is now elucidated with the help of a specific example, the quantum mechanical tunneling effect. The initial condition is described by a Gauss wave packet

(11.77)

centered at x = x ₀ which propagates in positive x-direction with momentum q. This wave-function is not yet normalized. Furthermore, we regard the single potential barrier

(11.78)

or the double potential barrier

(11.79)

The scales and parameters are chosen in the following way: L = 500, Δ x = 1, Δ t = 0. 1, $$m = \hslash = 1$$, x ₀ = 200, q = 2, $$\sigma = 20$$, V ₀ = 0. 7, a = 250, b = 260, c = 300, and d = 310. Figure 11.8 presents the time evolution of the square modulus of the resulting wave-function $$\vert \varPsi (x,n\varDelta t)\vert ^{2}$$ vs x (solid line, left hand scale) at different time steps n = 500, 1000, and 1500. The time step n = 0 corresponds to the initial condition. The potential V ₁(x) vs x is also plotted (dashed line, right hand scale). Figure 11.9 corresponds to Fig. 11.8 but now the potential is described by V ₂(x) and additional time steps for n = 2000 and 2500 have been added.

Fig. 11.8

Time evolution of the square modulus of the wave-function $$\vert \psi (x)\vert ^{2}$$ vs x (solid line, left hand scale). The potential V (x) = V ₁(x) is also plotted vs x (dashed line, right hand scale). We present the results for n = 500, 1000, and 1500 time steps. The graph labeled by n = 0 represents the initial configuration

Fig. 11.9

Time evolution of the square modulus of the wave-function $$\vert \psi (x)\vert ^{2}$$ vs x (solid line, left hand scale). The potential V (x) = V ₂(x) is also plotted vs x (dashed line, right hand scale). We present the results for n = 500, 1000, 1500, 2000, and 2500 time steps. The graph labeled by n = 0 represents the initial configuration

In both figures a typical quantum mechanical effect which is referred to as tunneling can be observed. In particular, there exists a finite probability that the potential barrier can be crossed, although, from a classical point of view, the particle’s energy is not sufficient to overcome the barrier. A detailed discussion of this effect and its technological importance can be found in any standard textbook on quantum mechanics [19–21].

In conclusion we remark that a very prominent method to solve numerically the time-dependent Schrödinger equation is based on the Fourier transformation. The numerical implementation of the Fourier transformation as well as its application to the Schrödinger equation is briefly discussed in Appendix D.

Summary

This chapter was about linear PDEs and how to find solutions numerically. The dominating theme was the application of the various finite difference methods. The two-dimensional Poisson equation served as an example for an elliptic PDE. The algorithm to solve this equation developed here was based on the central difference derivative. Parabolic PDEs were represented by the time-dependent one-dimensional heat equation. The numerical solution proved to be possible by either using an explicit or an implicit Euler scheme. For the explicit Euler scheme the appropriate choice of time and space discretization proved to be essential for the stability of the algorithm. The one-dimensional wave equation was introduced as an example of a hyperbolic PDE. The solution was found by employing an explicit Euler approximation. Again time and space discretization had to follow a specific stability criterion, the Courant-Friedrichs-Lewy condition. Finally, the one-dimensional time-dependent Schrödinger equation was studied. It does not fit into any of the above categories. The algorithm to find a numerical solution was developed here on the basis of a Crank-Nicolson scheme and it was tested with the quantum mechanical tunneling effect.

Problems

1.

Write a program which solves the two-dimensional Poisson equation for an arbitrary charge density distribution ρ(x, y). Use the numerical method discussed in Sect. 11.2.

a.

Impose Dirichlet boundary conditions $$\varphi (x,0) =\varphi (x,L_{y}) =\varphi (0,y) =\varphi (L_{x},y) = 0$$ as described in Sect. 11.2. Test the program by first reproducing Fig. 11.2.

b.

Solve the Poisson equation for different charge densities of your choice.

c.

Calculate the electric field E(x, y) with the help of Eq. (11.3).

2.

Calculate the time evolution of the temperature distribution T(x, t) along a cylindrical rod described in Sect. 9.​3 The rod is kept at constant temperatures T ₀ and T N at its ends. The parameters used in Sect. 9.​3 stay unchanged. Study also the case of a heat sink as suggested in the Problems section of Chap. 9

3.

Calculate the time evolution of the square modulus of the wave-function $$\vert \psi (x)\vert ^{2}$$ vs x for a potential V ₁(x) according to Eq. (11.78) with V ₀ < 0 (quantum well). In a second step, modify the potential according to

with V ₁ > 0, V ₂ < 0, and $$\vert V _{1}\vert &lt;\vert V _{2}\vert$$.

References

1.

Lapidus, L., Pinder, G.F.: Numerical Solution of Partial Differential Equations. Wiley, New York (1982)MATH

2.

Morton, K.W., Mayers, D.F.: Numerical Solution of Partial Differential Equations. Cambridge University Press, Cambridge (2005)CrossrefMATH

3.

Li, T., Qin, T.: Physics and Partial Differential Equations, vol. 1. Cambridge University Press, Cambridge (2012)MATH

4.

Li, T., Qin, T.: Physics and Partial Differential Equations, vol. 2. Cambridge University Press, Cambridge (2014)MATH

5.

Lui, S.H.: Numerical Analysis of Partial Differential Equations. Wiley, New York (2012)

6.

LeVeque, R.J.: Finite Volume Methods for Hyperbolic Problems. Cambridge Texts in Applied Mathematics. Cambridge University Press, Cambridge (2002)CrossrefMATH

7.

Gockenbach, M.S.: Understanding and Implementing the Finite Element Method. Cambridge University Press, Cambridge (2006)CrossrefMATH

8.

Selvadurai, A.: Partial Differential Equations in Mechanics, vol. 2. Springer, Berlin/Heidelberg (2000)CrossrefMATH

9.

Sleeman, B.D.: Partial differential equations, poisson equation. In: Dubitzky, W., Wolkenhauer, O., Cho, K.H., Yokota, H. (eds.) Encyclopedia of Systems Biology, pp. 1635–1638. Springer, Berlin/Heidelberg (2013)Crossref

10.

Jackson, J.D.: Classical Electrodynamics, 3rd edn. Wiley, New York (1998)MATH

11.

Greiner, W.: Classical Electrodynamics. Springer, Berlin/Heidelberg (1998)CrossrefMATH

12.

Polyanin, A.D.: Handbook of Linear Partial Differential Equations for Engineers and Scientists. Chapman & Hall/CRC, Boca Raton (2002)MATH

13.

Cannon, J.R.: The One-Dimensional Heat Equation. Encyclopedia of Mathematics and Its Applications. Cambridge University Press, Cambridge (1985)

14.

Carslaw, H.S., Jaeger, J.C.: Conduction of Heat in Solids, 2nd edn. Oxford University Press, Oxford (1986)MATH

15.

Crank, J., Nicolson, P.: A practical method for numerical evaluation of solutions of partial differential equations of the heat-conduction type. Proc. Camb. Philos. Soc. 43, 50–67 (1947). doi:10.1017/S0305004100023197ADSMathSciNetCrossrefMATH

16.

Zwillinger, D.: Handbook of Differential Equations, 3nd edn. Academic, San Diego (1997)MATH

17.

Courant, R., Friedrichs, K., Lewy, H.: On the partial difference equations of mathematical physics. IBM J. Res. Dev. 11, 215–234 (1967 [1928])ADSMathSciNetCrossrefMATH

18.

Bakhvalov, N.S.: Courant-friedrichs-lewy condition. In: Hazewinkel, M. (ed.) Encyclopaedia of Mathematics. Springer, Berlin/Heidelberg (1994)

19.

Sakurai, J.J.: Modern Quantum Mechanics. Addison-Wesley, Menlo Park (1985)

20.

Baym, G.: Lectures on Quantum Mechanics. Lecture Notes and Supplements in Physics. The Benjamin/Cummings Publ. Comp., Inc., London/Amsterdam (1969)MATH

21.

Cohen-Tannoudji, C., Diu, B., Laloë, F.: Quantum Mechanics, vol. I. Wiley, New York (1977)MATH

Footnotes

1

We note that the electrostatic potentials that we calculated here numerically can also be determined analytically with the method of mirror charges [10].

2

We remember that unitary means that $$UU^{\dag } = U^{\dag }U = \nVdash $$.

Part IIStochastic Methods

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_12

12. Pseudo-random Number Generators

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

12.1 Introduction

Stochastic methods in Computational Physics are based on the availability of random numbers and on the concepts of probability theory. (Readers not familiar with the basic concepts of probability theory are highly encouraged to study Appendix E before proceeding.) The required random numbers are provided by numerical random number generators and, thus, we have to speak, more precisely, of pseudo-random numbers. Let us now motivate the problem and discuss some preliminary items.

A popular example of randomness in physical systems is certainly the outcome of a dice-throw or the drawing of lotto numbers. Even though the outcome of a dice-throw is completely determined by the initial conditions, it is effectively unpredictable because the initial conditions cannot be determined accurately enough. A probabilistic description, which assigns the random variables 1, 2, 3, 4, 5, and 6 a probability of 1∕6, respectively, is much more convenient and promising. It has to be kept in mind, of course, that all predictions obtained on the basis of such an approach are also clearly probabilistic in their nature.

Another example is Brownian motion or diffusion which describes the random motion of dust particles on a fluid surface. It is in this case particularly obvious that a description with the help of a stochastic differential equation , such as the Langevin equation [1], is completely sufficient and more to the point than a description based on the dynamics of a large number of interacting particles.

Stochastic methods are not confined to physics: They are applied very successfully in many other fields of expertise, like biology [2], economics [3, 4], medicine [5], etc. Finally, an interesting and purely mathematical application can be found in the evaluation of integrals as an alternative to the methods discussed in Chap. 3 This method is referred to as Monte-Carlo integration and will be addressed in Chap. 14 together with a basic introduction to stochastics and its applications in physics.

From the numerical point of view, there is one common denominator to all these applications: Random numbers are an essential tool and, consequently, so are random number generators. Thus, a closer inspection of randomness in general and the generation of random numbers or sequences in particular is required. We have to explain what we understand by randomness and how it can be measured. Moreover, based on this discussion we have to formulate requirements to be imposed on the random number generators to deliver useful random numbers.

Although, we might have an intuitive picture of randomness it is hard to formulate without relying on mathematics. For instance, consider the sequence s ₁ which consists of N elements:

(12.1)

Is it random? The question cannot be answered without further information. Suppose, the numbers in sequence s ₁ were drawn from some set $$\mathcal{S}$$. If this set is of the form

(12.2)

then the above sequence s ₁ is certainly not random since there is only one possible outcome. However, suppose the numbers of the sequence s ₁ were drawn from the set $$\mathcal{S}_{2}$$

(12.3)

with the events 0 and 1 together with assigned probabilities P(0) and P(1). These probabilities describe the probability that the outcome of a measurement on the set $$\mathcal{S}_{2}$$ yields either the event 0 or 1, respectively. For instance, in the case of tossing a coin the event 0 may correspond to heads while 1 stands for tails. (To register this result is, within this context, a measurement. ) In this case the probabilities are given by $$P(0) = P(1) = 1/2$$ under the premise that the coin is perfectly ideal and has not been manipulated. Even, if we know that the coin has not been manipulated, sequence (12.1) is still a possible outcome, although it is rather improbable for a large number N of measurements (repeated tosses of the coin).

A literal definition of randomness within the context of a random sequence was given by G. J. Chaitin [6]:

[…] a series of numbers is random if the smallest algorithm capable of specifying it to a computer has about the same number of bits of information as the series itself.

This definition seems to include the most important features of randomness which we are used to from our experience. Since, no universal trend is observable, reproducing the sequence requires the knowledge of every single constituent. Hence, one may employ the sloppy definition: Randomness is the lack of a universal trend.

But how can we test whether or not a given sequence really follows a certain distribution? Of course, one can simply exploit the statistical definition of probability, Appendix, Eq. (E.4): The probability of a certain outcome is measured by counting the particular results. This procedure seems to be quite promising, however, it has to be kept in mind that the statistical definition of probability is only valid in the limit $$m \rightarrow \infty $$, where m is the number of measurements. Hence, it is fundamentally impossible to determine whether or not a sequence is random because an infinite number of elements would have to be evaluated and analyzed. More promising appears to be the calculation of moments or correlations (see Appendix, Sects. E.2 and E.10) from the sequence and to compare such a result with known values for real random numbers. These statistical tests will be discussed in Sect. 12.3. If we consider the sequence (12.1) drawn from the set $$\mathcal{S}_{2}$$, [Eq. (12.3), uniform distribution assumed] we can deduce that it is a very improbable result for large N, although it is certainly a possible outcome. Methods based on this train of thoughts are known as hypothesis testings and we discuss the χ ²-test as a simple representative of such tests in Sect. 12.3.

We are now in a position to clarify what we understand by a random number: We regard a random sequence drawn from the set

(12.4)

If the random number is to be uniformly distributed , we assign probabilities $$P(k) = 1/10$$, k = 0, 1, …, 9 and if we would like to obtain a random number out of the interval

(12.5)

we may simply draw the sequence s ₂ = a ₁, a ₂, a ₃, … from $$\mathcal{S}_{3}$$ and compose the random number r as

(12.6)

Section 12.2 is dedicated to the discussion of different methods of how to generate so called pseudo-random numbers . A pseudo-random number is a number generated with the help of a deterministic algorithm, however, it shows a behavior as if it were random. This implicates that its statistical properties are close to that of true random numbers. In contrast to pseudo-random numbers, real random numbers are truly random. A real random number can be obtained from experiments. One could, for instance, simply toss a coin and register the resulting sequence of zeros and ones. A more sophisticated method is to exploit the radioactive decay of a nucleus, which is believed to be purely stochastic. There are also more exotic ideas, such as using higher digits of π which are assumed to behave as if they were random. However, all these methods have in common that they are far too slow for computational purposes. Moreover, an experimental approach is obviously not reproducible in the sense, that a random sequence cannot be reproduced on demand, but the reproducibility of a random number sequence is essential for many applications.

This leads us to the formulation of several criteria a random number generator will have to comply with. It should

produce pseudo-random numbers whose statistical properties are as close as possible to those of real random numbers.

have a long period: It should generate a non-repeating sequence of random numbers which is sufficiently long for computational purposes.

be reproducible in the sense defined above, as well as restartable from an arbitrary break-point.

be fast and parallelizable: It should not be the limiting component in simulations.

We restrict, within this chapter, our discussion to random numbers that are uniformly distributed over a finite set. Thus, we assign to all possible outcomes of a measurement the same probability. The generation of non-uniformly distributed random numbers from uniformly distributed random numbers is not a difficult task and will be discussed in more detail in Chap. 13

12.2 Different Methods

We discuss here different types of pseudo-random number generators [7–9] which generate a pseudo-random number r which is uniformly distributed within the interval [0, 1). Hence, its probability density function (pdf) is given by

(12.7)

and from this follows the cumulative distribution function (cdf; see Appendix E):

(12.8)

We introduce here only some of the most basic concepts for pseudo-random number generators. However, in huge simulations based on random numbers standard pseudo-random number generators provided by the various compilers may not be sufficient due to their rather short period and bad statistical properties. In this case it is, therefore, recommended to consult the literature [7, 10] and use more advanced techniques in order to obtain reliable results.

Linear Congruential Generators

Linear congruential generators are the simplest and most prominent random number generators. They produce a sequence of integers {x n }, $$n \in \mathbb{N}$$ following the rule

(12.9)

where a, c and m are positive integers which obey 0 ≤ a, c < m. Furthermore, the generator is initialized by its seed x ₀, which is also a positive (in most cases odd) integer in the range 0 ≤ x ₀ < m. The seed is commonly taken from, for instance, the system time in order to avoid repetition at a restart of the sequence. In many environments it is, therefore, necessary to fix the seed artificially whenever one wants to perform reproducible tests.

We note that the sequence resulting from Eq. (12.9) is bounded to the interval $$x_{n} = [0,m - 1]$$ and, hence, its maximum period is m. However, the actual period of the sequence highly depends on the choices of the parameters a, c and m as well as on the seed x ₀. In general, linear congruential generators are very fast and simple, however, they have rather short periods. Moreover, they are very susceptible to correlations since the value x n+1 is calculated from x n only. (This is obviously a property which does not apply to real independent random numbers and it should therefore be eliminated!) In Sect. 12.3 we will discuss some simple methods which allow to identify such correlations.

One of the most prominent choices for the parameters in Eq. (12.9) are the Park-Miller parameters [10]:

(12.10)

Note that one has to be particularly careful when choosing c = 0. It follows from Eq. (12.9) that if c = 0 and if for any n, x n  = 0 one obtains x k  = 0 for all k > n.

The random numbers r n described by the pdf (12.7) are obtained via

(12.11)

Let us briefly discuss two famous improvements which concentrate on the reduction of correlations and an elongation of the period: The first idea which is referred to as shuffling [10] includes a second pseudo-random step. One calculates N numbers r n from Eqs. (12.9) and (12.11) and stores these numbers in an array. If a random number is needed by the executing program, a second random integer k ∈ [1, N] is drawn and the k-th element is taken from this array. In order to avoid that the same random number is used again, the k-th element of the array is replaced by a new random number which, again, is calculated from (12.9) and (12.11).

The second idea to improve the linear congruential generator is simply to include more previous elements of the sequence:

(12.12)

where ℓ > 0 and a ℓ ≠ 0. Again, the periodicity depends highly on the choice of the parameters and on the seed. A specific variation of random number generators using Eq. (12.12) are the Fibonacci generators.

Fibonacci Generators

The Fibonacci sequence is given by

(12.13)

which results for n ≥ 1 in

(12.14)

Choosing in Eq. (12.12) m = 10, ℓ = 1 and $$a_{0} = a_{1} = 1$$ simply leaves the last digits of the sequence (12.14):

(12.15)

This suggests the definition of a pseudo-random number generator based on the Fibonacci sequence [11]. It is of the form

(12.16)

which, according to our previous discussion, allows a periodicity exceeding m. A straightforward generalization results in the so called lagged Fibonacci generators:

(12.17)

where $$p,q \in \mathbb{N}$$ and the operator ⊗ stands for any binary operation, such as addition, subtraction, multiplication or some logical operation. Two of the most popular lagged Fibonacci generators are the shift register generator and the Marsaglia-Zaman generator.

The shift register generator is based on the exclusive or (XOR; ⊕) operation, which acts on each bit of the numbers x n−p and x n−q . In particular, the recurrence relation reads

(12.18)

The XOR operation ⊕ is shown in the following multiplication table:

a

b

a ⊕ b

0

0

0

1

0

1

0

1

1

1

1

0

Hence, suppose that the binary representation of x n−p is of the form 01001110… and for x n−q we have 11110011… Then we get from Eq. (12.18):

x n−p

0

1

0

0

1

1

1

0

…

x n−q

1

1

1

1

0

0

1

1

…

x n

1

0

1

1

1

1

0

1

…

A very prominent choice is given by p = 250 and q = 103 which yields a superior periodicity of order $$\mathcal{O}(10^{75})$$. The algorithm is initialized with the help of, for instance, a linear congruential generator.

In contrast, the Marsaglia-Zaman generator (subtract-with-borrow scheme) [12] uses the subtraction operation and may be written by introducing the so called carry bit Δ as

(12.19)

where x i  ∈ [0, m] for all i. Then,

(12.20)

and c n is obtained via

(12.21)

For the particular choice p = 10, q = 24 and m = 2²⁴ one finds an amazingly large periodicity of order $$\mathcal{O}(10^{171})$$. The random numbers x n are integers in the interval x n  ∈ [0, m], hence dividing the random numbers by m gives r n  ∈ [0, 1].

12.3 Quality Tests

Here, we discuss some tests to check whether or not a given, finite sequence of numbers x n consists of uniformly distributed random numbers out of the interval x n  ∈ [0, 1].¹

Statistical Tests

Statistical tests are generally the most simple methods to arrive at a first idea of the quality of a pseudo-random number generator. Statistical tests are typically based on the calculation of moments or correlations. Since we regard the simplified case of uniformly distributed, uncorrelated random numbers within the interval [0, 1], the moments can be calculated immediately from (see Appendix, Sect. E.2)

(12.22)

for $$k \in \mathbb{N}$$. These moments are approximated using the generated finite sequence of numbers {x n } n = 1, …, N via

(12.23)

As illustrated in Appendix, Sect. E.2, the error of this approximation is of order $$\mathcal{O}\left (1/\sqrt{N}\right )$$ and

(12.24)

Another method studies correlations (see Appendix, Sects. E.2 and E.10) between the random numbers of the sequence and compare it with the analytical result. We obtain for uncorrelated random numbers:

(12.25)

Another, quite evident test, is the analysis of the symmetry of the distribution. If X n  ∈ [0, 1] is uniformly distributed then it follows that (1 − X n ) ∈ [0, 1] should also be uniformly distributed.

Finally, we discuss a graphical test, known as the spectral test [7]. The spectral test consists of plotting subsequent random numbers x n vs x n+1 and of visual inspection of the result. One expects the random numbers to uniformly fill the unit-square, however, if correlations exist, particular patterns might evolve. We illustrate this method in Fig. 12.1 where it is applied to a linear congruential generator (12.9) with two different sets of parameters.

Fig. 12.1

Spectral test for a linear congruential generator. We used the Park-Miller parameters, (a) a = 7⁵, c = 0, and $$m = 2^{31} - 1$$, (b) a = 137, c = 0, and m = 2¹¹, and plotted N = 10³ subsequent pairs (x n , x n+1) of random numbers. In frame (a) the random numbers evolve nicely distributed within the unit square, showing no obvious correlations. On the other hand, in frame (b) subsequent random numbers lie on hyperplanes and, thus, develop correlations: They do not fill the unit square uniformly

Hypothesis Testing

Basically, one could employ different hypothesis tests, such as the Kolmogorov-Smirnov test, to test random numbers. These tests are rather basic and are discussed in numerous books on statistics. In what follows we shall briefly mention the χ ²-test; for more advanced techniques we refer the reader to the literature [13, 14].

The χ ²-test tests the pdf directly. One starts by sorting the N elements of the sequence into a histogram. Suppose we would like to have M bins and, hence, the width of every bin is given by 1∕M. We now count the number of elements which lie within bin k, i.e. within the interval $$\left [(k - 1)/M,k/M\right ]$$, and denote this number by n k . The histogram array h is given by h = c(n ₁, n ₂, …, n M ) T where the constant $$c = M/N$$ normalizes the histogram. In Fig. 12.2 we show three different histograms for N = 10⁵, N = 10⁶ and N = 10⁷ uniformly distributed random numbers as obtained with the Park-Miller linear congruential generator. In Fig. 12.3 we present a histogram for N = 10⁷ obtained with the bad linear congruential generator defined in Fig. 12.1b. We recognize numerous empty bins which are a clear indication that the random numbers are not uniformly distributed.

Fig. 12.2

Histograms for N = 10⁵, N = 10⁶ and N = 10⁷, M = 100 bins as obtained with the Park-Miller linear congruential generator, a = 7⁵, c = 0 and $$m = 2^{31} - 1$$

Fig. 12.3

Histogram for N = 10⁷ and M = 100 bins as obtained with a linear congruential generator with parameters a = 137, c = 0 and m = 2¹¹

Let us briefly remember some points from probability theory [15, 16]. One can show, that if numbers Q n are normally distributed random variables, their sum

(12.26)

follows a χ ²-distribution where ν is the number of degrees of freedom. The pdf of the χ ²-distribution is given by

(12.27)

where Γ(⋅ ) denotes the Γ-function. The probability of finding the variable x within the interval $$[a,b] \subset \mathbb{R}^{+}$$ can be calculated as

(12.28)

and in particular for a = 0 we obtain

(12.29)

Here we introduced the cdf F(b; ν). Let us consider the inverse problem: the probability that x ≤ b is equal to α, i.e. F(b; ν) = α. We then calculate the upper bound b by inverting Eq. (12.29) and obtain:

(12.30)

These values are tabulated [17, 18].

We return to our particular example: the hypothesis is that the sequence {x n } generated by some pseudo-random number generator complies to a uniform distribution. It is a consequence of the central limit theorem (see Appendix, Sect. E.8) that the deviations from the theoretically expected values n k th obey a normal distribution. We define the variable

(12.31)

If our hypothesis is true, χ ² follows a χ ²-distribution with $$\nu = M - 1$$ because the requirement that the sum of all numbers n k is equal to N reduces the degrees of freedom by one. We employ relation (12.30) for α = 0. 85 and ν = 99 and obtain b = 113. Hence, values χ ² < b are very likely if χ ² really follows a χ ² distribution, while values χ ² > b are unlikely and therefore the hypothesis may require a review. However, it has to be emphasized that it is fundamentally impossible to verify a hypothesis. It can only be falsified or strengthened. We note that the resulting value of χ ² will highly depend on the seed number of the generator as long as the maximum period has not been reached.

Summary

We first concentrated on a possible definition of randomness and on a mathematical definition of random numbers and sequences. As the generation of random numbers was the main topic of this section we moved on to describe the requirements an ‘ideal’ random number generator will have to obey. On the other hand, the numerics of computational physics demanded reproducible sequences of random numbers and this resulted in the notion of ‘pseudo’ random numbers which will be generated by deterministic methods and, thus, cannot possibly be ‘ideal’. A number of rather simple but quite effective pseudo-random number generators was discussed before the question of how to test the quality (randomness) of these numbers was raised. We discussed statistical tests and demonstrated the simple spectral test using a linear congruential generator. More sophisticated is the method of quality testing. The histogram technique as a direct test for the probability density function from which the random numbers are drawn was discussed in detail. Finally, some basics of the χ ²-test have been presented.

Problems

1.

Write the computer code for a linear congruential generator. This generator is described by

The random numbers r j  ∈ [0, 1] can be obtained by normalizing x j as was discussed in Sect. 12.2. Use the following parameters

a.

$$a = 16807\;,\quad c = 0\;,\quad m = 2^{31} - 1\;,\quad x_{0} = 3141549$$,

b.

$$a = 5\;,\quad c = 0\;,\quad m = 2^{7}\;,\quad x_{0} = 1$$.

2.

Perform the following analysis:

a.

Compute the mean $$\left \langle r\right \rangle$$ and the variance $$\text{var}\left (r\right )$$ for random numbers generated in N steps. Plot the result.

b.

Plot two successive random numbers r k versus r k+1 for $$k = 1,2,\ldots,N - 1$$ in a two dimensional plot.

c.

Repeat the above steps for random numbers generated by your system’s software.

d.

Discuss the results!

References

1.

Coffey, W.T., Kalmykov, Y.P.: The Langevin Equation, 3rd edn. World Scientific Series in Contemporary Chemical Physics: Volume 27. World Scientific, Hackensack (2012)

2.

Dubitzky, W., Wolkenhauer, O., Cho, K.H., Yokota, H. (eds.): Encyclopedia of Systems Biology, p. 1596. Springer, Berlin/Heidelberg (2013)

3.

Tapiero, C.S.: Risk and Financial Management: Mathematical and Computational Methods. Wiley, New York (2004)CrossrefMATH

4.

Lax, M., Cai, W., Xu, M.: Random Processes in Physics and Finance. Oxford Finance Series. Oxford University Press, Oxford (2013)MATH

5.

Laing, C., Lord, G.J. (eds.): Stochastic Methods in Neuroscience. Oxford University Press, Oxford (2009)MATH

6.

Chaitin, G.J.: Randomness and mathematical proof. Sci. Am. 232, 47 (1975)ADSCrossref

7.

Knuth, D.: The Art of Computer Programming, vol. II, 3rd edn. Addison Wesley, Menlo Park (1998)

8.

Gentle, J.E.: Random Number Generation and Monte Carlo Methods. Statistics and Computing. Springer, Berlin/Heidelberg (2003)MATH

9.

Ripley, B.D.: Stochastic Simulation. Wiley, New York (2006)MATH

10.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)MATH

11.

Knuth, D.: The Art of Computer Programming, vol. IV. Addison Wesley, Menlo Park (2011)MATH

12.

Marsaglia, G., Zaman, A.: A new class of random number generators. Ann. Appl. Prob. 1, 462–480 (1991)MathSciNetCrossrefMATH

13.

Iversen, G.P., Gergen, I.: Statistics. Springer Undergraduate Textbooks in Statistics. Springer, Berlin/Heidelberg (1997)Crossref

14.

Keener, R.W.: Theoretical Statistics. Springer, Berlin/Heidelberg (2010)CrossrefMATH

15.

Chow, Y.S., Teicher, H.: Probability Theory, 3rd edn. Springer Texts in Statistics. Springer, Berlin/Heidelberg (1997)CrossrefMATH

16.

Kienke, A.: Probability Theory. Universitext. Springer, Berlin/Heidelberg (2008)

17.

Abramovitz, M., Stegun, I.A. (eds.): Handbook of Mathemathical Functions. Dover, New York (1965)

18.

Olver, F.W.J., Lozier, D.W., Boisvert, R.F., Clark, C.W.: NIST Handbook of Mathematical Functions. Cambridge University Press, Cambridge (2010)MATH

Footnotes

1

From now on we define quite generally the interval out of which random numbers x n are drawn by x n  ∈ [0, 1] keeping in mind that this interval depends on the actual method applied. This method determines whether zero or one is contained in the interval.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_13

13. Random Sampling Methods

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

13.1 Introduction

Most applications require random number generators that follow a particular probability density function (pdf) which is not a uniform distribution on the interval [0, 1]. We present in this chapter methods to generate random numbers that follow some arbitrary pdf. As a source will serve uniformly distributed random numbers as they are generated with the help of the methods we discussed in Chap. 12

The two most prominent techniques to generate random numbers from an arbitrary distribution, are the inverse transformation method and the rejection method. They will be discussed in Sects. 13.2 and 13.3, respectively. In addition, we comment in Sect. 13.4 briefly on sampling from piecewise defined pdfs and combined pdfs. It has to be emphasized that these methods are in many cases not sufficient and a more powerful approach is required. One of these is based on the idea of importance sampling and is referred to as the Metropolis method. It will be discussed briefly in Chap. 14

Nevertheless, it is also possible to obtain quite easily random numbers for some specific pdfs by direct sampling [1]. For instance, suppose x ₁, x ₂ are two uniformly distributed random numbers. Hence, their pdf is given by

(13.1)

and the corresponding cumulative distribution function (cdf) follows:

(13.2)

One can prove that the new random number y

(13.3)

conforms to the cdf

(13.4)

and to the pdf¹:

(13.5)

The consequence is an elegant method to generate random numbers z which follow the pdf

(13.6)

by defining

(13.7)

Here, the random numbers x i are uniformly distributed and can be obtained with the help of the methods introduced in Chap. 12

Another equally elegant method can be employed to calculate random numbers which follow a normal distribution:

(13.8)

Again, we act on the assumption that the random numbers x i are uniformly distributed within the unit interval [0, 1]. We take two random numbers (x ₁, x ₂) and construct two random numbers (z ₁, z ₂) using the transformation:

(13.9)

It is easy to demonstrate that (z ₁, z ₂) follow the pdf (13.8). We introduce the joint distribution p u (x ₁, x ₂) = p u (x ₁)p u (x ₂) (assumption of no correlations). The transformation of probabilities [2–4] gives

(13.10)

or, equivalently, the Jacobian determinant

(13.11)

where we employed Eq. (13.1). We recognize that Eq. (13.9) is equivalent to

(13.12)

The Jacobian determinant is readily evaluated and gives²:

(13.13)

This is the product of two normal distributions and, thus, z ₁ and z ₂ follow indeed a normal distribution.

13.2 Inverse Transformation Method

The inverse transformation method is one of the simplest and most useful methods to sample random variables from an arbitrary pdf [1, 5–7]. Let p(x), x ∈ [x min, x max], denote the pdf from which we want to obtain our random numbers. The corresponding cdf will be denoted by

(13.14)

It follows immediately from the positivity and the normalization condition of pdfs (Appendix, Sect. E.5) that P(x) is monotonically increasing and, furthermore, that P(x min) = 0 and P(x max) = 1. Let $$\xi$$ denote some random number uniformly distributed within the interval [0, 1]. We obtain from the conservation of probability [2–4]

(13.15)

which can be solved by the choice $$\xi = P(x)$$, since

(13.16)

Hence, we arrive at

(13.17)

where P ⁻¹ denotes the inverse of P. It is an obvious caveat of this method that it requires the inverse $$P^{-1}(\xi )$$ to exist and that P(x) must be calculated and inverted analytically. This is, for instance, not possible in the case of the normal distribution (13.8).

Let us illustrate this method with two simple examples:

1.

Suppose we want to draw random numbers which are uniformly distributed within the interval [a, b]. The corresponding pdf reads

(13.18)

and the cdf takes on the form

(13.19)

where we set, in this particular example, x min = a. Hence, we have

(13.20)

which is uniformly distributed within [0, 1]. Consequently, we determine random numbers x ∈ [a, b] uniformly distributed via

(13.21)

2.

We are interested in random numbers x drawn from a pdf given by the exponential distribution:

(13.22)

Here, $$\lambda&gt; 0$$ and $$x \in [0,\infty )$$. These could, for instance, describe the free path x of a particle between interactions, where the mean free path $$\left \langle x\right \rangle =\lambda$$. From Eq. (13.17) we obtain

(13.23)

and consequently the relation

(13.24)

gives random variables x which comply to the exponential distribution (13.22) if $$\xi$$ follows the pdf $$p_{\mathrm{u}}(\xi )$$ of Eq. (13.1). Moreover, it follows from the symmetry of the uniform distribution that

(13.25)

without affecting the resulting random numbers. In Fig. 13.1 we show a

Fig. 13.1

The histogram representation of the pdf p(x) vs x generated by random numbers drawn from an exponential distribution Eq. (13.22) with the help of the inverse transformation sampling method. Two different values for $$\lambda$$ have been considered, namely (a) $$\lambda = 1$$ and (b) $$\lambda = 5$$. N = 10⁵ random numbers have been sampled. The solid line corresponds to the pdf p(x) according to Eq. (13.22)

histogram with random numbers drawn according to (13.25).

We pointed out already that it is certainly a caveat of this method that the cdf P(x) has to be calculated and inverted analytically. Even if P(x) is not analytically invertible, it is possible to employ the inverse transformation method by calculating P(x) for certain grid-points x i and then interpolating P(x) piecewise between these points with the help of an invertible function. However, in many cases it is advantageous to employ the rejection method, which will be discussed next.

13.3 Rejection Method

The rejection method is particularly suitable if the inverse transformation method fails [1, 6, 7]. One of the most prominent versions of the rejection method is the Metropolis algorithm. It will be introduced in Sect. 14.​3

The basic idea of the rejection method is to draw random numbers x from another, preferably analytically invertible pdf h(x) and check whether or not they lie within the desired pdf p(x). If this is the case the random number x is accepted, otherwise it will be rejected. This is also the basic idea of the hit and miss version of Monte-Carlo integration which will be discussed in Sect. 14.​2

We specify the rejection method: Let p(x) denote the pdf from which we want to draw random numbers. Furthermore, let h(x) be another pdf, which can easily be sampled (for instance with the help of the inverse transformation method) and which is chosen in a such a way that the inequality

(13.26)

holds for all x ∈ [x min, x max], where c ≥ 1 is some constant. The function c h(x) is referred to as the envelope of p(x) within the interval [x min, x max]. The strategy is clear: we sample a random variable x t (trial state) from h(x) and accept it with probability p(x)∕[c h(x)]. This procedure is sketched in Fig. 13.2. Let

Fig. 13.2

Schematic illustration of the rejection method. The trial state x t is accepted with probability p(x)∕[c h(x)]

p(A | x) denote the probability that a given value x is accepted and g(x) denotes the probability that we produce a variable x with the help of this algorithm. Furthermore, P(x = x t ) stands for the probability that a trial state x t is generated. We have

(13.27)

Hence, we indeed generate random numbers which follow the pdf p(x). We may also calculate the probability P(A) that an arbitrary trial state x t is accepted. This is done with the help of the marginalization rule (E.39):

(13.28)

More generally, the probability P(A) to accept a d-dimensional random variable is given by:

(13.29)

We deduce that the bigger c the worse is the acceptance probability of the rejection method. It is therefore advisable to choose the envelope h(x) very carefully.

As an example we aim at sampling the normal distribution  (E.43) for $$x \in \mathbb{R}$$

(13.30)

with expectation value $$\left \langle x\right \rangle \equiv x_{0} = 0$$ and variance $$\sigma ^{2}$$. In a first step we restrict our investigation to $$x \in [0,\infty )$$ due to the symmetry of the pdf. The slightly modified pdf for the right-half axis reads

(13.31)

where we adjusted the normalization. The complete normal distribution (13.30) is re-obtained by sampling the sign of x in an additional step. We use as an envelope h(x) the exponential distribution Eq. (13.22). Furthermore, $$\lambda$$ and c are chosen in such a way that the acceptance probability (13.28) has a maximum under the constraint (13.26). Since this is equivalent to $$c \rightarrow \min$$ we have to solve the optimization problem

(13.32)

The resulting c min is then given by

(13.33)

and x opt is the yet unknown optimal value for x. We obtain

(13.34)

and, therefore,

(13.35)

Consequently, we have

(13.36)

The above relation gives the minimum value of c for arbitrary values of $$\lambda$$. However, since h(x) is our envelope, we can choose $$\lambda$$ in such a way, that $$c_{\mathrm{min}} \rightarrow \min$$. This is achieved in a second step

(13.37)

which results in the optimum value $$\lambda _{\mathrm{opt}} =\sigma$$. This, finally, results together with Eq. (13.36) in:

(13.38)

The algorithm is executed in the following steps:

1.

Draw a uniformly distributed random number $$\xi \in [0,1]$$.

2.

Calculate $$x^{t} = -\lambda _{\mathrm{opt}}\ln (\xi )$$, where $$\lambda _{\mathrm{opt}} =\sigma$$.

3.

Draw a uniformly distributed random number r ∈ [0, 1]. If $$r \leq q(x^{t})/[c_{\mathrm{min}}h(x^{t})]$$, then x = x t is accepted and if $$r&gt; q(x^{t})/[c_{\mathrm{min}}h(x^{t})]$$, x t is rejected and we return to step 1.

4.

If x t was accepted, we draw a uniformly distributed random number r ∈ [0, 1] and only if r < 0. 5 we set $$x = -x$$ otherwise x stays as is.

5.

We repeat steps 1–4 until the number N of desired random numbers has been reached.

Figure 13.3 shows random numbers obtained with the help of this method

Fig. 13.3

The histogram representation of the pdf p(x) vs x generated by random numbers drawn from the normal distribution Eq. (13.30) ($$\sigma = 1$$) with the help of the rejection method. We sampled (a) N = 10³, (b) N = 10⁴, and (c) N = 10⁵ random numbers. The solid line represents the pdf p(x) (13.30)

in a histogram representation . We calculated (a) N = 10³, (b) N = 10⁴, and (c) N = 10⁵ random numbers for $$\sigma = 1$$. It is quite obvious that the original pdf (13.30) is the better approximated the bigger the number N of sampled random numbers becomes.

13.4 Probability Mixing

The method of probability mixing was developed to offer an algorithm which allows to generate random numbers by sampling piecewise defined or composite pdfs. Such a pdf is of the general form

(13.39)

where the sub-pdfs f i (x) fulfill the normalization requirement

(13.40)

and are non-negative, i.e.

(13.41)

for all i = 1, …, N. It follows that

(13.42)

which ensures that

(13.43)

is fulfilled. The question is how to sample random numbers from such a pdf, since in most cases it might be hard to invert the sum (inverse transformation method) or find a suitable envelope (rejection method). However, this question can easily be answered: We define

(13.44)

Thus, q N  = 1 and the interval [0, 1] has been divided according to:

The index i of the relevant pdf is determined by the condition

(13.45)

where r ∈ [0, 1] is a uniformly distributed random number. We then draw the required random number x from the sub-pdf f i (x) with any of the methods discussed above.

This procedure is quite plausible, since the coefficients α i give the relative weight of the sub-pdfs f i (x). In particular, α i determines the importance of the sub-pdf f i (x). It is, therefore, a natural approach to use α i as a measure of the probability that a random variable is to be sampled from the particular sub-pdf f i (x).

Summary

To generate random numbers is essential for many application in Computational Physics. This chapter concentrated on basic methods to generate the desired random numbers: (a) the direct sampling method used transformations of the uniform distribution to generate the required random numbers; (b) the inverse transformation method was based on the availability of an inverse cdf which was in most cases required to be calculated analytically; finally, (c) the rejection method which was basically a hit or miss method. It used an easily invertible pdf h(x) which enveloped the desired pdf p(x) completely within some interval x ∈ [x min, x max]. The effectiveness of this method depended on how ‘well’ the envelope h(x) enclosed the original pdf p(x). In a last step the method of probability mixing was discussed. It was an easily verifiable method which allowed to sample random numbers from composite pdfs.

Problems

Draw random numbers from the following pdfs:

1.

Direct Sampling:

Sample the normal distribution with $$\left \langle x\right \rangle = 0$$ and $$\sigma = 1$$ with the help of the method discussed in Sect. 13.1. Check the result by plotting the random numbers against the pdf p(x) in a histogram.

2.

Inverse Transformation Method:

Write a function which samples random numbers from the exponential distribution with the help of the inverse transformation method as discussed in Sect. 13.2. Compare the generated random numbers to the pdf in a histogram.

3.

Rejection Method:

Sample the normal distribution with $$\left \langle x\right \rangle = 0$$ and $$\sigma = 1$$ with the help of the exponential distribution as discussed in Sect. 13.3. Compare the generated random numbers with the pdf in a histogram. Determine the acceptance probability numerically.

4.

Probability Mixing:

We choose an alternative envelope for the normal distribution with $$\left \langle x\right \rangle = 0$$ and $$\sigma = 1$$. This envelope is chosen to be constant for all | x | < x ₀, and decays exponentially for | x | ≥ x ₀. (x ₀ is a parameter of your choice.) The parameters do not need to optimize the acceptance probability. Again, plot the generated random numbers in a histogram and compare the acceptance probability with the acceptance probability of point 3.

References

1.

Devroye, L.: Non-uniform Random Variate Generation. Springer, Berlin/Heidelberg (1986)

2.

Chow, Y.S., Teicher, H.: Probability Theory, 3rd edn. Springer Texts in Statistics. Springer, Berlin/Heidelberg (1997)

3.

Kienke, A.: Probability Theory. Universitext. Springer, Berlin/Heidelberg (2008)

4.

Stroock, D.W.: Probability Theory. Cambridge University Press, Cambridge (2011)

5.

Bratley, P., Fox, B.L., Schrage, L.E.: A Guide to Simulation. Springer, Berlin/Heidelberg (1987)

6.

Knuth, D.: The Art of Computer Programming, vol. II, 3rd edn. Addison Wesley, Menlo Park (1998)

7.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)

Footnotes

1

This follows from the transformation of pdfs (see Chap. 14):

2

We make use of:

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_14

14. A Brief Introduction to Monte-Carlo Methods

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

14.1 Introduction

This chapter presents a brief introduction to Monte-Carlo methods in general, and to Monte-Carlo integration as well as to the Metropolis-Hastings algorithm in particular. A detailed discussion of the fundamental concepts involved is postponed to Chap. 16 The introduction given here is not supposed to be self-contained and methods will be introduced without reference to their background.

The notion of Monte-Carlo methods, Monte-Carlo algorithms or Monte-Carlo techniques is not well defined. In particular, the term Monte-Carlo summarizes a wide field of methods which are based on the sampling of random numbers [1–3]. In general, the advantage of Monte-Carlo algorithms lies in their computational strength. In many cases it is simply not feasible to employ deterministic methods due to their very high computational cost. However, in many cases the use of methods based on random sampling is also motivated by the nature of the processes to be described. We mentioned in the previous chapter as a typical example the radioactive decay of some nucleus. This process is believed to be purely stochastic in nature.

The development of Monte-Carlo techniques was initialized in the 1940s by J. von Neumann, S. M. Ulam and N. Metropolis who coined the term Monte-Carlo methods. One of the earliest illustrations of the principle of Monte-Carlo techniques in general, and of Monte-Carlo integration in particular is the Monte-Carlo approximation of π. The discussion which follows now includes the essential ideas of Monte-Carlo integration.

We regard the unit square characterized by the corner points (0, 0), (0, 1), (1, 0), and (1, 1). The area A s of this square is one. We insert a quarter-circle of radius r = 1 which, consequently, possesses the area $$A_{c} =\pi /4$$. Suppose, we are throwing darts on this unit square in such a way that the impact points are uniformly distributed; then the probability P that a certain dart becomes stuck within the interior of the quarter-circle is given by

(14.1)

From a probabilistic point of view, we have after N throws of which n hit the interior of the quarter-circle the probability:

(14.2)

The strategy is clear: we draw uniformly distributed random numbers x i , y i from the interval [0, 1]. These are the intersection points of the darts. Repeating this experiment several times and counting the number of hits n within the quarter-circle allows us to approximate π via

(14.3)

The resulting approximation of π will be strongly influenced by the number of experiments N as well as by the performance of the random number generator used. Table 14.1 lists computed approximations of π for different numbers of experiments N as they were obtained with the help of a linear congruential generator. Linear congruential generators have been introduced and discussed in Sect. 12.​2 The parameters used to initialize the generators are given in the caption of the table. Furthermore, Fig. 14.1 illustrates the

Fig. 14.1

N = 10³ uniformly distributed random numbers within the unit-square. Frame (a) gives the results for generator (1) while frame (b) is for generator (2). The number of elements within the quarter-circle indicated by the solid line determines the value of π a (i). The inferior result of the approximation obtained with generator (2) [frame (b)] originates in correlations between the x and y coordinates

Table 14.1

Approximate values π a (i) obtained with the method discussed in the text. The linear congruential generators are initialized by the following parameters: generator (1): a = 7⁵, c = 0, $$m = 2^{31} - 1$$, and x ₀ = 281 (Park-Miller) and generator (2): a = 7⁵, c = 0, m = 2¹¹, and x ₀ = 281. We also give the absolute errors $$\vert \pi _{a}^{(i)}-\pi \vert$$

N

π a ⁽¹⁾

π a ⁽²⁾

10

2.8000

0.34159

2.8000

0.34159

10²

2.9200

0.22159

3.1600

0.01841

10³

3.1600

0.01841

3.1840

0.04241

10⁴

3.1304

0.01119

3.1868

0.04521

10⁵

3.1358

0.00579

3.1875

0.04589

10⁶

3.1393

0.00229

3.1875

0.04599

10⁷

3.1413

0.00028

3.1875

0.04599

result after N = 10³ experiments for both generators.

14.2 Monte-Carlo Integration

We generalize the ideas formulated above and consider a function f(x) ≥ 0 for $$x \in [a,b] \subset \mathbb{R}$$ where the area of interest is

(14.4)

We denote

(14.5)

and obtain using the above example

(14.6)

where n is the number of random points under the curve indicated schematically in Fig. 14.2. The area A s is given by

(14.7)

and the random numbers r i  = (x i , y i ) are uniformly distributed within the intervals x i  ∈ [a, b] and $$y_{i} \in [0,\xi ]$$. This method is referred to as hit and miss integration [4].

Fig. 14.2

Schematic illustration of the Monte-Carlo integration technique

Another way to perform a Monte-Carlo integration is the so called mean-value integration . It is essentially based on the mean value theorem of calculus which we already employed in our discussion of quadrature in Chap. 3 We restate it here for the sake of a more transparent presentation: The mean-value theorem states that if f(x) is a continuous function for x ∈ [a, b] then there exists a z ∈ (a, b) such that

(14.8)

The function value $$f(z) \equiv \left \langle \,f\right \rangle$$ is referred to as the expectation value or mean value of f(x). We know from probability theory [5–7] that the expectation value can be approximated by the arithmetic mean $$\overline{f}$$

(14.9)

with the error given by the standard error, Eq. (E.14). The arithmetic mean $$\overline{f}$$, on the other hand, is given by

(14.10)

and consequently

(14.11)

Note that here the variables x i are assumed to be uniformly distributed random numbers within the interval [a, b]. (This result will immediately be discussed in more detail.) However, first of all we note from the law of large numbers, Eq. (E.25), that this approach is exact in the limit $$N \rightarrow \infty$$:

(14.12)

Let us now consider the more general case which, in the end, will guide us to a very prominent formulation of Monte-Carlo integration. We want to estimate the expectation value

(14.13)

where $$x \in \mathbb{R}^{d}$$ and p(x) is a pdf. A typical example is the calculation of the thermal expectation value in statistical physics where the pdf p(x) is given by the normalized Boltzmann distribution

(14.14)

Here E(x) denotes the energy as a function of the parameter $$x \in \mathbb{R}^{d}$$, k B stands for Boltzmann’s constant, T is the temperature, and the normalization factor Z is referred to as the canonical partition function [8–11].

Equation (14.13) may be rewritten as

(14.15)

where we introduced the probability density q( f) of f via

(14.16)

with δ(⋅ ) Dirac’s δ-distribution. Let us briefly explain how we arrived at this definition. Let the cdf P(x) be defined by¹

(14.17)

We define in analogy the cdf Q( f):

(14.18)

Note that we distinguish between the function f(X) of the random variable X [which follows the pdf p(X)] and the particular function value $$f \in \mathbb{R}$$. Furthermore, the probability $$\Pr [\,f(X) \leq f]$$ can be rewritten as

(14.19)

where the values a n  < b n are the ordered intersection points a ₁ < b ₁ < a ₂ < b ₂ < … < a N  < b N chosen in such a way that

(14.20)

It is a matter of the particular form of f(x) whether or not the boundary points have to be included. Equation (14.19) can be rewritten:

(14.21)

The pdf q( f) is related to the cdf Q( f) via

(14.22)

and we obtain

(14.23)

However, we know from Eq. (14.20) that:

(14.24)

We introduce the intersection points x k where x ₁ < x ₂ < … < x K and K = 2N (if the boundary points are not included) for which $$f(x_{1}) = f(x_{2}) =\ldots = f(x_{K}) = f$$. Hence, Eq. (14.23) may be rewritten as

(14.25)

We want to improve this result and remember that the Dirac δ-distribution of an arbitrary function g(y) can be expressed as [12]

(14.26)

where the y i are the zeros of g(y), i.e. g(y i ) = 0. Hence, we arrive at the final form of Eq. (14.23)²:

(14.27)

We note, furthermore, that:

(14.28)

As a result, the variance of f, $$\text{var}\left (\,f\right )$$, can be expressed as

(14.29)

Let us define in a next step the arithmetic mean of f(X)

(14.30)

calculated with the help of N random numbers. Hence, we have

(14.31)

and

(14.32)

according to Appendix E. It follows from the central limit theorem, Appendix Sect. E.8, that for large values of N, the pdf of $$\mathcal{F}$$, $$p(\mathcal{F})$$ converges to a normal distribution  (E.43) with $$\left \langle \mathcal{F}\right \rangle$$ and $$\text{var}\left (\mathcal{F}\right )$$:

(14.33)

Based on this property $$\left \langle \,f\right \rangle$$ can be estimated from:

(14.34)

Here, the random numbers x i are sampled from the pdf p(x). This method is the most prominent formulation of Monte-Carlo integration.

We shall briefly discuss some properties of this method. We deduce from Eq. (14.34) that the error scales like $$N^{-\frac{1} {2} }$$. In contrast to the integration methods we discussed in Chap. 3, N is no longer the number of grid-points but the number of random numbers sampled.³ In principle, the error scaling is worse than in the case of classical integrators. For instance, in the case of the central rectangular rule (Sect. 3.​2) we had an error scaling of N ⁻² when summed over the whole interval. However, we obtained this result for the one-dimensional case, in higher dimensions we will certainly need much more grid-points. On the other hand, in Eq. (14.34) N corresponds to the number of d-dimensional random numbers x. Hence, Monte-Carlo integration can be of advantage whenever one has to deal with complicated, high dimensional integrals. In contrast, restricted to one dimension it is in most cases not an improvement of the methods discussed already.

Monte-Carlo integration can also be of advantage whenever the integrand f(x) is not well behaved. In such a case a very fine grid would be required to compute a reasonable estimate of the true value of the integral. Monte-Carlo integration offers a very convenient alternative due to its conceptual simplicity [13].

It is certainly a drawback of Monte-Carlo integration in its formulation (14.34), that the error is also proportional to $$\sqrt{ \text{var}\left (\,f\right )}$$ which is a yet unknown quantity. One has to approximate it with an adequate estimator, for instance with the help of the sampling variance. Moreover, if the variance $$\text{var}\left (\,f\right )$$ diverges, the central limit theorem does not hold and the procedure (14.34) is no longer justified and will fail for sure.

Closely related to the problem of how to determine $$\text{var}\left (\,f\right )$$, is the question of how many random numbers should be drawn. In most cases an iterative approach is the most promising strategy. In a first step N random numbers are drawn and the integral is computed using Eq. (14.34). Then another set of N random numbers is sampled and Eq. (14.34) is reevaluated now using all 2N random numbers. If the change in the resulting estimate of the integral is less than some given tolerance ε, the loop is terminated otherwise another set of N random numbers is added.

We mention that this form of Monte-Carlo integration can be improved particularly by sampling only from points which dominantly contribute to the integral. This method is referred to as importance sampling [13–16] and will be discussed in more detail later on.

14.3 The Metropolis Algorithm: An Introduction

The Metropolis algorithm is a more sophisticated method to produce random numbers from given distributions. In fact, the Metropolis algorithm is a special form of the rejection method (Sect. 13.​3). This section introduces the algorithm on a very basic level which will, in the end, allow a first glance at an interesting model out of statistical physics, namely the Ising model. It will be discussed in Chap. 15 and a more detailed discussion of the Metropolis algorithm will be postponed to Sect. 16.​4

The Metropolis algorithm is particularly useful to treat problems in statistical physics where thermodynamic expectation values of some observable O are of interest [8–11]. They are defined as

(14.35)

where x is a set of parameters and q(x) is the Boltzmann distribution  (14.14). The set of parameters x could be, for instance, the position- and momentum-space coordinates of N different particles. In most cases x is a high dimensional object which makes classical numerical integration (Chap. 3) cumbersome. Instead Monte-Carlo integration is employed and the integral (14.35) is approximated with the help of Eq. (14.34) by

(14.36)

where the uncorrelated random numbers x i , i = 1, 2, …, N are sampled from the pdf, Eq. (14.14). We recognize immediately the problem: we need to know the exact functional form of q(x) if we want to apply either the inverse transformation method or the rejection method discussed in Chap. 13. However, the partition function Z itself is determined by an integral which can be approximated using Eq. (14.36). We set

(14.37)

and

(14.38)

follows from the normalization of q(x). The Metropolis algorithm was designed to avoid precisely this problem. We concentrate on a pdf which is of the form (14.37), but q(x) must not necessarily be described by a normalized Boltzmann distribution, Eq. (14.14). Thus, p(x) is arbitrary but it ensures that

(14.39)

and q(x) ≥ 0 for all x. In other words, q(x) is a pdf. Suppose we already have a sequence x ₀, x ₁, …, x n  = { x n } of parameters which indeed follows the pdf q(x).⁴ We now add to the last element of this sequence x n a small perturbation δ and set

(14.40)

Note that the perturbation δ is of the same dimension as the vector x. Similar to the rejection method we seek for a criterion which helps us to decide whether or not the test value x t can be accepted as the next element of the sequence {x n }.

The Metropolis method proposes an acceptance probability of the form

(14.41)

Hence, if $$\Pr (A\vert x_{t},x_{n}) = 1$$, we set $$x_{n+1} = x_{t}$$, and if $$\Pr (A\vert x_{t},x_{n}) &lt;1$$, we draw a random number r ∈ [0, 1] and accept x t if $$r \leq \Pr (A\vert x_{t},x_{n})$$ and reject x t otherwise. We note that in this formulation the knowledge of the normalization factor Z is no longer required since it follows from Eq. (14.37) that

(14.42)

Consequently we rewrite Eq. (14.41) as

(14.43)

where we introduced in the last step a more compact notation.

A discussion of the underlying concepts and why the choice (14.41) indeed samples random numbers according to the pdf q(x) requires some basic knowledge of stochastics in general and of Markov-chains in particular. This is the reason why we postponed this discussion to Chap. 16 Nevertheless, there is a particular property, referred to as detailed balance which requires our attention because it is crucial for the Metropolis algorithm: Let p(x t  | x n ) denote the pdf for the probability that a random number x t is generated from the random number x n as defined in Eq. (14.43). Then the condition of detailed balance is defined as

(14.44)

In words: The probability p(x t  | x n ) that a random number x t is generated from a random number x n times the probability q(x n ) that the random number x n occurred at all is equal to the probability p(x n  | x t ) that the random number x n is generated from x t times the probability q(x t ) that x t occurred. Detailed balance is motivated by physics and is a condition of thermodynamic equilibrium.

Let us briefly demonstrate that the Metropolis algorithm (14.43) satisfies detailed balance: We distinguish three different cases: (i) Suppose that $$p(x_{t}\vert x_{n}) = p(x_{n}\vert x_{t}) = 1$$. From Eq. (14.43) we note that this is only possible if p(x t ) = p(x n ) and therefore q(x t ) = q(x n ) which is already Eq. (14.44) for this particular case. (ii) We assume that p(x t  | x n ) = 1 but p(x n  | x t ) ≠ 1. It follows from Eq. (14.43) that

(14.45)

This corresponds to Eq. (14.44) for p(x t  | x n ) = 1. Note that we made use of definition (14.37) in order to achieve this result. (iii) Finally, we find for p(x n  | x t ) = 1 and p(x t  | x n ) ≠ 1 that

(14.46)

which, again, is Eq. (14.44). Hence, the Metropolis algorithm (14.43) indeed obeys detailed balance.

So far the question of how to choose the initialization point x ₀ of the sequence stayed unanswered. This is clearly not a trivial problem and it is strongly related to one of the major disadvantages of the Metropolis algorithm, namely that subsequent random numbers (x n , x n+1) are strongly correlated. One of the most pragmatic approaches is to choose a starting point x ₀ at random out of the parameter space and then discard it together with the first few members of the sequence. This approach is strongly motivated by a clear physical picture: The sequence of random numbers resembles the evolution of the physical system from an arbitrary initial point x ₀ toward equilibrium which manifests itself in the condition of detailed balance. Hence, the approach of discarding the first few members of the sequence is referred to as thermalization.

The integral of interest, Eq. (14.35) is then approximated with the help of Eq. (14.36), where the random numbers $$x_{k},x_{k+1},\ldots,x_{k+N}$$ are used, if the thermalization required k steps. There is a remedy which helps to reduce correlations between subsequent random numbers within the sequence which is based on a similar strategy. In particular, the modified sequence

(14.47)

generated by discarding ℓ intermediate random numbers will reduce correlations between the members of this final sequence of random numbers.

Summary

This chapter set the stage for an important numerical tool in Computational Physics: the Monte-Carlo techniques. It started with the conceptual transparent task of how to calculate π using a sequence of uniformly distributed random numbers of the range [0, 1]. This established the so-called hit and miss technique. It moved on to a discussion of Monte-Carlo integration in a more formal way and discussed in detail the error involved by this type of integration as opposed to the error experienced by deterministic methods. The conclusion was, that Monte-Carlo integration was certainly preferable whenever estimates of high dimensional integrals were required and it also had advantages when the integrand was heavily structured. The second part of this chapter dealt with the Metropolis algorithm which allowed to generate a sequence of random numbers from some pdf p(x). It was conceptually similar to the rejection method discussed earlier. The mathematical background which is more involved was not discussed within this first contact with the Metropolis algorithm. Instead, the emphasis was to demonstrate that this algorithm obeyed detailed balance a property purely based on physics as a condition of thermodynamic equilibrium. It was, furthermore, pointed out that the random numbers generated by this algorithm were highly correlated and some strategies to remedy this problem were discussed.

References

1.

Gentle, J.E.: Random Number Generation and Monte Carlo Methods. Statistics and Computing. Springer, Berlin/Heidelberg (2003)

2.

Kalos, M.H., Whitlock, P.A.: Monte Carlo Methods, 2nd edn. Wiley, New York (2008)

3.

Kroese, D.P., Taimre, T., Botev, Z.I.: Handbook of Monte Carlo Methods. Wiley, New York (2011)

4.

Fishman, G.S.: Monte Carlo: Concepts, Algorithms and Applications. Springer Series in Operations Research. Springer, Berlin/Heidelberg (1996)

5.

Chow, Y.S., Teicher, H.: Probability Theory. Springer Texts in Statistics, 3rd edn. Springer, Berlin/Heidelberg (1997)

6.

Kienke, A.: Probability Theory. Universitext. Springer, Berlin/Heidelberg (2008)

7.

Stroock, D.W.: Probability Theory. Cambridge University Press, Cambridge (2011)

8.

Schwabl, F.: Statistical Mechanics. Advanced Texts in Physics. Springer, Berlin/Heidelberg (2006)

9.

Halley, J.W.: Statistical Mechanics. Cambridge University Press, Cambridge (2006)

10.

Pathria, R.K., Beale, P.D.: Statistical Mechanics, 3rd edn. Academic, San Diego (2011)

11.

Hardy, R.J., Binek, C.: Thermodynamics and Statistical Mechanics: An Integrated Approach. Wiley, New York (2014)

12.

Ballentine, L.E.: Quantum Mechanics. World Scientific, Hackensack (1998)

13.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)

14.

Doucet, A., de Freitas, N., Gordon, N. (eds.): Sequential Monte Carlo Methods in Practice. Information Science and Statistics. Springer, Berlin/Heidelberg (2001)

15.

Ripley, B.D.: Stochastic Simulation. Wiley, New York (2006)

16.

Landau, D.P., Binder, K.: A Guide to Monte Carlo Simulations in Statistical Physics, 3rd edn. Cambridge University Press, Cambridge (2009)

Footnotes

1

Please note that according to the conventions established in Appendix E capital letters denote random variables.

2

We give an example. Suppose $$f(x) =\exp (x)$$. Then we deduce that

and, consequently,

A second example was given in Chap. 13 where we derived the pdf (13.​5).

3

Nevertheless, there is certainly some conceptual similarity between grid-points and random numbers within this context.

4

The question of how one can obtain such a sequence will be discussed in Sect. 16.​3

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_15

15. The Ising Model

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

15.1 The Model

Ferromagnetic materials are materials which develop a non-vanishing magnetization M even in the absence of an external magnetic field B. It is an experimental observation, that this magnetization decreases smoothly with increasing temperature, and vanishes above the critical temperature T C , referred to as Curie temperature [1]. Above this temperature the magnetization is zero and the material is no longer ferromagnetic but paramagnetic. This typical situation is illustrated in Fig. 15.1 and it is the signature of a phase transition. In a theoretical description of this transition the magnetization M serves as an order parameter .¹ At T = T C the system exhibits a second order phase transition: The magnetization is not differentiable with respect to T; it is, however, continuous.

Fig. 15.1

Schematic illustration of the magnetization M as a function of temperature T in a ferromagnetic material

The microscopic origin of this macroscopic phenomenon is based on the exchange interaction between identical particles, the atoms or molecules forming the material. The exchange interaction is a purely quantum-mechanical effect which is a consequence of the Coulomb interaction in combination with the Pauli exclusion principle.² For more detailed information please consult Refs. [2–8].

Given two atoms or molecules with spins S ₁ and S ₂, where $$S_{1},S_{2} \in \mathbb{R}^{3}$$, the exchange interaction energy is of the form³

(15.1)

with the exchange constant J. The magnitude of J as well as its sign are determined by overlap integrals which include the Coulomb interaction. If J < 0 a parallel orientation of the spins is energetically favorable and ferromagnetism arises if T < T C . On the other hand, if J > 0, an antiparallel orientation is established as long as the temperature does not exceed the Néel temperature T N . However, in both cases the system undergoes a phase transition to a paramagnetic state if the temperature T exceeds the Curie temperature (ferromagnetic case) or the Néel temperature (antiferromagnetic case). A schematic illustration of ferro- and antiferromagnetism for a two-dimensional crystal is illustrated in Fig. 15.2. We summarize the different scenarios:

Fig. 15.2

Schematic illustration of the spin-orientation in a (a) ferromagnetic (J < 0) or (b) antiferromagnetic (J > 0) two-dimensional crystal

We concentrate on a cubic crystal lattice in which the atoms are localized at positions x ℓ . The spin of atom $$\ell$$ will be denoted by $$S_{\ell} \in \mathbb{R}^{3}$$ and the exchange parameter between atom $$\ell$$ and atom $$\ell'$$ by $$J_{\ell\ell'}$$. Furthermore, we consider the ferromagnetic case with $$J_{\ell\ell'} &lt; 0$$. The Hamilton function [9–11] is of the form

(15.2)

Here $$J_{\ell\ell'}$$ was replaced by $$J_{\ell-\ell'} = J_{\ell'-\ell}$$ to account for translational invariance. Moreover, we define that $$J_{\ell\ell} = 0$$, otherwise we would have to exclude the contributions $$\ell=\ell '$$ from the above sum. The Hamilton function (15.2) is genuine to the Heisenberg model [1]. We note that in this model there is no distinguished direction of spin orientation and, consequently, the Hamilton function is invariant under a rotation of all spin vectors $$S_{\ell}$$. The actual spin orientation may be determined by an external magnetic field or by an anisotropy of the crystal lattice. Furthermore, the restriction of the spin orientation to the positive or negative z-direction is the characteristic of the Ising model.

In a quantum mechanical description the Hamilton operator (Hamiltonian) of the Ising model is defined by

(15.3)

where $$S_{\ell}^{z}$$ are the spin operators in z-direction. If spin 1∕2 particles are described by this Hamiltonian, the spin operators $$S_{\ell}^{z}$$ are replaced by $$(\hslash /2)\sigma _{\ell}^{z}$$ with $$\sigma _{\ell}^{z}$$ the Pauli matrix and $$\hslash $$ the reduced Planck’s constant. Furthermore, we redefine $$J'_{\ell-\ell'} = -(\hslash ^{2}/4)J_{\ell-\ell'}$$, $$J'_{\ell-\ell'} &gt; 0$$, and represent the Hamiltonian in the basis of eigenstates of the operators $$\sigma _{\ell}^{z}$$. These eigenstates have eigenvalues $$\sigma _{\ell} = \pm 1$$ which correspond to spin up and spin down states, respectively. We obtain in this representation

(15.4)

where we dropped the prime on the exchange parameter $$J_{\ell-\ell'}$$ for the sake of a more compact notation. We added, furthermore, a term which accounts for the possible coupling of the spins to an external magnetic field,⁴ where h stands for the reduced field $$h = -\mu _{B}gB/2$$.⁵

There are some special cases in which the Ising model can be solved analytically [12, 13]. For instance, one can solve the general case described by Eq. (15.4) with the help of the mean field approximation: The contribution $$h_{\ell}$$ acting on site $$\ell$$

(15.5)

is replaced by its mean value

(15.6)

where $$m =\langle \sigma _{\ell}\rangle$$ and $$\tilde{J }=\sum _{\ell}J_{\ell}$$. (The term $$\tilde{J } m$$ is commonly referred to as the molecular field.) With the help of this ansatz it is, for instance, possible to reproduce the experimentally observed Curie-Weiss – law of ferromagnetic materials: The temperature dependence of the magnetic susceptibility χ for T > T C can be described by:

(15.7)

Another very interesting special case of the general model (15.4) is the restriction to nearest neighbor (n. n.) interaction with the assumption that the interaction between non-nearest neighbor spins is negligible. One step further goes the approximation that $$J_{\ell-\ell'}\equiv J$$ for nearest neighbors. Hence, we have

(15.8)

In this case Eq. (15.4) is rewritten as

(15.9)

where $$\sum _{\left \langle \ell\ell'\right \rangle }$$ denotes the sum over all nearest neighbors. This model can be solved analytically in one and two dimensions if the system is assumed to be spatially unlimited. The solution in one dimension was published by E. Ising [14]. The solution in two dimensions, which is much more involved, was reported by L. Onsager [15].

We briefly discuss Ising’s solution in one dimension. The Hamiltonian (15.9) for N-particles aligned in a one-dimensional chain is rewritten as

(15.10)

where we applied periodic boundary conditions, $$\sigma _{N+1} =\sigma _{1}$$, and the factor 1∕2 was absorbed into J. Let us now briefly elaborate on the kind of observables we would like to describe within this model. (We note in passing that the following discussion is not restricted to the one-dimensional case.) Given a particular spin configuration $$\mathcal{C} =\{\sigma _{i}\}$$, we assume that the probability of finding the system in this configuration is given by the Boltzmann distribution $$p(\mathcal{C})$$ ⁶:

(15.11)

Here, T is the temperature and k B is Boltzmann’s constant. The energy $$E(\mathcal{C})$$ associated with configuration $$\mathcal{C}$$ is given by Eq. (15.10). Please note that now, obviously, we have to treat the model in the classical sense, although we consider spin degrees of freedom. The partition function Z N is given by the sum over all possible configurations $$\mathcal{C}$$ [3, 4, 16]:

(15.12)

In general, the task of solving the Ising problem is a problem of how to evaluate the sum (15.12). This is certainly not trivial since, for instance, in the one dimensional case with N = 100 grid-points one has $$2^{N} = 2^{100} \approx 1.3 \times 10^{30}$$ different configurations $$\mathcal{C}$$. On the other hand, once Z N has been determined more information about the properties of the system can be derived [2, 12, 13]. For instance, the expectation value of the energy ⁷ is given by

(15.13)

and the expectation value of the magnetization follows from

(15.14)

where we defined the magnetization $$\mathcal{M}(\mathcal{C})$$ of a configuration $$\mathcal{C}$$ via:

(15.15)

The term $$\sum _{\ell}\sigma _{\ell}$$ was placed within parenthesis indexed by $$\mathcal{C}$$ to emphasize its dependence on the particular configuration $$\mathcal{C}$$. From the observables (15.13) and (15.14) the fluctuation quantities, namely, the magnetic susceptibility, χ, and the heat capacity, c h , can be derived. The following relations hold:

(15.16)

Equation (15.13) is applied to rewrite the expression for the heat capacity:

(15.17)

Here we made use of the fact that $$E(\mathcal{C})$$ is independent of temperature T. We evaluate, furthermore, the derivative of $$p(\mathcal{C})$$ with respect to temperature T:

(15.18)

This is inserted into Eq. (15.17) and results in a final expression for the heat capacity:

(15.19)

This result justifies why the heat capacity is referred to as a fluctuation quantity.

We determine now, following the same ideas, the magnetic susceptibility using relation (15.14):

(15.20)

We note that

(15.21)

and obtain:

(15.22)

This results in a final expression for the magnetic susceptibility χ which relates it to the variance of the magnetization M:

(15.23)

After this excursion, we return to the analytic treatment of the infinite one-dimensional Ising model with nearest neighbor interaction, Eq. (15.10). If it were possible to evaluate the partition function Z N , the required observables would be directly accessible via the above relations. In most cases this task is not analytically feasible. Nevertheless, in our particular case it appears to be possible because we recognize that we can actually evaluate Eq. (15.12) explicitly by keeping in mind Eq. (15.9):

(15.24)

In the last step the sum over $$\sigma _{\ell}$$ was replaced by an alternative sum

(15.25)

which is a consequence of the periodic boundary conditions $$\sigma _{N+1} =\sigma _{1}$$. Equation (15.24) can be rewritten as

(15.26)

where $$\text{ tr}\left (\cdot \right )$$ denotes the trace operation and we introduced the transfer matrix:

(15.27)

Let us briefly clarify this point: The trace operation in the basis of the spin eigenvalues $$\sigma = \pm 1$$ results in

(15.28)

Hence, we have

(15.29)

In the last step we redefined the sum indices and we used the notation $$\{\sigma _{i}\}$$ to indicate that the sum runs over all possible values of $$\sigma _{1},\sigma _{2},\ldots,\sigma _{N}$$ in order to abbreviate the notation. However, the sum over all possible values of $$\sigma _{1},\sigma _{2},\ldots,\sigma _{N}$$ can be replaced by a sum over all configurations $$\mathcal{C}$$ where one configuration is a specific combination of definite values $$\sigma _{1},\sigma _{2},\ldots,\sigma _{N}$$. For these definite values the product of transfer matrices in Eq. (15.29) is equivalent to the product of exponentials in Eq. (15.24) due to our definition of the transfer matrix $$\mathcal{T}_{\sigma,\sigma '}$$. Hence we demonstrated that expression (15.26) is indeed equivalent to Eq. (15.24).

It follows from definition (15.27) that

(15.30)

It is an easy task to determine the eigenvalues of this matrix [17, 18]. The characteristic polynomial

(15.31)

is of the form

(15.32)

which is easily solved. We get for the two eigenvalues $$\lambda _{1,2}$$

(15.33)

and note that $$\lambda _{1} \geq \lambda _{2}$$ for all temperatures T ≥ 0.

We now make use of the fact that the trace is invariant under a basis transformation Γ. Hence we can express the transfer matrix in a basis in which it is diagonal and set

(15.34)

which immediately results in:

(15.35)

Everything required to calculate the expectation value of energy per particle $$\left \langle \varepsilon \right \rangle$$

(15.36)

in the thermodynamic limit $$N \rightarrow \infty $$ is now in place and, thus, we can investigate the possibility of a phase transition. First, we consider the limit

(15.37)

since $$\lambda _{1} \geq \lambda _{2}$$ for all T ≥ 0.⁸

If there is no external field, i.e. h = 0, we have

(15.38)

which is a smooth function of T for T ≥ 0. Consequently, we do not observe a phase transition in the one dimensional Ising model. Even more information about the system can be provided by the spin correlation function $$\left \langle \sigma _{\ell}\sigma _{\ell'}\right \rangle$$

(15.39)

A basic, however, tedious calculation shows that in the thermodynamic limit it is described by

(15.40)

with the result that the spin correlation decreases with increasing distance ℓ − ℓ′ since $$\lambda _{2} &lt;\lambda _{1}$$ for T > 0.

We move on and briefly sketch the solution of the infinite two-dimensional Ising model according to L. Onsager [15]. The Hamilton function (15.10) changes into:

(15.41)

The strategy developed for the one-dimensional case can again be applied: The system is treated as a classical system with spin degrees of freedom. The Hamilton function (15.41) is inserted into the expression, Eq. (15.12) for the partition function Z N . With the help of the correct basis Z N can be described by the trace over a product of transfer matrices. However, in this case the transfer matrix $$\mathcal{T}$$ is of dimension 2N × 2N rather than 2 × 2. It is quite obvious that the search for the largest eigenvalue for arbitrary values of N is not a trivial task. Therefore, we limit our discussion to a summary of the most important results for the particular case h = 0.

In the two-dimensional case a phase transition is indeed observed: The magnetic susceptibility becomes singular at a particular temperature T C . This temperature is given as the solution of equation:

(15.42)

The expectation value of the energy per particle takes on the form

(15.43)

where $$K_{1}(\xi )$$ is the complete elliptic integral of the first kind [see Eq. (1.​14)] with the argument:

(15.44)

The magnetization per particle $$\left \langle m\right \rangle$$ is proved to be determined from

(15.45)

with

Equation (15.45) clearly describes a phase transition at T = T C .

15.2 Numerics

We study a finite two-dimensional Ising model on a square lattice Ω with grid-points (x i , y j ), $$i,j = 1,2,\ldots,N$$, which will be denoted by (i, j). We write the Hamilton function in the form

(15.46)

where the $$\sigma _{i,j} \in \{-1,1\}$$ are treated as ‘classical’ spins. We consider nearest neighbor interaction and regard the exchange parameter as independent of the actual positions i, j. The problem is easily motivated: We calculate numerically observables like the expectation value of the energy or of the magnetization which will then be compared with analytic results. Such a procedure provides a rather simple check of the quality of the numerical approach which can then be extended to similar models which cannot any longer be treated analytically. We need numerical methods because summing over all possible configurations in a calculation of the partition function Z N is simply no longer feasible since, for instance, for N = 100 we have $$2^{N^{2} } = 2^{10000} \approx 10^{3000}$$ possible configurations which will have to be considered as follows from Eqs. (15.12), (15.13), and (15.14). A more convenient approach would be to approximate the sums with the help of methods we encountered within the context of Monte-Carlo integration in Sect. 14.​2 For instance, the estimate of the energy expectation value is given by

(15.47)

Here, $$\mathcal{C}_{i}$$, $$i = 1,2,\ldots,M$$ are M configurations drawn from the pdf (15.11), the Boltzmann distribution. Equation (15.47) is referred to as the estimator of the internal energy. We note that we also have to calculate an estimate of the variance of E using a similar approach in order to determine the error induced by this approximation.⁹

Hence, there remains the task to find configurations $$\mathcal{C}_{i}$$ which follow the Boltzmann distribution (15.11). The inverse transformation method of Sect. 13.​2 cannot be applied since $$E(\mathcal{C}_{i})$$ is not invertible. Furthermore, the rejection method is useless since we would need the partition function Z N to make it work. However, calculating the partition function is a task as difficult as calculating the internal energy (15.13) without any approximations. Therefore, the method of choice will be the Metropolis algorithm discussed in Sect. 14.​3

Let $$\mathcal{C}$$ be a given spin configuration on the two-dimensional square lattice Ω. We modify the spin on one particular grid-point (i, j) and obtain a trial spin configuration $$\mathcal{C}^{t}$$. According to our discussion in Sect. 14.​3, the probability of accepting the new configuration $$\mathcal{C}^{t}$$ is then given by

(15.48)

The spin orientation was changed only on one grid-point (i, j), with $$\sigma _{i,j} \rightarrow \hat{\sigma }_{i,j} = -\sigma _{i,j}$$; thus, the energy difference $$\varDelta E_{ij}$$ is easily evaluated using

(15.49)

with $$\sigma _{i,j}$$ the original spin orientation.

We focus now on numerical details, some particular to the numerical treatment of the Ising model [19], and some of rather general nature which should be considered whenever a Monte-Carlo simulation is planned.

(1) Lattice Geometry

We regard a two-dimensional N × N square lattice with periodic boundary conditions¹⁰ in order to reduce finite volume effects. It is of advantage to write a program code which will help to identify the nearest neighbors of some grid-point, since we will need this information in the Metropolis run whenever we calculate the energy difference due to a spin flip according to Eq. (15.49). To help with this task a matrix $$neighbor(site,i)$$ will be generated only once for each choice of the system size N. Here i = 1, 2, 3, 4 are the directions to the neighboring grid-points of the grid-point site. In a first step the sites of the square lattice are relabeled following the scheme¹¹:

(15.50)

In the next step, the matrix $$neighbor$$ is initialized as an array of size N ² × 4. Every site has four nearest neighbors: up, right, down, and left. The corresponding matrix elements for periodic boundary conditions can be evaluated according to the following scheme:

For up we have:

(a)

If $$site + N \leq N^{2}$$: up = site + N,

(b)

else if site + N > N ²: up = site − N(N − 1).

For right we have:

(a)

If mod(site, N) ≠ 0: right = site + 1,

(b)

else if mod(site, N) = 0: right = site − N + 1.

For down we have:

(a)

If site − N ≥ 1: down = site − N,

(b)

else if site − N < 1: down = site + N(N − 1)

For left we have:

(a)

If mod(site − 1, N) ≠ 0: left = site − 1,

(b)

else if mod(site − 1, N) = 0: left = site + N − 1.

In a final step, the array elements are rearranged according to

(15.51)

where site = 1, 2, …, N ².

(2) Initialization

It has already been discussed in Sect. 14.​3 that the quality of random numbers generated with the help of the Metropolis algorithm is highly dependent on the choice of initial conditions. This is, in our case, the initial spin configuration $$\mathcal{C}_{0}$$. Of course, it would be favorable to start with a configuration which was already drawn from the Boltzmann distribution $$p(\mathcal{C})$$. However, in practice this is not feasible ab initio. But, as will be elucidated in Chap. 16, the Metropolis algorithm produces configurations which become independent of the initial state and follow the Boltzmann distribution. Hence we can simply start with some arbitrary configuration and discard it together with the first n constituents of the sequence $$\mathcal{C}_{0},\mathcal{C}_{1},\ldots,\mathcal{C}_{n}$$. This method is referred to as thermalization. ¹² The question arises: can n be determined to ensure that the sequence starting with $$\mathcal{C}_{n+1}$$ will conform to the pdf $$p(\mathcal{C})$$?

There are two different ways to approach this problem: (i) The first is to measure auto-correlations between configurations $$\mathcal{C}_{i}$$ where it has to be ensured that the set of states is sufficiently large to allow for a significant conclusion. We will discuss auto-correlations in more detail in Chap. 19 (ii) The second approach is to empirically check whether equilibrium has been reached or not. For instance, one could simply plot some selected observables and check when the initial bias vanishes. In this case the observable reaches some saturation value as a function of the number of measurements. A particularly useful method is to start the algorithm with at least two different configurations. As soon as equilibrium has been reached, the observables should approach the same saturation values after a certain (finite) number of measurements. Typical choices are the cold start and the hot start . Cold start means that the temperature is initially below the critical temperature, i.e. in the Ising model all spins are aligned (ferromagnetic state). Hot start means that the temperature is well above the critical temperature and for the Ising model the spin orientation is chosen at random for any site (paramagnetic state).

(3) Execution of the Code

The Metropolis algorithm for the Ising model is executed in the following steps:

1.

Choose an initial configuration $$\mathcal{C}_{0}$$.

2.

We migrate through the lattice sites systematically.¹³ Suppose we just reached site (i, j) (we use the double-index notation i, j = 1, 2, …, N, to improve the readability) and our current configuration is $$\mathcal{C}_{k}$$. Then k configurations have been accepted so far. We generate a new configuration $$\mathcal{C}^{t}$$ from $$\mathcal{C}_{k}$$ by replacing in $$\mathcal{C}_{k}$$ the entry $$\sigma _{i,j}$$ by $$-\sigma _{i,j}$$.

3.

The new configuration is accepted with probability

(15.52)

where Δ E ij is determined from Eq. (15.49). $$\mathcal{C}^{t}$$ is accepted if $$\Pr (A\vert \mathcal{C}^{t},\mathcal{C}_{k})$$ is equal to one or if $$\Pr (A\vert \mathcal{C}^{t},\mathcal{C}_{k}) \geq r\, \in \, [0,1]$$ otherwise $$\mathcal{C}^{t}$$ is rejected. If $$\mathcal{C}^{t}$$ was accepted we set $$\mathcal{C}_{k+1} = \mathcal{C}^{t}$$.

4.

Go to the next lattice site [step 2].

We note that instead of sampling the lattice sites sequentially as suggested in step 2 the lattice sites can also be sampled randomly with the help of

(15.53)

where r ∈ [0, 1] is a uniformly distributed random number and int(⋅ ) denotes the integer part of a given quantity. Obviously, Eq. (15.53) is only useful in the single-index notation i = 1, 2, …, N ².

(4) Measurement

As soon as thermalization was achieved the procedure to measure interesting observables can be started. Such a procedure consists of collecting the data required and in calculating expectation values as was illustrated in Eq. (15.47) for the case of the expectation value of the energy. A more detailed study of estimator techniques is postponed to Chap. 19 However, there is one crucial point one should be aware of: We already mentioned in our discussion of the Metropolis algorithm in Sect. 14.​3 that subsequent configurations $$\mathcal{C}_{k}$$ may be strongly correlated. This problem can be circumvented by simply neglecting intermediate configurations. For instance, one may allow a couple of ‘empty’ sweeps between two measurements.

In the following we discuss some selected results obtained with the numerical approach described above.

15.3 Selected Results

We investigate the two-dimensional Ising model with periodic boundary conditions and we chose h = 0 and J = 0. 5 for all following illustrations.

In a first experiment we plan to check the thermalization process and, thus, measure after every single sampling step and skip thermalization. The observables of interest, the expectation value of the energy per particle, $$\left \langle \varepsilon \right \rangle$$, and the expectation value of the magnetization per particle, $$\left \langle m\right \rangle$$, are illustrated in Fig. 15.3 for 30 sweeps in a system of the size N = 50 which corresponds to

Fig. 15.3

Time evolution of (a) the expectation value of the energy per particle $$\left \langle \varepsilon \right \rangle$$ and (b) of the expectation value of the magnetization per particle $$\left \langle m\right \rangle$$ vs the number of measurements M. We used a cold start (solid line) and a hot start (dashed line) to achieve these results

$$m \sim 8 \times 10^{4}$$ measurements. Moreover, we set k B T = 3 which should be well above T C according to Eq. (15.42). Hence, we expect paramagnetic behavior, i.e. $$\left \langle m\right \rangle = 0$$ in the equilibrium since the acceptance probability is rather large because the spins are randomly orientated. In addition, Fig. 15.4 shows a typical

Fig. 15.4

Typical spin configuration for a temperature well above the critical temperature T C . Black shaded areas correspond to spin up sites while the white areas are spin down sites

spin configuration for a temperature well above T C .

According to Fig. 15.3b the expectation value of the magnetization per particle $$\langle m\rangle$$ approaches indeed zero after a rather short thermalization period independent of the starting procedure. This is certainly not the case for the energy expectation value per particle $$\langle \varepsilon \rangle$$, Fig. 15.3a, which does not approach saturation even after $$M \sim 8 \times 10^{4}$$ measurements for both starting procedures. The consequence is that the thermalization period certainly needs to be longer than only 30 sweeps.

Keeping this result in mind we move on to perform the next check of our numerics, namely to study the influence of the system size N on the numerical results we get for the observables $$\left \langle \varepsilon \right \rangle$$, $$\left \langle m\right \rangle$$ as well as c h and χ as functions of temperature T. Let us outline the strategy: a thermalization period of 500 sweeps will be used and 10 sweeps between each measurement will be discarded. Moreover, we start with the hot start configuration and at a temperature $$k_{\mathrm{B}}T_{0} = 3$$ well above T C . After the measurements at T ₀ have been finished, the temperature is slightly decreased, T ₁ < T ₀.

One more point should be addressed: We perform a simulation using the strategy outlined above and obtain as a result some observable O as a function of temperatures {T n }, with T ₀ the initial temperature well above T C and T n+1 < T n . From the physics point of view, this temperature dependence will, of course, be most interesting for temperatures T ≈ T C . Thus, what we need is an adaptive cooling strategy designed in such a way that the temperature is decreased rapidly for temperatures T ≫ T C or $$T \ll T_{C}$$, but for T ≈ T C the temperature is modified only minimally. [This question will also be a very important point in the discussion of simulated annealing, a stochastic optimization strategy (see Sect. 20.​3).] At the moment we are satisfied with equally spaced temperatures, i.e. $$T_{k+1} = T_{k}-\delta$$, where $$\delta = \text{const}$$ because we are mainly interested to study the influence of the system size N on our calculations.

The error bars of the calculated expectation values have been obtained with the help of Eq. (15.47). The error estimates for the heat capacity c h as well as for the magnetic susceptibility χ are more complex to evaluate. The method employed is referred to as statistical bootstrap, where M = 100 samples have been generated. This method will be explained in some detail in Chap. 19

In Fig. 15.5 we compare the expectation value of the energy per particle,

Fig. 15.5

(a) The expectation value of the energy per particle $$\left \langle \varepsilon \right \rangle$$, (b) the absolute value of the expectation value of the magnetization per particle $$\vert \langle m\rangle \vert$$, (c) the heat capacity c h , and (d) the magnetic susceptibility χ vs temperature k B T for the two-dimensional Ising model. The system sizes are N = 5, 20, 50, 100

$$\left \langle \varepsilon \right \rangle$$, the absolute value of the magnetization per particle $$\vert \langle m\rangle \vert$$, the overall heat capacity c h and the overall magnetic susceptibility χ for four system sizes N = 5, 20, 50, 100. Furthermore, in Fig. 15.6 we show the curves for the system size of N = 50 together with corresponding error bars.

Fig. 15.6

(a) The expectation value of the energy per particle $$\left \langle \varepsilon \right \rangle$$, (b) the expectation value of the magnetization per particle $$\vert \langle m\rangle \vert$$, (c) the heat capacity c h , and (d) the magnetic susceptibility χ with error bars vs temperature k B T obtained for the two-dimensional Ising model of size N = 50

We observe that the phase transition becomes sharper with increasing system size. In fact we know, that the phase transition is infinitely sharp as $$N \rightarrow \infty $$ from the analytic solution given by Onsager. It is a quite obvious result of this study that the system size N should be greater than 20 to achieve acceptable results.

Furthermore, we presented the absolute value of the magnetization rather than the magnetization itself. The reason is that for T < T C the ground state is degenerate. In particular, the state with all spins up or all spins down is equally probable since we set the external magnetic field h = 0. This is a manifestation of the $$\mathbb{Z}_{2}$$ symmetry of the Hamiltonian discussed in Sect. 15.1.

Of particular interest is the region around the critical temperature, referred to as the critical region. In this region, the spins are not perfectly aligned and not randomly orientated either. In this region the spins align in so called magnetic domains, which are also referred to as Weiss domains [1]. A typical spin configuration which exhibits such domains is presented in Fig. 15.7.

Fig. 15.7

For T ≈ T C the spins organize in Weiss domains. Here we show a typical spin configuration for N = 100 and k B T = 1. 15. The black shaded areas correspond to spin up sites while the white areas indicate spin down sites

We conclude this chapter with an interesting note: Fig. 15.6 makes it quite clear that the error of the expectation value of the magnetization and of the energy is biggest for values around the transition temperature. In fact, if we increase the system size the error will become even larger. The reason is quite obvious: The error of our Monte-Carlo integration is proportional to the square root of the variance of the investigated observable. However, since we deal with a second order phase transition, this variance tends to infinity as $$N \rightarrow \infty $$ [4]. There is one cure to the problem: We are dealing here with finite-sized systems, thus, the variance will never actually be infinitely large. Furthermore, according to Eq. (15.47) we can decrease the error by increasing the number of measurements. Hence, if one is confronted with large systems, one has also to perform many measurements in order to reduce the error.¹⁴

Summary

The Ising model is a rather simple model which describes effectively a second order phase transition. Such phase transitions are the topic of extensive numerical studies and, therefore, this model served here as a tool to demonstrate how to proceed from the problem analysis to a numerical algorithm which will allow to simulate the physics. The advantage of the Ising model was that under certain simplifications solutions could be derived analytically. In the course of this analysis the important concept of observables was introduced. Observables are certain physical properties of a system which characterize the specific phenomenon of interest. Numerically, observables are certain variables which are to be ‘measured’ within the course of a simulation. After the extensive analysis of the Ising model the transition to the numerical analysis of the two-dimensional Ising model was a rather easy part. The required modification of spin configurations turned out to be the key element of the simulation and this suggested the application of the Metropolis algorithm for sampling. Finally, important problems like initialization of the simulation, thermalization, finite size effects, measurement of observables, and the prevention of correlations between subsequent spin configurations caused by the Metropolis algorithm have been discussed on the basis of concrete calculations. The first part of this chapter was motivated by W. S. Dorn and D. D. McCracken [20]:

Numerical methods are no excuse for poor analysis.

Problems

1.

Write a program to simulate the two-dimensional Ising model with periodic boundary conditions with the help of the Metropolis algorithm. Follow the strategy outlined in Sect. 15.2 and try to reproduce the results illustrated in Sect. 15.3 for N = 5, 20, 50.

In particular, as a first step write a routine which stores the nearest neighbors of the square lattice in an array. As a second step, write a program which performs a sweep through the lattice geometry. You can either choose the lattice sites systematically or at random. As a third step, set up the main program which calls the sweep routine. Choose some initial configuration and thermalize the system. Measure the expectation value of the energy per particle as well as the absolute value of the expectation value of the magnetization for different temperatures k B T and determine the respective errors, see Eq. (15.47). Calculate also the overall magnetic susceptibility and the overall heat capacity. The determination of the error is more complicated in this case and can therefore be neglected for the moment.

Good parameters to start with are J = 0. 5, N therm  = 500, N skip  = 10 and h = 0. 0.

2.

Try also different values of J and h ≠ 0.

References

1.

White, R.M.: Quantum Theory of Magnetism, 3rd edn. Springer Series in Solid-State Sciences. Springer, Berlin/Heidelberg (2007)Crossref

2.

Landau, L.D., Lifshitz, E.M.: Course of Theoretical Physics. Statistical Physics, vol. 5. Pergamon Press, London (1963)

3.

Halley, J.W.: Statistical Mechanics. Cambridge University Press, Cambridge (2006)Crossref

4.

Pathria, R.K., Beale, P.D.: Statistical Mechanics, 3rd edn. Academic, San Diego (2011)MATH

5.

Baym, G.: Lectures on Quantum Mechanics. Lecture Notes and Supplements in Physics. The Benjamin/Cummings, London/Amsterdam (1969)MATH

6.

Cohen-Tannoudji, C., Diu, B., Laloë, F.: Quantum Mechanics, vol. I. Wiley, New York (1977)MATH

7.

Sakurai, J.J.: Modern Quantum Mechanics. Addison-Wesley, Menlo Park (1985)

8.

Ballentine, L.E.: Quantum Mechanics. World Scientific, Hackensack (1998)CrossrefMATH

9.

Arnol’d, V.I.: Mathematical Methods of Classical Mechanics, 2nd edn. Graduate Texts in Mathematics, vol. 60. Springer, Berlin/Heidelberg (1989)

10.

Goldstein, H., Poole, C., Safko, J.: Classical Mechanics, 3rd edn. Addison-Wesley, Menlo Park (2013)MATH

11.

Scheck, F.: Mechanics, 5th edn. Springer, Berlin/Heidelberg (2010)CrossrefMATH

12.

Mandl, F.: Statistical Physics, 2nd edn. Wiley, New York (1988)

13.

Schwabl, F.: Statistical Mechanics. Advanced Texts in Physics. Springer, Berlin/Heidelberg (2006)MATH

14.

Ising, E.: Beitrag zur Theorie des Ferromagnetismus. Z. Phys. 31, 253 (1925)ADSCrossref

15.

Onsager, L.: Crystal statistics, I. A two-dimensional model with an order-disorder transition. Phys. Rev. 65, 117–149 (1944). doi:10.1103/PhysRev.65.117MathSciNetMATH

16.

Hardy, R.J., Binek, C.: Thermodynamics and Statistical Mechanics: An Integrated Approach. Wiley, New York (2014)CrossrefMATH

17.

Kwak, J.H., Hong, S.: Linear Algebra. Springer, Berlin/Heidelberg (2004)CrossrefMATH

18.

Strang, G.: Introduction to Linear Algebra, 4th edn. Cambridge University Press, Cambridge (2009)MATH

19.

Stauffer, D., Hehl, F.W., Ito, N., Winkelmann, V., Zabolitzky, J.G.: Computer Simulation and Computer Algebra, pp. 79–84. Springer, Berlin/Heidelberg (1993)

20.

Dorn, W.S., McCracken, D.D.: Numerical Methods with Fortran IV Case Studies. Wiley, New York (1972)MATH

Footnotes

1

For a short introduction to phase transitions in general please consult Appendix F.

2

The statement that magnetism is a purely quantum-mechanical phenomenon that cannot explained in classical terms is known as the Bohr-van Leeuwen theorem [3, 4].

3

In this discussion we regard the spin as a classical quantity. In the quantum mechanic case one has to replace the vectors by vector operators S i .

4

We note in passing that the Hamiltonian (15.4) is invariant under a spin flip of all spins if h = 0 ($$\mathbb{Z}_{2}$$ symmetry). This symmetry is broken if h ≠ 0, i.e. the spins align with the external field h.

5

We note that $$H \propto \mu \cdot B$$ where B is the magnetic field and μ is the magnetic moment. Furthermore, μ can be expressed as $$\mu = -\mu _{B}gS/\hslash = -\mu _{B}g\sigma /2$$, where μ B is the Bohr magneton, g is the Landé g-factor and $$\sigma$$ is the vector of Pauli matrices. The sign is convention.

6

In particular we assume ergodicity of the system as will be explained in Chap. 16

7

$$\left \langle E\right \rangle$$ is also referred to as internal energy U.

8

We transform

and use that

9

In particular $$\text{var}\left (E\right ) = \left \langle E^{2}\right \rangle -\left \langle E\right \rangle ^{2}$$ is to be determined and only the second term is already known. The first term, $$\left \langle E^{2}\right \rangle$$, is then estimated with the help of

10

Periodic boundary conditions in two dimensions imply that

for all i, j.

11

In the following we will refer to the notation (i), $$i = 1, 2,\ldots,N^{2}$$ as the single-index notation while the notation (i, j), $$i,j = 1, 2,\ldots,N$$ will be referred to as the double-index notation.

12

The number of configurations discarded is referred to as the thermalization length.

13

A migration through all lattice sites is referred to as a sweep.

14

We note from Eq. (15.47) that we have to perform four times as many measurements in order to reduce the error by a factor 2.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_16

16. Some Basics of Stochastic Processes

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

16.1 Introduction

This chapter is devoted to an introduction to some basic concepts of stochastic processes. This introduction serves two purposes: First of all, it allows for a more systematic treatment of non-deterministic methods in Computational Physics which is certainly necessary if we really aim at an understanding of these methods. The second reason can be found in the elementary importance of stochastics in modern theoretical physics and chemistry in general. Hence, many of the concepts elaborated within this chapter will be of profound importance in subsequent chapters. For instance, we present a discussion of diffusion theory in Chap. 17 as a motivating example.

The reader not familiar with the basics of probability theory [1–4] is highly encouraged to at least consult Appendix E before proceeding. In particular, we are going to apply the notation introduced in Appendix E throughout this chapter.

The basics of stochastic processes will be discussed within five sections including this introduction. In Sect. 16.2 we introduce basic definitions associated with stochastic processes in general. Here we discuss concepts which will serve as a basis for an understanding of the methods presented within the subsequent sections. Section 16.3 deals with a special class of stochastic processes, the so called Markov processes. As we shall see, these processes are of fundamental importance for statistical physics and for computational methods. Moreover, in Sect. 16.4 we consider so called Markov-chains which are discrete Markov processes defined on a discrete time span. This will serve as the basis of a very important method in computational physics, the so called Markov-Chain Monte Carlo technique. We already encountered a simple example of this method in Sect. 14.​3 and in Chap. 15, the Metropolis algorithm. Finally, in Sect. 16.5 continuous-time Markov-chains will be discussed, in particular, discrete Markov processes on a continuous time span. These processes are very important, for instance, in diffusion theory as will be demonstrated in Chap. 17.

A discussion of detailed balance will also be included in the section on Markov processes, Sect. 16.3, although detailed balance follows from physical arguments. Detailed balance has already been introduced in our discussion of the Metropolis algorithm, Sect. 14.​3.

16.2 Stochastic Processes

The following discussion is primarily restricted to one-dimensional processes.

A stochastic process is a time dependent process depending on randomness [5–7]. From a mathematical point of view, a stochastic process Y X (t) is a random variable Y which is a function of another random variable X and time t ≥ 0:

(16.1)

Here we apply the notation of Appendix E and denote random variables by capital letters, such as X, and their realization by lower case characters, such as x. Consequently, the realization of a stochastic process is described by

(16.2)

The set of all possible realizations of Y X (t) spans the state space of the stochastic process. We note that it is in principle not necessary to define t as the time in a classical sense. It suffices to denote t ∈ T, where T is a totally ordered set such as, for instance, $$T = \mathbb{N}$$ the natural numbers. The set T is referred to as the time span . We distinguish four different scenarios:

discrete state space, discrete time span,

continuous state space, discrete time span,

discrete state space, continuous time span,

continuous state space, continuous time span.

Stochastic processes on a continuous time span are referred to as continuous-time stochastic processes.

Suppose the random variable X follows the pdf p X (x). It is then an easy task to calculate averages $$\left \langle Y (t)\right \rangle$$ of the stochastic process Y X (t) via

(16.3)

This concept is easily extended to multiple times t ₁, t ₂, …, t n by

(16.4)

which defines the moments of the stochastic process [1, 5, 8]. Similar to the concept of the correlation coefficient (see Appendix, Sect. E.10) we define the so called auto-correlation function κ(t ₁, t ₂):

(16.5)

The function γ[Y (t ₁), Y (t ₂)] is referred to as the auto-covariance function and is defined as

(16.6)

We proceed by defining the pdf of a stochastic process Y X (t). The pdf p ₁(y, t), which describes the probability that the stochastic process Y X (t) takes on its representation y at time t, is given by (see Sect. 14.​2)

(16.7)

We define, in analogy, the pdf p n (y ₁, t ₁, y ₂, t ₂, …, y n , t n ) which describes the probability that the stochastic process takes on the realization y ₁ at time t ₁, y ₂ at time t ₂, …, and y n at time t n for arbitrary n:

(16.8)

This is referred to as the hierarchy of pdfs. We note the following important properties of the pdf p n (y ₁, t ₁, y ₂, t ₂, …, y n , t n ) [8]:

$$p_{n}(y_{1},t_{1},y_{2},t_{2},\ldots,y_{n},t_{n}) \geq 0\;,$$ (16.9)

$$p_{n}(\ldots,y_{k},t_{k}\ldots,y_{\ell},t_{\ell},\ldots ) = p_{n}(\ldots,y_{\ell},t_{\ell}\ldots,y_{k},t_{k},\ldots )\;,$$ (16.10)

$$\int \mathrm{d}y_{n}\,p_{n}(y_{1},t_{1},\ldots,y_{n},t_{n}) = p_{n-1}(y_{1},t_{1},\ldots,y_{n-1},t_{n-1})\;,$$ (16.11)

$$\int \mathrm{d}yp_{1}(y,t) = 1\;.$$ (16.12)

The moments defined in Eq. (16.4) can also be expressed with the help of the pdfs p n by

(16.13)

Conditional pdfs p ℓ | k can also be introduced. They describe the probability that we have y k+1 at t k+1, …, y k+ℓ at t k+ℓ if there existed y ₁ at t ₁, …, y k at t k via

(16.14)

It follows that

(16.15)

Let us give some further definitions [8]:

A stochastic process is referred to as a stationary process if the moments defined in Eq. (16.4) are invariant under a time-shift Δ t:

(16.16)

In particular, one has $$\left \langle Y (t)\right \rangle = \text{const}$$ and the auto-covariance depends only on the time difference $$\vert t_{1} - t_{2}\vert$$:

(16.17)

It is understood that $$\gamma (t) =\gamma (-t)$$. Moreover, we have

(16.18)

and in particular, p ₁(y, t) = p ₁(y).

A time-homogeneous process is a stochastic process whose conditional pdfs are stationary

(16.19)

for all t ₂, τ, s ₂. The pdf p 1 | 1 is referred to as transition probability.

A process of stationary increments is a stochastic process Y X (t) for which the difference Y X (t ₂) − Y X (t ₁) is stationary for all t ₂ − t ₁, with t ₂ > t ₁ ≥ 0. This means, in particular, that the pdf of this process depends only on the time difference t ₂ − t ₁. The quantities Y X (t ₂) − Y X (t ₁) are referred to as increments.

A process of independent increments is a stochastic process Y X (t) for which the differences

are independent for all t n  > t n−1 > … > t ₂ > t ₁.

A Lévy process is a continuous-time stochastic process with stationary independent increments which starts with Y X (0) = 0.

A Gaussian process is a stochastic process Y X (t) for which all finite linear combinations of Y X (t), t ∈ T follow a normal distribution (see Appendix, Sect. E.7). We shall come back to this kind of process in Chap. 17.

A Wiener process is a continuous-time stochastic process with independent increments which starts with Y X (0) = 0 and for which the increments Y X (t ₂) − Y X (t ₁) follow a normal distribution with mean 0 and variance t ₂ − t ₁. The Wiener process is a special case of a Lévy process. One of the main applications of the Wiener process is to study Brownian motion or diffusion. This process will be discussed in more detail in Sect. 16.3 and in Chap. 17.

The random walk is the discrete analogy to the Wiener process [9–11]. This means in particular that if the step size of the random walk goes to zero, the Wiener process is reestablished. This point will be elucidated in Chap. 17.

After stating the most important definitions, we proceed to the next section in which the attention is on a special class of stochastic processes, the so called Markov processes.

16.3 Markov Processes

A Markov process is a stochastic process Y X (t) for which the conditional pdf p 1 | n−1 satisfies for arbitrary n and t ₁ < t ₂ < ⋯ < t n the relation

(16.20)

Hence, a Markov process is a process in which any state y n , t n is uniquely defined by its precursor state $$y_{n-1},t_{n-1}$$ and is independent of the entire rest of the past [12]. Markov processes are of particular importance in natural sciences because of their rather simple structure. This will become clear throughout the rest of this book.

We note in passing that a process with independent increments is always a Markov process because

(16.21)

is satisfied. Since the increment $$Y _{X}(t_{n+1}) - Y _{X}(t_{n})$$ is independent of all previous increments which gave rise to Y X (t n ) by definition, Y X (t n+1) depends only on Y X (t n ), which is exactly the Markov property  (16.20).

The quantity $$p_{1\vert 1}(y_{n},t_{n}\vert y_{n-1},t_{n-1})$$ which appears in Eq. (16.20) is referred to as transition probability. Given the transition probability p 1 | 1 together with the pdf p ₁, one can construct the whole hierarchy of pdfs  (16.8) of the Markov process by calculating successively [8]:

(16.22)

Here we employed definition (16.14) and in the second step of the second equation we employed for p 1 | 2 the Markov property (16.20).

The fact that the whole hierarchy of pdfs can be constructed by repeating the steps illustrated in Eq. (16.22) reveals the rather simple structure of Markov processes. However, Eq. (16.22) contains another useful information. We regard the pdf p ₃ of (16.22) for three successive times t ₁ < t ₂ < t ₃. First we integrate the left-hand side with respect to y ₂ which yields with the help of property (16.10):

(16.23)

Hence, we have

(16.24)

or after dividing both sides by p ₁(y ₁, t ₁) and by keeping in mind Eq. (16.14) we arrive at:

(16.25)

This equation is known as the Chapman-Kolmogorov equation [8, 13]. The interpretation of this equation is straight-forward: the transition probability from (y ₁, t ₁) to (y ₃, t ₃) is equivalent to the transition probability from (y ₁, t ₁) to (y ₂, t ₂) multiplied by the transition probability from (y ₂, t ₂) to (y ₃, t ₃) when summed over all intermediate positions y ₂.

This is illustrated in Fig. 16.1.

Fig. 16.1

Illustration of the Chapmann-Kolmogorov equation

We state a very important theorem: Any two non-negative functions p 1 | 1 and p ₁ uniquely define a Markov process if the Chapman-Kolmogorov equation (16.25) is obeyed and if

(16.26)

which follows immediately from the first equation in Eqs. (16.22) in combination with property (16.10).

As a first example we consider one of the most important Markov processes in physics, the Wiener process [10]. Its importance stems from its application to the description of Brownian motion, the random motion of dust particles on a fluid surface. (In Chap. 17 we take a closer look at diffusion phenomena.) The transition probability of the Wiener process is of the form¹

(16.27)

The initial condition is given by

(16.28)

A straight-forward calculation proves that (16.27) indeed obeys the Chapman-Kolmogorov equation (16.25). Moreover, we deduce from Eqs. (16.28) together with (16.26) that

(16.29)

The Wiener process is easily realized on the computer. We regard the one-dimensional case and start at the origin Y X (0) = 0. As per definition the increments $$Y _{X}(t +\mathrm{ d}t) - Y _{X}(t)$$ follow a normal distribution $$\mathcal{N}(\mathrm{d}y\vert 0,\mathrm{d}t)$$ of mean zero and variance dt. Hence, we start with y ₀ = 0 at time t ₀ = 0, sample the displacement dy within a time-step dt from $$\mathcal{N}(\mathrm{d}y\vert 0,\mathrm{d}t)$$ and calculate the next position at time $$t_{1} = t_{0} +\mathrm{ d}t$$ which is given by: $$y_{1} = y_{0} +\mathrm{ d}y$$.² This process is repeated until a certain time limit has been reached. Figure 16.2 presents the result of three such calculations which have been started using different seeds.

Fig. 16.2

Three possible realizations of the Wiener process

Let us mention a second very important Markov process, the Poisson process. The Poisson process is particularly interesting for problems involving waiting times, such as the decay of some radioactive nucleus. However, we shall also come across the Poisson process within the context of diffusion in Chap. 17. The transition probability of the Poisson process is defined as

(16.30)

Here it is understood that $$n_{1},n_{2} \in \mathbb{N}$$ and n ₂ > n ₁. Hence, the Poisson process counts the number of occurrences n ₂ of a certain event until the time t ₂ is reached under the premise that n ₁ events have already occurred at time t ₁. The Poisson process is initialized by the pdf

(16.31)

here δ ij is the Kronecker-δ. Hence we have according to Eq. (16.26)

(16.32)

which is a Poisson distribution (see Appendix, Sect. E.4 and, for instance, Ref. [14]). Let us briefly consider the time between two events. Suppose we had n ₁ events at time t ₁. Then, we calculate the probability that at time $$t_{2} = t_{1}+\tau$$ we still counted n ₂ = n ₁ events, thus, nothing happened. We have

(16.33)

and the waiting times are independent and follow an exponential distribution. We may simulate the Poisson process by starting at t ₁ = 0 with n ₁ = 0 and by

increasing n ₂, n ₃, … by one, i.e. $$n_{i+1} = n_{i} + 1$$ after successive waiting times τ ₁, τ ₂, … which we sample from the exponential distribution (see Sect. 13.​2) until a final count N has been reached. The result of such a procedure is illustrated in Fig. 16.3 where n(t) vs t has been plotted for three runs started by different seeds.

Fig. 16.3

Three possible realizations of a Poisson process

Finally, we remark that for a time-homogeneous Markov process the transition probability p 1 | 1(y ₂, t ₂ | y ₁, t ₁) depends by definition on the time difference t ₂ − t ₁ ≡ τ rather than explicitly on the two times t ₁ and t ₂ and is usually denoted by T τ (y ₂, y ₁).

We turn now our attention to another very important general concept of Markov processes, the master equation [8]. This equation is in fact the differential form of the Chapman-Kolmogorov equation. We regard the Chapman-Kolmogorov equation (16.25) for three successive times $$t_{1} &lt; t_{2} &lt; t_{3} = t_{2}+\tau$$ where τ is assumed to be small, i.e. τ ≪ 1. We expand the conditional pdf p 1 | 1 in a Taylor series with respect to τ:

(16.34)

In order to transform this equation into a more transparent form, we introduce the transition rate w(y ₃ | y ₂, t ₂) from y ₂ to y ₃, with y ₂ ≠ y ₃:

(16.35)

In addition, we note that the first term on the right-hand side of Eq. (16.34) has to be of the form:

(16.36)

On the other hand, we defined the transition rate (16.35) only for elements y ₂ ≠ y ₃ and, thus, we denote the remaining part (i.e. y ₂ = y ₃) by a(y ₂, t ₂). All this allows us to rewrite Eq. (16.34) as

(16.37)

where we neglected terms of order $$\mathcal{O}(\tau ^{2})$$. The pdf p 1 | 1(y ₃, t ₂ +τ | y ₂, t ₂) is subject to the normalization (16.15) and this provides us with the required condition to determine a(y ₂, t ₂):

(16.38)

Hence, the term 1 + a(y ₂, t ₂) describes the probability that no event occurs within the time interval [t ₂, t ₂ +τ]. The expansion (16.37) is inserted into the Chapman-Kolmogorov equation (16.25) with the result:

(16.39)

Finally, we arrive, in the limit τ → 0, at the master equation:

(16.40)

We multiply this equation by p ₁(y′, t′) and integrate over y′. This results in the master equation for the pdf p ₁(y, t)

(16.41)

where we made use of the property (16.26).

Let us briefly discuss this result: In its derivation we assumed the state space to be continuous. However, if a master equation for a discrete state space is required the integral is to be replaced by a sum over the discrete states. On the other hand, the physical interpretation of such an equation is straight-forward: The time evolution of the quantity p ₁(y, t) is governed by the sum over all transitions into state y (first term) minus all transitions out of state y. We remark that master equations occur commonly in physical applications; for instance, the collision integral of the Boltzmann equation is of a similar form. The transitions rates w(y | y′, t) can be determined explicitly in many applications in physics.³

Furthermore, if the system is in a stationary state then it is described by a stationary distribution p ₁(y, t) = p ₁(y) and we obtain from (16.41) the relation

(16.42)

which is referred to as global balance. The much stronger condition

(16.43)

is referred to as detailed balance and will be discussed next.

The task now is to prove that the equilibrium distribution function p e (X) of a classical physical system will, under certain restrictions, indeed fulfill detailed balance. (This proof was given by N.G. van Kampen [5].) The next steps of the proof become more transparent if a vector $$x = (q_{k},p_{k})^{T} \in \mathbb{R}^{6N}$$ is introduced which represents the phase space trajectory of the N particles constituting the system under investigation. This trajectory is determined by Hamilton’s equations of motion [16–18]:

(16.44)

Furthermore, Y X (t) denotes a stochastic process which describes some observable of the physical system. We require that Y X (t) is invariant under time reversal. We also assume the equilibrium distribution function p e (x) to be invariant under time reversal, which in most cases is equivalent to the requirement that the Hamilton function H(x) is invariant under time reversal. The operation of time reversal will be indicated by bared variables:

(16.45)

Hence, the above assumptions result in

(16.46)

and

(16.47)

In particular, we deduce from Eq. (16.46) that

(16.48)

and

(16.49)

We calculate the pdf p ₂ from

(16.50)

However, since we integrate over the whole phase space we recognize that the volume is invariant under a change $$\mathrm{d}x \rightarrow \mathrm{ d}\overline{x}$$. Thus, we can change the variable of integration from x to $$\overline{x}$$ and this results in:

(16.51)

We obtain immediately:

(16.52)

Differentiation of this equation with respect to t together with definition (16.35) yields for small values of t

(16.53)

which is the condition of detailed balance, Eq. (16.43), for stationary distributions.

It should be noted at this point that detailed balance in physical systems is strongly connected to the entropy growth (the H-theorem by Boltzmann [19]). Here, detailed balance was based on the condition that the stochastic process Y X (t) was invariant under time reversal and that the equilibrium distribution p e (x) had the same property. This has in most cases the consequence that the Hamilton function is also invariant under time reversal transformations. However, a detailed discussion of these properties is far beyond the scope of this book.

We continue our presentation with so called Markov-chains which are a special class of Markov processes. Markov-chains will prove to be very important for the understanding of Markov-chain Monte Carlo techniques, such as the Metropolis algorithm.

16.4 Markov-Chains

A Markov-chain is a time-homogeneous Markov process defined on a discrete time span and in a discrete state space [20–22]. Hence, we express the time instances by integers $$T = \mathbb{N}$$, t n  = n where $$n \in \mathbb{N}$$ and possible outcomes are indexed by integers Y X (t n ) ∈ { m} where $$m \in \mathbb{N}$$. As a first consequence of the discreteness of the state space we replace all pdfs p(⋅ ) by probabilities $$\Pr (\cdot )$$. Hence the Markov property  (16.20) reads

(16.54)

where we applied the notation Y n  ≡ Y X (t n ) and y n  ∈ { m} is one particular realization out of the discrete state space. Since we assume the transition probabilities to be independent of the actual time, we can define a transition matrix P = { p ij } via

(16.55)

Consequently, we write

(16.56)

We note that the transition matrix is a stochastic matrix, a matrix with only non-negative elements such that the sum of each row is equal to one. Furthermore, one can prove that the product of two stochastic matrices results, again, in a stochastic matrix.

We define the state vector at time n, π (n) = {π i (n)} as

(16.57)

From the marginalization rule (Appendix, Sect. E.6) follows for the particular case n = 1

(16.58)

or with the help of the definitions (16.55) and (16.57):

(16.59)

Hence, we get for n = 1

(16.60)

and for n = 2

(16.61)

Obviously,

(16.62)

follows for arbitrary n. Hence the probability matrix for an n step transition P (n) is given by P (n) = P n . We immediately deduce that the Chapman-Kolmogorov equation for Markov-chains is fulfilled since

(16.63)

for two integers n and m.

Let us cite some further definitions in order to classify Markov-chains [5, 8, 20–22]:

The notation $$i \rightarrow j$$ means state i leads to state j and is true whenever there is a path of length n, $$i_{0} = i,i_{1},\ldots,i_{n} = j$$ such that all $$p_{i_{k}i_{k+1}} &gt; 0$$ for $$k = 0,1,\ldots,n - 1$$. This is equivalent to (P n ) ij  > 0.

The notation $$i \leftrightarrow j$$ means state i communicates with state j. This relation is true whenever $$i \rightarrow j$$ and $$j \rightarrow i$$.

A class of states is given if (i) all states within one class communicate with each other and (ii) two states of different classes never communicate with each other. These classes are referred to as the irreducible classes of the Markov-chain.

An irreducible Markov -chain is a Markov-chain in which the whole state space forms an irreducible class, i.e. all states communicate with each other.

A closed set of states is a set of states which never leads to states which are outside of this set.

An absorbing state is a state which does not lead to any other states: It forms itself a closed set. An absorbing state can be reached from the outside but there is no escape from it.

A state is referred to as transient if the probability of returning to the state is less than one.

A state is referred to as recurrent if the probability of returning to the state is equal to one.

Furthermore, we call a state positive recurrent if the expectation value of the first return time is less than infinity and null recurrent if it is infinity. We may formulate this in a more mathematical language: The time of first return to state i is defined via

(16.64)

The probability that we return to state i for the first time after n steps is defined as

(16.65)

Hence, a state is referred to as recurrent if

(16.66)

positive recurrent if

(16.67)

and null recurrent if

(16.68)

We note that we also have $$\left \langle T_{i}\right \rangle = \infty $$ if state i is transient. Furthermore, one can show that a state is only recurrent if

(16.69)

A state is referred to as periodic if the return time of the state can only be a multiple of some integer d > 1.

A state is referred to as aperiodic if d = 1.

We call a state ergodic if it is positive recurrent and aperiodic.

A Markov-chain is called ergodic if all its states are ergodic.

We give some useful theorems in the context of the above definitions: First of all, it can be proved that if a Markov-chain is irreducible it follows that either all states are transient, or all states are null recurrent, or all states are positive recurrent.

Furthermore, a theorem by Kolmogorov states that if a Markov-chain is irreducible and aperiodic then the limit

(16.70)

exists. It follows from the above discussion that if all states j are transient or null recurrent we have

(16.71)

and if all states j are positive recurrent, we have

(16.72)

In this case the state vector π = {π j } is referred to as the stationary distribution or equilibrium distribution. We note that in this context the term equilibrium does not mean that nothing changes, but that the system forgets its own past. In particular, as soon as the system reaches the stationary distribution, it is independent of the initial state π ⁽⁰⁾.

We concentrate now on equilibrium distributions. It follows from Eq. (16.62) that π satisfies:

(16.73)

Thus, π is the left-eigenvector to the transition probability matrix P with eigenvalue 1. We note that Eq. (16.73) states a homogeneous eigenvalue problem: The solution is only determined up to a constant multiplicator (see Sect. 8.​3). However, it is clear that the vector π satisfies

(16.74)

One can prove that the unique solution of the eigenvalue problem (16.73) together with the normalization condition (16.74) for n states can be written as

(16.75)

where e is an n-element row vector containing only ones, E is a n × n matrix containing only ones and I is the n × n identity.

Let us briefly elaborate on this point: if it is possible to construct a Markov-chain which possesses a unique stationary distribution, we know that it will definitely reach this distribution independent of the choice of initial conditions. The existence as well as the form of the stationary distribution is clearly determined by the transition probabilities p ij . A sufficient condition for a unique stationary distribution to exist is the requirement of reversibility. A Markov-chain is referred to as reversible if

(16.76)

i.e. if the transition probabilities ensure detailed balance for the stationary distribution π.

Now we are in a position to understand better why detailed balance was such an important concept of the Metropolis algorithm discussed in Sect. 14.​3: Invoking the detailed balance condition ensures that for all possible initial states the Markov-chain converges toward the equilibrium distribution for which detailed balance is fulfilled. Of course, the convergence time will highly depend on the choice of the initial state as well as on the choice of the transition matrix. Hence, we can generate random numbers with the help of such a Markov-chain and after a thermalization period these numbers will follow the required pdf. Methods based on this concept are commonly referred to as Markov -chain Monte Carlo sampling methods [23–26].

We give a brief example, the spread of a rumor. Let Z ₁ and Z ₂ be two distinct versions of a report. If a person receives report Z ₁ it will pass this report on as Z ₁ with probability (1 − p) or as Z ₂ with probability p. An alternative is that the person receives Z ₂ and passes it on as Z ₂ with probability (1 − q) or modifies it to Z ₁ with probability q. We summarize

$$\Pr (Z_{1} \rightarrow Z_{1}) = (1 - p) = p_{11}$$ ,

$$\Pr (Z_{1} \rightarrow Z_{2}) = p = p_{12}$$ ,

$$\Pr (Z_{2} \rightarrow Z_{1}) = q = p_{21}$$ ,

$$\Pr (Z_{2} \rightarrow Z_{2}) = (1 - q) = p_{22}$$ .

The transition matrix is of the form

(16.77)

We note that the two states communicate with each other $$Z_{1} \leftrightarrow Z_{2}$$, hence the Markov-chain is irreducible. Furthermore, since the process can reach either state Z ₁ or Z ₂ within a single time step, it is clearly aperiodic. Let us briefly investigate the probabilities of first recurrence f ii n after n steps. Due to the theorem by Kolmogorov it is sufficient to investigate the state Z ₁ since the Markov-chain is irreducible and it follows that also Z ₂ has the same recurrence properties. We note the following possible paths for a first return to state Z ₁:

$$1: \quad \Pr (Z_{1} \rightarrow Z_{1}) = (1 - p) = f_{11}^{1}$$ ,

$$2: \quad \Pr (Z_{1} \rightarrow Z_{2} \rightarrow Z_{1}) = pq = f_{11}^{2}$$ ,

$$3: \quad \Pr (Z_{1} \rightarrow Z_{2} \rightarrow Z_{2} \rightarrow Z_{1}) = p(1 - q)q = f_{11}^{3}$$ ,

$$n: \quad \Pr (Z_{1} \rightarrow Z_{2} \rightarrow \cdots \rightarrow Z_{2} \rightarrow Z_{1}) = p(1 - q)^{n-2}q = f_{11}^{n}$$ .

The probability of returning to Z ₁ is, see Eq. (16.66),

(16.78)

where we employed that 0 < (1 − q) < 1 as well as the convergence of the geometric series. Hence state Z ₁ is recurrent and, therefore, also state Z ₂. We calculate the expectation value of the first return time $$\left \langle T_{1}\right \rangle$$:

(16.79)

Hence, the states Z ₁ and Z ₂ are positive recurrent as long as p ≠ 0 and q ≠ 0. This means that an equilibrium distribution exists and it can be obtained from Eq. (16.70). We have

(16.80)

Due to the normalization condition (16.74) we obtain

(16.81)

and, therefore,

(16.82)

Since all states are positive recurrent and aperiodic, the above Markov-chain is ergodic. Finally, we remark that this example also fulfills detailed balance since

(16.83)

Let us briefly interpret this example: Suppose the original, true version Z ₁ of a report is ‘Mr. X is going to resign’ while Z ₂ is just the opposite: ‘Mr. X is not going to resign’. The property of irreducibility of the Markov-chain reflects the fact that there is no version of the report which cannot be reached or modified. Moreover, we just demonstrated that the process is positive recurrent: Even if the probability p that Z ₁ was modified to Z ₂ is very small and the probability q that Z ₂ was modified to Z ₁ is very high, the report will infinitely often return to version Z ₂ with probability one. This means that the public will be told infinitely often that Mr. X is not going to resign with probability one. The equilibrium probabilities π ₁ and π ₂ display the asymptotic probability of versions one and two of the report, respectively. However, as has already been emphasized, this does not mean that the report cannot be modified in equilibrium, it simply displays the fact that the probabilities reached a steady state. Finally, we note an interesting effect in passing: Suppose that the probabilities that any of the two versions is modified is very small but equal, i.e. p = q ≪ 1. Then the equilibrium distribution is

(16.84)

and the public will believe Z ₁ and Z ₂ with the same probability after some time independently of the initial version and also independent of the actual decision of Mr. X. Detailed balance expresses the property that the probability of receiving Z ₂ and passing it on as Z ₁ is the same as the probability of receiving Z ₂ and passing it on as Z ₁.

We close this section with a final remark: It is an easy task to generalize the ideas of Markov-chains to continuous state spaces since we already introduced the required tools in Sect. 16.3. Let π(x) denote the stationary distribution density and p(x | y) the accompanying transition rate pdf. Then relation (16.73) transforms into

(16.85)

together with

(16.86)

the usual normalization of pdfs. In this case, the condition of detailed balance is given by

(16.87)

which is equivalent to Eq. (16.52).

16.5 Continuous-Time Markov-Chains

A generalization of the results of the previous sections to a continuous time span is straight-forward. We define the continuous-time Markov-chain as a time-homogeneous Markov process on a discrete state space but with a continuous time span, t ≥ 0. Thus

(16.88)

is independent of s ≥ 0. In this case the transition matrix P(t) = { p ij (t)} is an explicit function of time t. Its elements p nm (t) have the following four properties:

(a)

All matrix elements p nm (t) of the transition matrix P are positive:

(16.89)

(b)

The usual normalization of the rows of the transition matrix P is valid:

(16.90)

(c)

As for every Markov process, the transition matrix of the continuous time Markov-chain obeys the Chapman-Kolmogorov equation:

(16.91)

which can alternatively be expressed as

(16.92)

(d)

We assume p nm (t) to be a continuous function of t and that:

(16.93)

It follows from this equation that the matrix elements p nm (t) can be written as

(16.94)

where we introduced with $$\lbrace q_{nm} \rbrace = {Q}$$ the transition rate matrix. The transition rate matrix Q obeys:

(a)

All off-diagonal elements q nm , n ≠ m, are non-negative since

(16.95)

(b)

All diagonal elements q nn are non-positive since

(16.96)

(c)

Differentiating Eq. (16.90) with respect to t yields that the sum over all elements in a row is equal to zero. Therefore, we conclude:

(16.97)

Moreover, differentiating the Chapman-Kolmogorov equation with respect to t or t′ gives the Kolmogorov forward – or Kolmogorov backward equations

(16.98)

respectively. We obtain $$P(t) =\exp \left (Qt\right )$$ where the exponential function of a matrix has to be interpreted as

(16.99)

where Q ⁰ = I is the identity matrix.

We define s as the time of the first jump of our process for the particular case X(0) = n

(16.100)

It can be shown that P n (s > t), the probability that the jump occurs at some time s > t, is given by

(16.101)

where we note that q nn  ≤ 0. Moreover,

(16.102)

and the process starts again at time s and in state m. This means that in a continuous-time Markov-chain the waiting times between two consecutive jumps are exponentially distributed. One of the simplest examples of a continuous time Markov-chain is the Poisson process, discussed in Sect. 16.3.

Summary

This chapter introduced the concept of stochastic processes Y X (t) as ‘time’ dependent processes depending on randomness. Y was a random variable which depended on another random variable X and t, the time. All realizations of Y X (t) spanned the state space. Each stochastic process was coupled to a pdf which described the probability that the process took on the realization y at time t. In the course of this introduction a series of general properties which classify such processes were defined. This was followed by the discussion of a particular class of stochastic processes, the Markov processes. They had the remarkable property that a future realization of the process solely depended on its current realization and not on the history how this current realization had been reached (Markov property). A huge class of processes in physics and related sciences is Markovian in nature. The next refinement in our discussion was the introduction of Markov-chains. These were processes defined on a discrete time span and in a discrete state space. This allowed to replace the pdfs by probabilities. Again, various specific properties of Markov-chains opened the possibility of a distinctive classification. A very important observation was that under certain conditions a Markov-chain reached a stationary or equilibrium distribution and that it definitely arrived at this distribution independent of the choice of initial conditions. Moreover, detailed balance was obeyed by this equilibrium condition. This observation was the backbone of Markov-chain Monte Carlo sampling methods, in particular of the Metropolis algorithm. Finally, continuous-time Markov-chains were discussed.

Problems

1.

Write a program to simulate the Wiener process in one dimension. Follow the method explained in Sect. 16.2 and perform the following analysis:

a.

Illustrate graphically some typical sample paths.

b.

Calculate the mean $$\left \langle x(t)\right \rangle$$ and the variance var[x(t)] by restarting the process several times with different seeds and plot the result.

c.

Measure the position x of the particle at a particular time t for several runs (with different seeds) and illustrate the result p(x, t) graphically.

2.

Realize numerically a Poisson process according to the instructions given in Sect. 16.2. Again, plot some typical sample paths. Moreover, calculate the mean waiting time $$\left \langle \tau \right \rangle$$ as well as the variance $$\text{var}\left (\tau \right )$$ numerically as well as analytically.

References

1.

Chow, Y.S., Teicher, H.: Probability Theory, 3rd edn. Springer Texts in Statistics. Springer, Berlin/Heidelberg (1997)CrossrefMATH

2.

Kienke, A.: Probability Theory. Universitext. Springer, Berlin/Heidelberg (2008)

3.

Stroock, D.W.: Probability Theory. Cambridge University Press, Cambridge (2011)MATH

4.

von der Linden, W., Dose, V., von Toussaint, U.: Bayesian Probability Theory. Cambridge University Press, Cambridge (2014)CrossrefMATH

5.

van Kampen, N.G.: Stochastic Processes in Physics and Chemistry. Elsevier, Amsterdam (2008)MATH

6.

Gardiner, C.: Stochastic Methods. Springer Series in Synergetics. Springer, Berlin/Heidelberg (2009)MATH

7.

Chiasson, J.: Introduction to Probability Theory and Stochastic Processes. Wiley, New York (2013)MATH

8.

Breuer, H.P., Petruccione, F.: Open Quantum Systems, chap. 1 Clarendon Press, Oxford (2010)

9.

Montroll, E.W., Schlesinger, M.F.: The wonderful world of random walks. In: Lebowitz, J.L., Montroll, E.W. (eds.) Non-equilibrium Phenomena II. Studies in Statistical Mechanics, vol. 11. North-Holland, Amsterdam (1984)

10.

Rudnik, J., Gaspari, G.: Elements of the Random Walk. Cambridge University Press, Cambridge (2010)

11.

Ibe, O.C.: Elements of Random Walk and Diffusion Processes. Wiley, New York (2013)CrossrefMATH

12.

Marcus, M.B., Rosen, J.: Markov Processes, Gaussian Processes, and Local Times. Cambridge University Press, Cambridge (2011)MATH

13.

Papoulis, A., Pillai, S.: Probability, Random Variables and Stochastic Processes. McGraw Hill, New York (2001)

14.

Knuth, D.: The Art of Computer Programming, vol. II, 3rd edn. Addison Wesley, Menlo Park (1998)

15.

Ballentine, L.E.: Quantum Mechanics. World Scientific, Hackensack (1998)CrossrefMATH

16.

Arnol’d, V.I.: Mathematical Methods of Classical Mechanics, 2nd edn. Graduate Texts in Mathematics, vol. 60. Springer, Berlin/Heidelberg (1989)

17.

Scheck, F.: Mechanics, 5th edn. Springer, Berlin/Heidelberg (2010)CrossrefMATH

18.

Goldstein, H., Poole, C., Safko, J.: Classical Mechanics, 3rd edn. Addison-Wesley, Menlo Park (2013)MATH

19.

Pathria, R.K., Beale, P.D.: Statistical Mechanics, 3rd edn. Academic, San Diego (2011)MATH

20.

Norris, J.R.: Markov Chains. Cambridge Series in Statistical and Probabilistic. Cambridge University Press, Cambridge (1998)MATH

21.

Modica, G., Poggiolini, L.: A First Course in Probability and Markov Chains. Wiley, New York (2012)CrossrefMATH

22.

Graham, C.: Markov Chains: Analytic and Monte Carlo Computations. Wiley, New York (2014)CrossrefMATH

23.

Fishman, G.S.: Monte Carlo: Concepts, Algorithms and Applications. Springer Series in Operations Research. Springer, Berlin/Heidelberg (1996)CrossrefMATH

24.

Doucet, A., de Freitas, N., Gordon, N. (eds.): Sequential Monte Carlo Methods in Practice. Information Science and Statistics. Springer, Berlin/Heidelberg (2001)MATH

25.

Kalos, M.H., Whitlock, P.A.: Monte Carlo Methods, 2nd edn. Wiley, New York (2008)CrossrefMATH

26.

Kroese, D.P., Taimre, T., Botev, Z.I.: Handbook of Monte Carlo Methods. Wiley, New York (2011)CrossrefMATH

Footnotes

1

This form is equivalent to the above definition of the Wiener process, in particular to the requirement of normally distributed increments with variance t ₂ − t ₁.

2

Alternatively, we may sample dy from a normal distribution with variance 1 and multiply it by $$\sqrt{\mathrm{d}t}$$. This follows from a simple transformation of variables.

3

As an example we quote Fermi’s golden rule [15], where the transition rate w nn′ from unperturbed states n to n′ is of the form

where H nn′′ are the matrix elements of the perturbation Hamiltonian H′ and ρ(E n ) denotes the density of states of the unperturbed system.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_17

17. The Random Walk and Diffusion Theory

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

17.1 Introduction

Diffusion is one of the most widely spread processes in science. Its occurrence ranges from random motion of dust particles on fluid surfaces, historically known as Brownian motion, to the motion of particles in numerous physical systems [1, 2], the spreading of malaria by migration of mosquitoes [3], or even to the description of fluctuations in stock markets [4].

For instance, let us regard N neutral, identical, classical particles which solely interact through collisions, for instance an H₂-gas in a box, where $$N = N_{A} \approx 6.022 \times 10^{23}$$. We are interested in the dynamics of one particle under the influence of all others and under no influence by an external force; we expect that diffusion will be the dominating process. From the microscopic point of view such a situation can be described with the help of N coupled Newton’s equations of motion. (See Chap. 7) Anyhow, such a task will not be feasible due to the size of the system – the magnitude of N. However, a statistical description can be obtained from Boltzmann’s equation [5]

(17.1)

where f(r, η, t) is the phase space distribution function. Hence, $$f(r,\eta,t)\mathrm{d}r\mathrm{d}\eta$$ is the number of particles of momentum η within the phase-space volume drdη which is centered around position r at time t. We have, in particular:

(17.2)

Here C[ f](r, η, t) is the collision integral and F describes an external force. In cases where collisions result solely from two-body interactions between particles that are assumed to be uncorrelated prior to the collision,¹ the collision integral can be described by

(17.3)

where $$g(\xi _{1},\xi _{2},\xi _{3},\eta )$$ accounts for the probability that a collision between two particles of initial moments $$\xi _{1}$$ and $$\xi _{2}$$ and final momenta $$\xi _{3}$$ and η occurs. This function depends on the particular type of particles under investigation and has, in general, to be determined from a microscopic theory.² We now define the particle density ρ(r, t) as a function of space r and time t via

(17.4)

A complicated mathematical analysis of Eq. (17.1) results in a diffusion equation of the well-known form

(17.5)

if collisions dominate the dynamics (diffusion limit). Here D = const is the diffusion coefficient of dimension length²× time⁻¹. Note that

(17.6)

is the number of particles within our system.³ Thus, in our example we can interpret diffusion as the average evolution of the integrated phase space distribution function governed by collisions between particles. Such an interpretation will certainly not hold in the case of fluctuations in stock markets or in the case of the spreading of malaria because typically mosquitoes do not collide with humans.

It is the aim of the first part of this chapter to present a purely stochastic approach to diffusion, the so called random walk model [7, 8]. This stochastic description will prove to have several precious advantages: (i) We will be able to identify criteria for the validity of the diffusion model even for systems lacking a straight-forward physical interpretation. (ii) The stochastic formulation will give us the opportunity to perform diffusion ‘experiments’ on the computer without much computational effort as the methods employed are based on algorithms discussed in previous chapters. (iii) Within this framework it will be an easy task to generalize the approach to stochastic models of anomalous diffusion [9]: The fractal time random walk and Lévy flight models [10]. These models play an increasingly important role in modern statistical physics.

17.2 The Random Walk

The random walk is one of the classical examples of Markov-chains [11–13]. In this section we discuss some of the basic properties of random walks in one dimension. For convenience, we are going to use the familiar picture of one diffusing particle.

Basics

The random walk [8] is defined as the motion of a single particle which moves at the time instances

(17.7)

between grid-points

(17.8)

For a more transparent notation the lattice point $$n\varDelta x$$, with $$n \in \mathbb{Z}$$, will be denoted by x n and the instance $$k\varDelta t$$, with $$k \in \mathbb{N}$$, will be denoted by t k . This notation follows the conventions of Chap. 2 The initial position is given by

(17.9)

and the transition rates p ij from position i to position j within a single time step $$\varDelta t$$ are defined as

(17.10)

Here p denotes the probability that the particle jumps to the neighboring grid-point on the right-hand side, q stands for the probability that the particle jumps to the neighboring grid-point on the left-hand side, and r denotes the probability of staying at the same-grid point within this time step. Naturally, we have

(17.11)

Consequently, we have a Markov-chain with time instances t n and a state space spanned by the positions x k . Moreover, we note that the stochastic process is clearly irreducible since all states communicate with each other (see Sect. 16.​4). Hence, it follows that either all states are recurrent or all states are transient. Furthermore, in the case that r ≠ 0 the Markov-chain is aperiodic, otherwise the chain is periodic with periodicity d = 2 because it takes at least two steps to return to the starting position.

We concentrate first on the classical random walk that is a one-dimensional random walk with $$\varDelta t =\varDelta x = 1$$, r = 0, and $$p + q = 1$$. This ensures that the probability of remaining in the actual position within one time step is equal to zero. If, furthermore, $$p = q = 1/2$$ the random walk is referred to as unbiased and for p ≠ q we call it biased . We write the position X(t n ) = x n at time t n  = n as

(17.12)

where $$\xi _{i} \in \{-1,1\}$$ and $$\Pr (\xi _{i} = +1) = p$$, $$\Pr (\xi _{i} = -1) = q$$. Let us assume that within these n steps the particle moved m times to the right and, consequently, n − m times to the left. The actual position x n after n steps can then be determined from

(17.13)

where we used that x ₀ = 0. It is interesting to calculate the probability $$\Pr (x_{n} = k)$$ to find the particle after n time steps at some particular position k. This is simply the sum over all paths along which the particle moved $$m = (n + k)/2$$ times to the right and $$n - m = (n - k)/2$$ times to the left multiplied by the probability for m steps to the right and n − m steps to the left. In total, this yields $$\binom{n}{m} = \binom{n}{(n + k)/2}$$ different contributions and we have

(17.14)

In particular, we find for the unbiased random walk:

(17.15)

Due to the aperiodicity of the classical random walk, k can only take on the values $$k = -n,-n + 2,\ldots,n - 2,n$$. Consequently n ± k has to be even. For all other values of k we have $$\Pr (x_{n} = k) = 0$$. Furthermore,

(17.16)

and the probability of finding the particle at time n within [−n, n] is equal to one. A simple algorithm to simulate the one-dimensional biased random walk consists of the following steps:

1.

Define values x ₀, p, and $$q = 1 - p$$ .

2.

Draw a uniformly distributed random number r ∈ [0, 1] .

3.

If r < p set $$x_{n+1} = x_{n} + 1$$ , otherwise set $$x_{n+1} = x_{n} - 1$$ .

4.

Return to step 2.

In Fig. 17.1 we present three different realizations of an unbiased one-dimensional random walk for (a) N = 50, (b) N = 100, and (c) N = 1000 consecutive steps.

Fig. 17.1

Three different realizations of an unbiased one-dimensional random walk for (a) N = 50, (b) N = 100, and (c) N = 1000 time steps and different seeds

Comparison between Figs. 17.1 and 16.2 already suggests a connection between the random walk and the Wiener process and we shall come back to this point in the course of this chapter.

Moments

Let us briefly elaborate on the moments of the random walk (see Appendix, Sect. E.2). The first moment or expectation value $$\left \langle x_{n}\right \rangle$$ is given by

(17.17)

We now introduce a bias v such that

(17.18)

and obtain

(17.19)

We calculate the second moment $$\left \langle x_{n}^{2}\right \rangle$$ using the above method and get:

(17.20)

The variance $$\text{var}\left (x_{n}\right )$$ follows immediately:

(17.21)

We note the following: The expectation value $$\left \langle x_{n}\right \rangle$$ moves according to Eq. (17.19) with a uniform velocity defined by the bias $$v = p - q$$. In particular, for the unbiased random walk v = 0 and, thus, $$\left \langle x_{n}\right \rangle = 0$$ for all n. Furthermore, we observe that $$\text{var}\left (x_{n}\right )$$ increases linearly with time n – a property we already noted for the Wiener process in Sect. 16.​3 – and it is maximal for v = 0. For v = ±1, which describes a pure drift motion in the positive or negative x direction, the variance is equal to zero.

Recurrence

Let us briefly investigate the recurrence behavior of the random walk. We are interested in the probability $$f_{00}^{(2\ell)}$$ of a first return to the origin x ₀ = 0 after $$2\ell$$ steps. We already know that $$f_{00}^{(2\ell)} \propto p^{\ell}q^{\ell}$$ from our previous analysis. In the very first time step the particle moves either to x ₁ = 1 or to $$x_{1} = -1$$ and, consequently, within the following $$2\ell - 2$$ steps it must not cross or touch the line x k  = 0 and the particle has to terminate at position $$x_{2\ell-1} = x_{1}$$. Therefore, the walker performs $$\ell-1$$ steps to the left and $$\ell-1$$ steps to the right within these $$2\ell - 2$$ steps. The total number of possible paths N from x ₁ to $$x_{2\ell-1} = x_{1}$$ is, thus, given by

(17.22)

Moreover, N may also be written as the sum of N c paths which cross or touch the line x k  = 0 and N nc paths which do not cross or touch the line x k  = 0, i.e.

(17.23)

Obviously, we are only interested in the paths which do not cross or touch the line x k  = 0. We employ the reflection principle to solve this problem. In general, the number of paths which go from x ₁ = i > 0 to $$x_{k+1} = j &gt; 0$$ within

k-steps and cross the line x ℓ  = 0 is equal to the total number of paths which go from $$x_{1} = -i$$ to $$x_{k+1} = j$$, as is schematically illustrated in Fig. 17.2.

Fig. 17.2

Illustration of the reflection principle

Let us regard the case x ₁ = 1: The walker moved in the first step to the right. Hence, from the reflection principle we obtain that the number of paths from x ₁ to $$x_{2\ell-2} = x_{1}$$ in $$2\ell - 2$$ steps which cross or touch the line x k  = 0 is given by the total number of paths from − x ₁ to $$x_{2\ell-2} = x_{1}$$. Thus, N c is determined by:

(17.24)

We note that in this picture, the walker moves $$\ell$$ steps to the right and $$\ell-2$$ steps to the left. Hence, we obtain that the number of paths which do not cross or touch the line x k  = 0 is given by

(17.25)

The prefactor 2 accounts for the fact that the walker can move in its first step either to $$x_{1} = -1$$ or to x ₁ = 1. Thus, the probability for the first return of the particle after $$2\ell$$ steps is described by:

(17.26)

We calculate the recurrence probability according to Eq. (16.​66) and this results in

(17.27)

with the consequence that the one-dimensional random walk is only recurrent in the unbiased case v = 0.

Another possibility to demonstrate the recurrence of the unbiased one-dimensional random walk is provided by Eq. (16.​69). The probability that a walker returns to x ₀ = 0 after 2n steps is given by

(17.28)

In this case we are not interested in the question whether or not it is the particle’s first return. By Stirling’s approximation [Appendix, Eq. (E.20)]

(17.29)

and we obtain for P (2n)(x ₀):

(17.30)

We assume p ≤ 1∕2 and since $$pq = p(1 - p) \leq 1/4$$ one gets

(17.31)

The same argument holds for p > 1∕2 since we can write $$pq = (1 - q)q \leq 1/4$$. According to Eq. (16.​69) this means that the process is recurrent only for p = q, in accordance with our previous result (17.27), and transient otherwise. We note that this agrees also with the more physical picture of an external force inducing a bias or drift velocity v ≠ 0.

It should be noted that the unbiased random walk in two dimensions is also recurrent while it can be proved to be transient in higher dimensions. For instance, the recurrence probability is approximately 0. 34⁴ in 3D.

17.3 The Wiener Process and Brownian Motion

It is the purpose of this section to demonstrate that the Wiener process is the scaling limit of the random walk. Moreover, we discuss briefly the Langevin equation and derive the diffusion equation.

As a starting point we consider the one-dimensional unbiased random walk on an equally spaced grid according to Eq. (17.8) and time instances given by Eq. (17.7). We denote the stochastic process by X n  = X(t n ) and it is described by

(17.32)

where $$\xi \in \{-1,1\}$$ together with X ₀ = 0. Since we regard the unbiased case $$\Pr (\xi _{i} = \pm 1) = 1/2$$, $$\left \langle \xi _{i}\right \rangle = 0$$, and $$\text{var}\left (\xi _{i}\right ) = 1$$. This is equivalent to

(17.33)

as we already demonstrated in the previous section, Eq. (17.21). The variance $$\text{var}\left (X_{n}\right )$$ can be reformulated as

(17.34)

using the definition $$t_{n} \equiv n\varDelta t$$. The simultaneous limit $$\varDelta t,\varDelta x \rightarrow 0$$ is now performed in such a way that

(17.35)

with D the diffusion coefficient. This limit is known as the continuous limit and it will be denoted by the operator $$\mathcal{L}$$. Hence, in the continuous limit Eq. (17.34) results in

(17.36)

where we renamed t n  ≡ t. We also note that the limit Δ t → 0 for constant t is equivalent to $$n \rightarrow \infty $$ and we obtain in accordance with the central limit theorem (see Appendix, Sect. E.8):

(17.37)

Here $$\mathcal{N}(0,Dt)$$ denotes the normal distribution of mean zero and variance Dt, Appendix Eq. (E.43). Furthermore, the symbol W t was introduced to represent the Wiener process and the symbol ‘$$\sim $$’ stands, within this context, for the notion follows the distribution. If W t describes a Wiener process it is necessary to prove that W t has independent increments $$W_{t_{2}} - W_{t_{1}}$$ which follow, according to Sect. 16.​3, a normal distribution with mean zero and a variance proportional to t ₂ − t ₁. This is demonstrated quite easily: We learn from our discussion of the random walk that

(17.38)

and, therefore, X n − X m and X m − X k are clearly independent for n > m > k and it follows that also W t − W s and W s − W u are independent. Furthermore, we have

(17.39)

where the symbol ‘$$\stackrel{d}{=}$$’ stands for the notion to follow the same distribution or to be distributionally equivalent. Therefore, in the limit $$\mathcal{L}$$ for t > s

(17.40)

which completes the proof. We note that the particular case D = 1 is commonly referred to as the standard Wiener process. We remark that in many cases the terms Wiener process and Brownian motion are used as synonyms for a stochastic process satisfying the above properties. However, strictly speaking, the stochastic process is the Wiener process while Brownian motion is the physical phenomenon which can be described by the Wiener process.

If we suppose that p ≠ q then

(17.41)

with the drift constant ν, describes a Wiener process with a drift term

(17.42)

This process behaves like W t with the only difference that it fluctuates around mean ν t instead of mean zero. Note that for ν > 0 the mean $$\left \langle \tilde{W}_{t}\right \rangle$$ increases, while for ν < 0 it decreases with time t.

Another interesting property of the Wiener process is its self-similarity. In particular, we have the property that for α > 0

(17.43)

with the consequence that it is completely sufficient to study the properties of the Wiener process for t ∈ [0, 1] to know its properties for arbitrary time intervals. Relation (17.43) follows from the fact that $$W_{t} \sim \mathcal{N}(0,Dt)$$.

Furthermore, white noise, η(t), is defined as the formal derivative of the Wiener process W t with respect to time. We give its most important properties without going into details⁵:

(17.44)

White noise is referred to as Gaussian white noise if η(t) follows a normal distribution.

Figure 17.3 presents three different realizations of the

Fig. 17.3

Three different realizations of the standard Wiener process with drift ν = 1 according to Eq. (17.42). The expectation value $$\left \langle x\right \rangle =\nu t$$ of the process is presented as a dashed line

standard Wiener process with drift according to Eq. (17.42). The curves in this figure were generated using the procedure outlined in Sect. 16.​3 in connection with Fig. 16.​2

Let us derive the diffusion equation from the random walk model. The probability $$\Pr (x,t)$$ of finding the particle at time t at position x is expressed by

(17.45)

where we made use of relation (17.11). The interpretation of this equation is straight-forward: The probability to find the particle at the position-time point (x, t) is the sum of three terms. The first term describes the probability that the particle arrived already at position x in the previous time step $$t -\varDelta t$$ and that it will stay there during the next time step. The remaining two terms describe the probability that the particle arrived at position $$x -\varDelta x$$ ($$x +\varDelta x$$) in the previous time step and that it will move one step to the right (left) in the next time step. Each particular term is now expanded into a Taylor series up to order $$\mathcal{O}(\varDelta x^{2})$$ and $$\mathcal{O}(\varDelta t)$$, respectively. This requires the transition from a discrete to a continuous state space and, consequently, the probabilities Pr(⋅ ) are replaced by pdfs p(⋅ ). We get

(17.46)

and furthermore:

(17.47)

We draw the continuous limit and define the drift constant

(17.48)

the diffusion constant

(17.49)

and arrive at the one-dimensional diffusion equation with drift term:

(17.50)

This equation is referred to as a Fokker-Planck equation [17]. In the specific case p = q the drift term disappears and we obtain, as expected, the classical diffusion equation

(17.51)

which we solved already numerically in Chaps. 9 and 11. It follows from this discussion that the position of a diffusing particle can be described as a stochastic process where, in the continuous limit, the jump-lengths follow a normal distribution. In addition, we know from our discussion of continuous-time Markov-chains in Sect. 16.​5, that the waiting times between two successive jumps will certainly follow an exponential distribution. These insights will serve as a starting point in the discussion of general diffusion models in Sect. 17.4. Moreover, we note that the anisotropy of the jump-length distribution is a model for the presence of an external field which manifests itself in a drift term.

An alternative approach to the formal description of Brownian motion goes back to Langevin. He considered the classical equation of motion of a particle in a fluid which reads

(17.52)

where β denotes the friction coefficient and we set the particle’s mass m equal to one. Langevin argued that this equation may only be valid for the average motion of the particle which corresponds to the long time behavior of the motion of massive particles. However, if the particle is not heavy at all its trajectory can be highly affected by collisions with solvent’s molecules. He supposed that a reasonable generalization of Eq. (17.52) should be of the form [18]

(17.53)

where F(t) is a random force. In particular, F(t) is a stochastic process which satisfies

(17.54)

where A is a constant and we obtain

(17.55)

Equation (17.53) is referred to as the Langevin equation and it is the prototype stochastic differential equation. Based on the definition of white noise η(t) the Langevin equation can be rewritten:

(17.56)

The solution of the Langevin equation describes a stochastic process referred to as the Ornstein-Uhlenbeck process [19]. This process is essentially the only stochastic process which is stationary, Gaussian and Markovian. Its master equation is a Fokker-Planck equation of the form [17]

(17.57)

where p(v, t) is the pdf of the Ornstein-Uhlenbeck process. If the initial velocity v ₀ is given then the pdf p(v, t) can be proved to be

(17.58)

It is possible to solve the Langevin equation (17.53) analytically with the result:

(17.59)

We write in particular

(17.60)

with Z n defined as:

(17.61)

Since η(t) was assumed to be Gaussian white noise, Z n can be proved to be described by

(17.62)

which offers a very convenient way to simulate the Ornstein-Uhlenbeck process. This particular formulation of Brownian motion allows to model this process by sampling changes in the velocity Z n from the normal distribution with mean zero and the variance given in Eq. (17.62). The walker’s position x(t) can then be obtained by approximating the velocity $$v =\dot{ x}$$ with the help of finite difference derivatives, as described in Chap. 2 In conclusion we remark that although the Langevin equation was introduced in a heuristic manner, it represents a very useful tool due to its rather simple interpretation.

Figure 17.4 presents three different realizations of the Ornstein-Uhlenbeck process based on three different initial velocities v ₀.

Fig. 17.4

Three different realizations of the Ornstein-Uhlenbeck process v(t) vs t. For this simulation we chose β = 1, A = 5, $$\mathrm{d}t = 10^{-2}$$ and N = 10³ time steps. Furthermore, we chose three different initial velocities, i.e. v ₀ = 0 (black), v ₀ = 5 (gray) and v ₀ = 10 (light gray)

The corresponding random trajectories x(t) of the Brownian particle are illustrated in Fig. 17.5.

Fig. 17.5

Random trajectories x(t) vs t of the Brownian particle which correspond to the velocities v(t) illustrated in Fig. 17.4 with initial position x ₀ = 0. Note that we used for this figure N = 10⁵ time steps

17.4 Generalized Diffusion Models

We formulate now a very general approach to diffusive behavior which is based on continuous random variables. We start with the introduction of the pdf $$\varLambda (x,t)$$. Its purpose is to describe the event that a particle arrives at time t at position x. It can be expressed as [20, 21]

(17.63)

where $$\psi (x,t;x',t')$$ is the jump pdf. We offer the following interpretation: $$\psi (x,t;x',t')$$ describes the probability for an event that a particle which arrived at time t′ at position x′ – with pdf $$\varLambda (x',t')$$ – waited at position x′ until the time t was reached and then jumped within an infinitesimal time interval from position x′ to x. If we regard a space and time homogeneous process then $$\psi (x,t;x',t')$$ is replaced by $$\psi (x - x',t - t')$$. This allows the introduction of a jump length pdf p(x) and of a waiting time pdf q(t). They are related to the jump pdf by

(17.64)

If the jump length pdf and the waiting time pdf are conditionally independent one can simply write $$\psi (x,t) = p(x)q(t)$$. The probability $$\varphi (x,t)$$ of finding a particle at position x at time t is, furthermore, given by

(17.65)

where Ψ(t) is the probability, that a particle stayed at least for a time interval t at the same position, i.e.

(17.66)

Finally, the jump length variance $$\sigma ^{2}$$ and the characteristic waiting time τ are given by

(17.67)

We conclude from our discussion of the Wiener process that for Brownian motion the jump length pdf is a Gaussian and the waiting time pdf is an exponential distribution:

(17.68)

The characteristic function [Appendix Eq. (E.54)] of the waiting time pdf q(t) is given by

(17.69)

and we find for the jump length pdf p(x):

(17.70)

For $$x,t \rightarrow \infty $$, i.e. k, s → 0, the characteristic functions $$\hat{q}(s)$$ and $$\hat{p}(k)$$ develop the asymptotic behavior

(17.71)

and

(17.72)

In fact, it can be shown that any pair of jump length and waiting time pdfs lead in first order to the same asymptotic behavior, namely $$\mathcal{O}(\tau )$$ and $$\mathcal{O}(\sigma ^{2})$$, as long as the moments τ and $$\sigma ^{2}$$ exist.

However, there is a variety of processes which cannot be accounted for within the basic framework of Brownian motion. Such processes are described within the concept of anomalous diffusion [9, 20]. Examples are, for instance, the foraging behavior of spider monkeys, particle trajectories in a rotating flow, diffusion of proteins across cell membranes, diffusion of tracers in polymer-like breakable micelles, the traveling behavior of humans, charge carrier transport in disordered organic molecules, etc.

We concentrate now on two particular models of anomalous diffusion. The first model can, from a qualitative point of view, be characterized as a diffusion process which consists of small clustering jumps which are intersected by very long flights. Such behavior is, for instance, encountered in the context of human travel behavior, Fig. 17.6 [22], charge carrier transport in disordered solids, etc. The incorporation of these long jumps on a stochastic level is referred to as Lévy flight [10]. The second model, which is referred to as the fractal time random walk incorporates anomalously long waiting times between two successive jumps. In particular, these long waiting times account for non-Markovian effects which could be due to, for instance, trapping processes of charge carriers in disordered solids. It has to be emphasized at this point that the resulting diffusion models are still linear in the pdf $$\varphi (x,t)$$. The inclusion of non-linear effects will not be discussed here, however, can be achieved within the framework of non-extensive thermodynamics [23].

Fig. 17.6

Traveling behavior of humans (Adapted from [22]. Copyright © 2006, Rights Managed by Nature Publishing Group)

Let us start with Lévy flights. In this case one modifies the asymptotic behavior of the characteristic function of the jump length pdf according to

(17.73)

where α ∈ (0, 2]. We recognize that this is the asymptotic behavior $$\vert k\vert \rightarrow 0$$ of the characteristic function of a symmetric Lévy α-stable distribution [19] following Appendix Eq. (E.69). In the limit α → 2 normal, Gaussian behavior is recovered. According to Appendix Eq. (E.70) the characteristic function (17.73) corresponds to a jump length pdf:

(17.74)

It is commonly referred to as a fat-tailed jump length pdf because of its asymptotic behavior.

A Lévy flight is, in principle, a random walk where the length of the jumps at discrete time instances t n follow the pdf (17.74). In the continuous time limit, the waiting times are distributed exponentially as was illustrated in Sect. 16.​5. It has to be noted that in such a case the jump length variance diverges, i.e. $$\varSigma ^{2} \rightarrow \infty $$. Consequently, Lévy α-stable distributions are not subject to the central limit theorem (see Appendix, Sect. E.8). In particular, the distance from the origin after some finite time t follows a Lévy α-stable distribution. Moreover, we note that if 0 < α < 1 even the mean jump length $$\left \langle x\right \rangle$$ diverges. A detailed mathematical analysis proves, that Lévy flights result in a diffusion equation of the form

(17.75)

where D α is the fractional diffusion coefficient of dimension length α × time⁻¹ and $$\mathcal{D}_{\vert x\vert }^{\alpha }$$ is the symmetric Riesz fractional derivative operator of order α ∈ (1, 2)⁶:

(17.76)

where f″(x) is the second spatial derivative of f.

Figure 17.7 illustrates a one-dimensional Lévy flight and Fig. 17.8 presents a comparison between a two-dimensional Lévy

Fig. 17.7

Three different realizations of the one dimensional Lévy flight. The parameters are $$\ell= 0.001$$, α = 1. 3 and we performed N = 1000 time steps

Fig. 17.8

Comparison between the two-dimensional Wiener process (solid up-triangles) and the two-dimensional Lévy flight (open squares) for α = 1. 3. The minimal flight length of the Lévy flight as well as the jump length variance of the Wiener process were set $$\ell=\varSigma ^{2} = 0.1$$ and we performed N = 100 time steps

flight and a two-dimensional Wiener process. These figures were generated by sampling an exponential distribution with mean $$\left \langle t\right \rangle = 1$$ for the waiting times. On the other hand a jump length pdf

(17.77)

was sampled for the jump length of the Lévy flight. Here α is referred to as the Lévy index, $$\varTheta (\cdot )$$ denotes the Heaviside $$\varTheta$$ function and ℓ > 0 is the minimal flight length. We introduced this particular form of the pdf because it can rather easily be sampled with the help of the inverse transformation method – Sect. 13.​2 – and it obeys the asymptotic behavior, Eq. (17.74). Moreover, it can be proved that it gives the correct behavior in the limit $$\ell\rightarrow 0$$. Finally, the direction of the jump has to be sampled in an additional step. Figure 17.8 is particularly instructive because the different physics described by these two models becomes immediately apparent.

Let us turn our attention to the second scenario, the fractal time random walk. In this case the asymptotic behavior of the waiting time pdf is modified according to

(17.78)

where $$\beta \in (0,1]$$ and for β → 1 regular behavior, an exponentially distributed waiting time, is recovered. A pdf of such a form is commonly referred to as a fat-tailed waiting time pdf. After an inverse Laplace transform we obtain

(17.79)

We note that in this case the mean waiting time $$T = \left \langle t\right \rangle$$ diverges for β < 1. This clearly indicates a non-Markovian time evolution since we demonstrated in Sect. 16.​5 that every Markovian discrete time process converges in the continuous time limit to a process with exponentially distributed waiting times. Again, the ansatz

(17.80)

is employed, where τ > 0 is the minimal waiting time. The process is essentially a random walk with waiting times distributed according to Eq. (17.80), i.e. the jump length $$\varDelta x$$ is constant. In the continuous space limit $$\varDelta x \rightarrow 0$$ the jump lengths follow a Gaussian, as in the case of a regular random walk. A detailed analysis proves that in the limit τ → 0 the corresponding diffusion equation is given by

(17.81)

where the diffusion constant D β is of dimension length²× time−β . Here, $$^{C}D_{t}^{\beta }$$ is the Caputo fractional time derivative of order β ∈ (0, 1) (see Appendix G). It is of the form

(17.82)

It follows from the properties of fractional derivatives that an alternative form of Eq. (17.81) can be found, namely

(17.83)

where D t β is the Riemann-Liouville fractional derivative of order β (see Appendix G).

Figure 17.9 presents three different realizations of the fractal time random walk. The waiting times were sampled from the pdf (17.80) with the help of

Fig. 17.9

Three different realizations of the fractal time random walk in one dimension for β = 0. 8 and τ = 0. 1

the inverse transformation method – Sect. 13.​2 – and the jump lengths were sampled from a normal distribution with jump length variance $$\varSigma ^{2} = 1$$.

It is a straight-forward task to combine fractal time random walks and Lévy flights to so called fractal time Lévy flights. The resulting diffusion equation can be written as

(17.84)

where the diffusion constant $$D_{\alpha \beta }$$ has units length α × time−β and $$^{C}D_{t}^{\beta }$$ and $$\mathcal{D}_{\vert x\vert }^{\alpha }$$ are the fractional Caputo and Riesz derivatives, respectively.

Figure 17.10 illustrates three different realizations of such a diffusion process. The waiting times were sampled from the pdf (17.80) where we set

Fig. 17.10

Three possible realizations of the fractal time Lévy flight in one dimension. The parameters are τ = 0. 1, β = 0. 8, $$\ell= 0.01$$ and α = 1. 3

τ = 0. 1 and β = 0. 8. The jump lengths were sampled from the pdf (17.77) with α = 1. 3 and $$\ell= 0.01$$. Finally, the direction of the jump was sampled in an additional step.

We close this chapter with a short discussion: The description of diffusion processes with the help of stochastics proofed to be one of the most powerful methods in modern theoretical physics. Within this chapter we discussed several different paths toward a description of Brownian motion, namely the random walk, the Wiener process, and the Langevin equation, as well as models which describe phenomena beyond Brownian motion. It has to be emphasized that the field of anomalous diffusion in general is still developing rapidly, however, its importance for the description of various phenomena in science is already impressive. We refer the interested reader to the excellent review articles by R. Metzler and J. Klafter on anomalous diffusion [20, 21].

Summary

The random walk, a classical example of Markov-chains, was used to open the door to the realm of diffusion theory. Random walks have been used for a long time to simulate Brownian motion and related problems. From a theoretical point of view random walks were described by the scaling limit of the Wiener process. The biased Wiener process was then used to demonstrate that the Fokker-Planck equation followed in the limit of a continuous state space, as the classical diffusion equation followed from the unbiased Wiener process in the same limit. Brownian motion was also the basis for the rather heuristic introduction of the stochastic differential equation by Langevin. A direct consequence of this equation was the Ornstein-Uhlenbeck process with its master equation, the Fokker-Planck equation. It was the only stationary, Gaussian, and Markovian process in this class of stochastic diffusion processes. An extension of these processes was then possible by the introduction of a jump pdf which in turn allowed to define a jump length pdf and a waiting time pdf. These two pdfs resulted in a more general description of diffusion processes in a space and time homogeneous environment. Furthermore, the observation that many diffusive processes (not only in physics) cannot be understood within the framework of ‘classical’ Brownian motion resulted in the introduction of Lévy flights. This was particularly motivated by the need for a process whose jump-length variance diverges which enabled, for instance the simulation of human travel behavior. In the very last step the fractal time random walk was introduced. It was characterized by a specific form of the waiting time pdf which made it possible to describe on a stochastic level anomalously long waiting times between two consecutive jumps. Such behavior can, for instance, be observed by trapping phenomena in solids. The combination of both extensions resulted in the fractal time Lévy flight.

Problems

1.

Write a program which simulates different realizations of the following stochastic processes in one spatial dimension:

a.

A random walk.

b.

A standard Wiener process and a Wiener process with drift.

c.

An Ohrnstein-Uhlenbeck process.

d.

A Lévy flight.

e.

A fractal time random walk.

f.

A fractal time Lévy flight.

Illustrate three different sample paths graphically for each process. Furthermore, perform the following tests:

a.

Calculate the expectation value $$\left \langle x_{n}\right \rangle$$ and the variance $$\text{var}\left (x_{n}\right )$$ of the random walk numerically by restarting the process several times with different seeds.

b.

In a similar fashion, calculate numerically $$\left \langle W_{t}\right \rangle$$ and $$\text{var}\left (W_{t}\right )$$.

c.

Try different parameters α, β for Lévy flights and fractal time random walks.

2.

Write a program which simulates the Wiener process in two dimensions. This can be achieved by drawing the jump length from a normal distribution and sampling the jump angle, i.e. the direction, in an additional step. Augment this program with Lévy flight jump lengths pdfs.

References

1.

Glicksman, M.E.: Diffusion in Solids. Wiley, New York (1999)MATH

2.

Cussler, E.L.: Diffusion. Cambridge University Press, Cambridge (2009)Crossref

3.

Dubitzky, W., Wolkenhauer, O., Cho, K.H., Yokota, H. (eds.): Encyclopedia of Systems Biology, p. 1596. Springer, Berlin/Heidelberg (2013)

4.

Tapiero, C.S.: Risk and Financial Management: Mathematical and Computational Methods. Wiley, New York (2004)CrossrefMATH

5.

Harris, S.: An Introduction to the Theory of the Boltzmann Equation. Dover, Mineola (2004)

6.

Ballentine, L.E.: Quantum Mechanics. World Scientific, Hackensack (1998)CrossrefMATH

7.

Rudnik, J., Gaspari, G.: Elements of the Random Walk. Cambridge University Press, Cambridge (2010)

8.

Ibe, O.C.: Elements of Random Walk and Diffusion Processes. Wiley, New York (2013)CrossrefMATH

9.

Pekalski, A., Sznajd-Weron, K. (eds.): Anomalous Diffusion. Lecture Notes in Physics. Springer, Berlin/Heidelberg (1999)MATH

10.

Shlesinger, M.F., Zaslavsky, G.M., Frisch, U. (eds.): Lévy Flights and Related Topics in Physics. Lecture Notes in Physics. Springer, Berlin/Heidelberg (1995)MATH

11.

Norris, J.R.: Markov Chains. Cambridge Series in Statistical and Probabilistic. Cambridge University Press, Cambridge (1998)MATH

12.

Modica, G., Poggiolini, L.: A First Course in Probability and Markov Chains. Wiley, New York (2012)CrossrefMATH

13.

Graham, C.: Markov Chains: Analytic and Monte Carlo Computations. Wiley, New York (2014)CrossrefMATH

14.

Pólya, G.: Über eine Aufgabe der Wahrscheinlichkeitsrechnung betreffend die Irrfahrt im Straßennetz. Math. Ann. 84, 149–160 (1921)MathSciNetCrossrefMATH

15.

Finch, S.R. (ed.): Mathematical Constants, pp. 322–331. Cambridge University Press, Cambridge (2003)

16.

Weisstein, E.W.: Pólya’s random walk constants. http://​mathworld.​wolfram.​com/​PolyasRandomWalk​Constants.​html

17.

Risken, H., Frank, T.: The Fokker-Planck Equation. Springer Series in Synergetics. Springer, Berlin/Heidelberg (1996)CrossrefMATH

18.

Coffey, W.T., Kalmykov, Y.P.: The Langevin Equation, 3rd edn. World Scientific Series in Contemporary Chemical Physics: Volume 27. World Scientific, Hackensack (2012)

19.

Breuer, H.P., Petruccione, F.: Open Quantum Systems, chap. 1 Clarendon Press, Oxford (2010)

20.

Metzler, R., Klafter, J.: The random walk’s guide to anomalous diffusion: a fractional dynamics approach. Phys. Rep. 339, 1–77 (2000)ADSMathSciNetCrossrefMATH

21.

Metzler, R., Klafter, J.: The restaurant at the end of random walk: recent developments in the description of anomalous transport by fractional dynamics. J. Phys. A 37, R161 (2004)ADSMathSciNetCrossrefMATH

22.

Brockmann, D., Hufnagl, L., Geisl, T.: The scaling laws of human travel. Nature (London) 439, 462–465 (2006). doi:10.1038/nature04292ADSCrossref

23.

Tsallis, C.: Introduction to Nonextensive Statistical Mechanics. Springer, Berlin/Heidelberg (2009)MATH

Footnotes

1

This assumption is known as the approximation of molecular chaos. In fact it represents the Markov approximation to the dynamics of a many particle system.

2

For instance, one can employ Fermi’s golden rule [6] to obtain this function on a quantum mechanical level. We already came across an expression of the form (17.3) on the right hand side of the master equation, see Sect. 16.​3, Eq. (16.​42). However, the collision integral of the Boltzmann equation is non-linear.

3

The function ρ(r, t) is referred to as a physical distribution function due to the normalization condition (17.6). This is in contrast to distribution functions we encountered so far within this book, which are normalized to unity.

4

This is one of Pólya’s random walk constants [14–16].

5

In fact, it can be shown that W t is non-differentiable with probability one. This is the reason why it is defined as the formal derivative of W t . Let $$\varphi (t)$$ be a test function and f(t) an arbitrary function which does not need to be differentiable with respect to t. Then the formal derivative $$\dot{f}(t)$$ is defined by

6

A short introduction to fractional derivatives and integrals can be found in Appendix G.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_18

18.  Markov-Chain Monte Carlo and the Potts Model

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

18.1 Introduction

This chapter discusses in more detail the concept of Markov-chain Monte Carlo techniques [1–4]. We already came across the Metropolis algorithm in Sect. 14.​3, where the condition of detailed balance proved to be the crucial point of the method. The reason for imposing such a condition was explained in all required detail during our discussion of Markov-chains within Sect. 16.​4 The Ising model, analyzed in Chap. 15, served as a first illustration of the applicability of Markov-chain Monte Carlo methods in physics.

Let us briefly summarize what we learned so far: We discussed several methods to sample pseudo random numbers from a given distribution in Chap. 13 The two most important methods, the inverse transformation method and the rejection method, were based on an exact knowledge of the analytic form of the distribution function which the random numbers were supposed to follow. However, when simulating the physics of the Ising model it was required to draw random configurations from the equilibrium distribution of the system and, unfortunately, the exact analytic form of this distribution was unknown. On the other hand, in the discussion of Markov-chains we came across the condition of detailed balance. Invoking this condition ensured that the constructed Markov-chain converged toward a stationary distribution, independent of the initial conditions. Consequently, we can also sample random numbers by constructing a Markov-chain with a stationary distribution which is equal to the distribution from which we would like to obtain our random numbers. In such a case the distribution function has to be known, at least in principle. However, the formulation of the Metropolis algorithm allowed for an unknown normalization constant of the distribution function which, in turn, makes this method such a powerful tool in computational physics.

Here we plan to discuss Markov-chain Monte Carlo techniques in greater detail. We start with the introduction of the concept of importance sampling, review the Metropolis algorithm, and discuss the straight forward generalization to the Metropolis-Hastings algorithm. Finally, the applicability of the Metropolis-Hastings algorithm will be demonstrated by simulating the physics of the q-states Potts model [5] which is closely related to the Ising model. This chapter is closed with a brief presentation of some of the more advanced techniques within this context.

18.2 Markov-Chain Monte Carlo Methods

Before turning our focus toward the Markov-chain Monte Carlo methods we shall briefly discuss importance sampling. Let p(x) be a certain pdf from which we would like to draw a sequence of random numbers {x i }, i ≥ 1. Furthermore, let f(x) be some arbitrary function and we would like to estimate its expectation value $$\left \langle \,f\right \rangle _{p}$$ which is determined by the integral

(18.1)

But $$\left \langle \,f\right \rangle _{p}$$ can also be regarded as the expectation value $$\left \langle a\right \rangle _{u}$$ of the function a(x): = f(x)p(x), with u(x) the pdf of the uniform distribution. Hence, we may evaluate $$\left \langle a\right \rangle _{u}$$ by drawing uniformly distributed random numbers on a given interval $$[a,b] \subset \mathbb{R}$$ and by estimating the expectation value by its arithmetic mean as discussed in Sect. 14.​2 This approach is the easiest version of a method referred to as simple sampling. On the other hand, we might approximate $$\left \langle \,f\right \rangle _{p}$$ by sampling x i according to p(x) and by employing the central limit theorem (see Appendix, Sect. E.8) as was demonstrated in Sect. 14.​2 The basic idea of importance sampling, however, is to improve this approach by sampling from a different distribution q(x) which is in most cases chosen in such a way that the expectation value $$\left \langle \,f\right \rangle _{p}$$ is easier to evaluate.

Let g(x) be some function with g(x) > 0 for all x. Then

(18.2)

where we defined the function $$q(x) = p(x)g(x)/c$$ and c is chosen in such a way that $$\int \mathrm{d}xq(x) = 1$$. We note that g(x) can be any positive function. Hence, such an approach might be interesting in two different scenarios: (i) if it is easier to sample from the distribution q(x) rather than from p(x) and, (ii) if such a sampling results in a variance reduction which is equivalent to a decrease in error, and less random numbers are to be sampled to obtain comparable results.

Let us briefly elaborate on this point: we have

(18.3)

and for the particular choice g(x) ≡ f(x) we obtain that

(18.4)

and the error of our Monte Carlo integration vanishes. However, the ideal case of g(x) ≡ f(x) is unrealistic because we obtain for the normalization constant c

(18.5)

which is exactly the integral we want to evaluate. Nevertheless, the function g(x) can be adapted to improve the result. We choose g(x) in such a way that the integral $$\left \langle g\right \rangle _{p}$$ is easily evaluated and that g(x) follows f(x) as closely as possible; in other words, the quotient f(x)∕g(x) becomes as constant as possible. This means that we no longer sample from p(x) within a given interval but only from points which are of importance for the particular function f(x). Such an approach is referred to as importance sampling [6–9].

The attentive reader might have observed that, on a first glance, importance sampling has nothing to do with Markov-chain Monte Carlo methods in general. Nevertheless, it can be demonstrated that Markov-chain Monte Carlo methods correspond indeed to importance sampling.

To prove this, we remember that Markov-chain Monte Carlo techniques are based on the generation of a sequence of configurations S (n):

(18.6)

Each individual configuration S (n) is generated from the previous configuration S (n−1) at random with a certain transition probability P(S (n−1) → S (n)). These transition probabilities obey

(18.7)

and this property ensures that the sequence (18.6) is a Markov-chain. In Sect. 16.​4 we observed that the condition of detailed balance for a stationary distribution P(S)

(18.8)

guarantees convergence of the Markov-chain toward the stationary distribution. Hence, the remaining task is to find transition probabilities which fulfill detailed balance. In a typical situation, the transition probabilities can be written as

(18.9)

where P p (S → S′) is the probability that a configuration S′ is proposed and P a (S → S′) is the probability that the proposed configuration is accepted. In many cases one simplifies the situation by assuming that

(18.10)

and, thus, the condition of detailed balance changes into

(18.11)

The Metropolis algorithm uses one possible choice for the acceptance probability, namely

(18.12)

It was demonstrated in Sect. 14.​3 that Eq. (18.12) indeed fulfills Eq. (18.11). The execution of the algorithm has already been illustrated in Chap. 15 in its application to the numerics of the Ising model.

A rather straight forward generalization of the Metropolis algorithm (18.12) is found when an asymmetric proposal probability P p (S → S′) is considered. It is easily demonstrated that the choice

(18.13)

also fulfills detailed balance (18.8). The choice (18.13) is referred to as the Metropolis-Hastings algorithm [10]. ¹

By exploiting the Markov property in order to sample configurations according to the Boltzmann distribution we perform importance sampling as illustrated above. An alternative approach would be to select different configurations according to a uniform distribution which obviously increases the numerical cost of the method by magnitudes. Hence, sampling with the help of a Markov-chain yields a variance reduction in comparison to the crude approach of simple sampling. Furthermore, the algorithm can be optimized by a clever choice of P p (S → S′) which does not need to be symmetric. Clearly, this choice will have to depend on the particular problem at hand.

We shall briefly discuss two alternative approaches to Markov-chain Monte Carlo sampling, namely Gibbs sampling [11] and slice sampling [12]: Suppose we want to sample a sequence of m-dimensional variables $$x^{(n)} = (x_{1}^{(n)},x_{2}^{(n)},\ldots,x_{m}^{(n)})^{T}$$ from a multivariate distribution function p(x) = p(x ₁, x ₂, …, x m ). In such a case Gibbs sampling is particularly interesting if the joint distribution function is well-known and simple to sample. The acceptance probability for a particular component of the vector x (n) is set to:

(18.14)

This is possible as we have

(18.15)

because the denominator of the left hand side of Eq. (18.15) is independent of x j . It can, therefore, be treated as a normalization constant when x j is sampled.

Let us briefly discuss slice sampling: For reasons of simplicity we shall regard the uni-variate case where p(x) denotes the pdf from which we would like to sample. We apply the following algorithm:

1.

Choose some initial value x ₀.

2.

Sample a uniformly distributed random variable y ₀ from the interval [0, p(x ₀)].

3.

Sample the next random variable x ₁ uniformly from the slice $$\mathcal{S}[p^{-1}(y_{0})]$$.

4.

Sample a uniformly distributed random number y ₁ ∈ [0, p(x ₁)].

5.

Sample the next random variable x ₂ uniformly from the slice $$\mathcal{S}[p^{-1}(y_{1})]$$.

6.

…$$\vdots$$

The final sequence {x j } is constructed by ignoring the y n -values (even steps). This procedure is illustrated schematically in Fig. 18.1.

Fig. 18.1

Schematic illustration of slice sampling for the uni-variate case described by the pdf p(x). The relevant steps of the algorithm are indicated by solid asterisks

18.3 The Potts Model

We studied in Chap. 15 the two-dimensional Ising model as an example for the Metropolis algorithm. Here we expand on this discussion and investigate the q-states Potts model [5] which can be regarded as a generalization of the Ising model. The model is characterized by the Hamilton function

(18.16)

where the notation used for the Ising model applies. In particular, we shall regard the case J ij  = J for i, j nearest neighbors and J ij  = 0 otherwise. In contrast to the Ising model, the spin realizations $$\sigma _{i}$$ on grid-point i can take integer values $$\sigma _{i} = 1,2,\ldots,q$$. For q = 2, the Potts model is equivalent to the Ising model which can be easily proved by rewriting the Hamilton function as

(18.17)

Here $$\langle ij\rangle$$ denotes sum over nearest neighbors. We observe that $$2\left (\frac{1} {2} -\delta _{\sigma _{i}\sigma _{j}}\right )$$ is equal to − 1 for $$\sigma _{i} =\sigma _{j}$$ and + 1 for $$\sigma _{i}\neq \sigma _{j}$$. Moreover, the constant energy shift in Eq. (18.17) can be neglected and we recover the Ising model of Chap. 15.

The method to calculate the observables of interest, like $$\left \langle E\right \rangle$$, $$\left \langle M\right \rangle$$, c h and χ, and the basic algorithm can be adopted from Sect. 15.​2 as is.² There is one important difference. It occurs in step 3 of the algorithm: Instead of setting $$\sigma _{ij} = -\sigma _{ij}$$ we sample the new value of $$\sigma _{ij}$$ uniformly distributed from 1, 2, …, q under exclusion of the old value of $$\sigma _{ij}$$.

Figures 18.2, 18.3, 18.4, and 18.5 display the mean energy per particle, the mean magnetization per particle $$\langle m_{1}\rangle$$ [with Q = 1 in Eq. (18.18)],

Fig. 18.2

The mean free energy per particle $$\langle \varepsilon \rangle$$ vs temperature k B T for a q-states Potts model on a 40 × 40 square lattice, with q = 1, 2, …, 8 and J = 0. 5. 10⁴ measurements have been performed

Fig. 18.3

The mean magnetization per particle $$\langle m_{1}\rangle$$ vs temperature k B T for a q-states Potts model on a 40 × 40 square lattice, for q = 1, 2, …, 8 and J = 0. 5. 10⁴ measurements have been performed

Fig. 18.4

The heat capacity c h vs temperature k B T for a q-states Potts model on a 40 × 40 square lattice, with q = 1, 2, …, 8 and J = 0. 5. 10⁴ measurements have been performed. The inset shows the specific heat c h on a logarithmic scale in the region around the transition temperature

Fig. 18.5

The magnetic susceptibility χ vs temperature k B T for a q-states Potts model on a 40 × 40 square grid, with q = 1, 2, …, 8 and J = 0. 5. 10⁴ measurements have been performed. The inset shows the magnetic susceptibility χ on a logarithmic scale in the region around the transition temperature

the heat capacity c h as well as the magnetic susceptibility χ for q = 1, 2, …, 8 and J = 0. 5 [Eq. (18.16)] vs temperature k B T. The size of the system was N × N with N = 40. We performed 10⁴ measurements per temperature and 10 sweeps where discarded between two successive measurements in order to reduce correlations. The equilibration time

was set to 10³ sweeps. A typical spin configuration for q = 4 and k B T = 0. 47 can be found in Fig. 18.6.

Fig. 18.6

A typical spin configuration $$\sigma _{i,j}$$ for a q-states Potts model on a 40 × 40 square lattice with q = 4, J = 0. 5, and k B T = 0. 47

A number of interesting details can be observed in Fig. 18.3. First of all, we recognize that the mean magnetization $$\langle m_{1}\rangle$$ above the critical temperature decreases with increasing values of q. The reason is that the mean magnetization $$\langle m_{1}\rangle$$ represents for T ≫ T c the probability of finding a particular spin in state $$\sigma _{i} = 1$$. This is equivalent to 1∕q for a uniform distribution and therefore decreases with increasing q. Please note that the expectation value of the magnetization $$\langle m_{Q}\rangle$$ is restricted to take the values from {0, 1} for T ≪ T C due to the modified definition of $$\mathcal{M}_{Q}(\mathcal{C})$$. This is in contrast to the Ising model where $$\langle m\rangle \in \{-1,1\}$$ for T < T c . Hence, we obtain for T ≪ T C $$\langle m_{1}\rangle = 0$$ with probability $$(q - 1)/q$$ and $$\langle m_{1}\rangle = 1$$ with probability 1∕q. However, the particular definition (18.18) of $$\mathcal{M}_{Q}(\mathcal{C})$$ is not important since the physically relevant property of the Potts model Hamilton function (18.16) is its $$\mathbb{Z}_{q}$$ symmetry with a degenerate ground state.

A second interesting feature is the observation that the critical temperature T c also decreases with increasing values of q which becomes particularly transparent from Figs. 18.4 and 18.5. The critical temperatures are quoted in Table 18.1. Finally, we deduce from Fig. 18.2 that the phase

Table 18.1

List of the critical values $$\alpha _{c} = J/(k_{\mathrm{B}}T_{c})$$ of the q-states Potts model for q = 2, 3, …, 8

q

α c

2

0.89

3

1.00

4

1.09

5

1.16

6

1.22

7

1.28

8

1.35

transition is smoother for q = 2 and becomes discontinuous for large values of q. In particular, the q-states Potts model exhibits a second order phase transition for q = 2, 3, 4 and a first order phase transition for q > 4 which is hard to see from Figs. 18.2 and 18.3. However, there is another method to unambiguously identify a first order phase transition.

It is referred to as the histogram technique. The mean energies of consecutive measurements near the critical temperature are simply collected in a histogram. If only one peak is observed, the system fluctuates around a single phase, and a second order phase transition was observed. However, the existence of two or more peaks means that the system fluctuates between two or more different phases and, therefore, exhibits a first order phase transition. Figure 18.7 displays two histograms for q = 2 (k B T = 0. 56) and q = 8 (k B T = 0. 37) from 10⁴ measurements to prove our case.

Fig. 18.7

(a) Histogram of 10⁴ measurements of the absolute value of the mean free energy per particle $$\vert \langle \varepsilon \rangle \vert$$ for a q-states Potts model on a 40 × 40 square lattice at temperature k B T = 0. 56 with q = 2. We observe one single peak which indicates that the system exhibits a second order phase transition. (b) The same as (a) but for q = 8 and temperature k B T = 0. 37. We observe two well separated peaks, thus the system exhibits a first order phase transition

One possible realization of the q = 3 states Potts model was discussed by M. Kardar and A.N. Berker [13]. They studied the over saturated adsorption of Krypton atoms on a graphite surface. A detailed analysis of this system revealed that three energetically degenerate sublattices are formed. Furthermore, the authors demonstrated that the thermodynamic properties of this system can be explained by a q = 3 states Potts model. For a more detailed discussion we refer to the original paper. More applications of the Potts model were discussed in the review by F.Y. Wu [14].

The attentive reader may have noticed that our results do not carry error-bars. We neglected error-bars for a clearer illustration. A short discussion of methods used to calculate numerical errors was presented in Sect. 15.​2 for the Ising model and they can easily be adapted for the Potts model. More advanced techniques will be introduced in the next chapter.

18.4 Advanced Algorithms for the Potts Model

We discuss briefly some advanced techniques for the Potts model. Although these algorithms are applicable for arbitrary q we restrict our discussion to the case q = 2, the Ising model, for reasons of simplicity. Let us briefly motivate the need for more advanced methods: For large values of N we observe the formation of spin domains³ for temperatures T ≈ T c . In such a case the specific Metropolis algorithm used so far is disadvantageous because single spin flips will only affect the boundaries of these domains (critical slowing down). It is therefore necessary to perform many sweeps in order to produce configurations which are entirely different. It might therefore be a better approach to flip a whole spin cluster at once. Such algorithms are referred to as cluster algorithms. The main problem is the identification of clusters as well as the assignment of a probability to the flip of a particular cluster.

As a first example we shall discuss the Swendsen-Wang algorithm [16]. The algorithm is executed in the following steps:

1.

Identify all links between two neighboring identical spins.

2.

Define a bond between two linked spins with probability

(18.19)

with $$\beta = 1/(k_{\mathrm{B}}T)$$.

3.

Identify all clusters which are built from spins connected by bonds, see Fig. 18.8.

Fig. 18.8

Schematic illustration of the identification of clusters according to the Swendsen-Wang algorithm. 1 and 2 denote two different spin orientations, bonds are denoted by solid lines and all bonded spins form clusters

4.

Flip every cluster with probability 1∕2.

5.

Delete the bonds and restart the iteration for the next spin configuration.

We note the following properties of the Swendsen-Wang algorithm:

The algorithm is ergodic because every spin forms a cluster on its own with a non-vanishing probability according to Eq. (18.19).

The algorithm fulfills detailed balance for the Boltzmann distribution and thus reproduces the correct stationary distribution.

Since the algorithm breaks domain walls or flips whole clusters, this algorithm can be regarded to be very efficient from a numerical point of view. However, it outperforms the single spin Metropolis algorithm only for temperatures near the critical temperature because only then spin domains dominate the observables.

A simpler version of this algorithm consists of the following four steps:

1.

Randomly pick a lattice site.

2.

Find all neighbors with the same spin and form bonds with probability (18.19).

3.

Move to the boundary of the cluster and repeat step 2, i.e. the cluster grows.

4.

If no new bond is formed, flip the cluster with probability 1.

In this simplified version the identification of clusters is not necessary because each cluster is built dynamically during the simulation. Such a formulation of a cluster algorithm is the Wolff algorithm [17] which is essentially a generalization of the work of Swendsen and Wang [16]. But why is it allowed to accept every step, i.e. flip every formed cluster, without contradicting the condition of detailed balance? The explanation is found in the definition of the probability of bond-formation, Eq. (18.19). An even more effective extension of the Wolff algorithm to quantum systems is the loop algorithm [18]. For a more detailed discussion of all these methods we refer the interested reader to the literature [19] and to the particular papers cited here.

Before proceeding to the next chapter, let us briefly mention that there is also an entirely different approach to improve the Metropolis algorithm for quantum systems, the so called worm algorithms [18]. However, a detailed discussion of such algorithms is beyond the scope of this book.

Summary

The dominant topic of this chapter was importance sampling, a method to improve Monte Carlo methods by reducing the variance. In this method some hard to sample pdf was approximated as closely as possible by another, easy to sample pdf and one concentrated on intervals which particularly matter for an as accurate as possible estimate of, for instance, an expectation value of some property f(x). In this sense Markov-chain Monte Carlo techniques corresponded to importance sampling as long as detailed balance was obeyed. In this particular case the Markov-chain was known to approach the equilibrium distribution which must not necessarily be known in detail. The Metropolis algorithm with its symmetric acceptance probability was one possible realization of Markov-chains which obeyed detailed balance. Another method was the Metropolis-Hastings algorithm with its asymmetric acceptance probability. It also obeyed detailed balance and improved the variance over the ‘classical’ Metropolis algorithm. The second part of this chapter was dedicated to the simulation of the q-state Potts model, an extension of the Ising model. The Potts model had the feature that it developed a second order phase transition for q ≤ 4 and a first order phase transition for q > 4. Moreover, the transition temperature was q-dependent. The numerical simulation of the physics of this model proved to be able to pick up on all these particular features. Finally, some advanced algorithms developed for a more precise handling of various properties of spin-models, particularly around the phase transition, have been presented without going into great detail.

Problems

1.

Modify the program designed to solve the Ising model (see Problems in Chap. 15) in such a way that the physics of the q-states Potts model can be simulated for arbitrary values of q. Try to reproduce the figures presented within this chapter. In order to investigate the order of the phase transition, plot the internal energy per particle $$\left \langle \varepsilon \right \rangle$$ for T ≈ T c in a histogram for different measurements.

The critical temperatures listed in Table 18.1 for q = 2, 3, …, 8 can be used to validate your code.

2.

Include a non-zero external field h and study its influence on the physics of the q-states Potts model for different values of q.

References

1.

Norris, J.R.: Markov Chains. Cambridge Series in Statistical and Probabilistic. Cambridge University Press, Cambridge (1998)MATH

2.

Kendall, W.S., Liang, F., Wang, J.S.: Markov Chain Monte Carlo: Innovations and Applications. Lecture Notes Series, vol. 7. Institute for Mathematical Sciences, National University of Singapore. World Scientific, Singapore (2005)

3.

Modica, G., Poggiolini, L.: A First Course in Probability and Markov Chains. Wiley, New York (2012)CrossrefMATH

4.

Graham, C.: Markov Chains: Analytic and Monte Carlo Computations. Wiley, New York (2014)CrossrefMATH

5.

Potts, R.B.: Some generalized order-disorder transformations. Math. Proc. Camb. Philos. Soc. 48, 106–109 (1952). doi:10.1017/S0305004100027419ADSMathSciNetCrossrefMATH

6.

Doucet, A., de Freitas, N., Gordon, N. (eds.): Sequential Monte Carlo Methods in Practice. Information Science and Statistics. Springer, Berlin/Heidelberg (2001)MATH

7.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)MATH

8.

Kalos, M.H., Whitlock, P.A.: Monte Carlo Methods, 2nd edn. Wiley, New York (2008)CrossrefMATH

9.

von der Linden, W., Dose, V., von Toussaint, U.: Bayesian Probability Theory. Cambridge University Press, Cambridge (2014)CrossrefMATH

10.

Berg, B.A.: Markov Chain Monte Carlo Simulations and Their Statistical Analysis. World Scientific, Singapore (2004)CrossrefMATH

11.

German, S.: Stochastic relaxation, gibbs distributions, and the bayesian restoration of images. IEEE Trans. Pattern Anal. Mach. Intell. 6, 721–741 (1984). doi:10.1109/TPAMI.1984.4767596CrossrefMATH

12.

Neal, R.M.: Slice sampling. Ann. Stat. 31, 705–767 (2003). doi:10.1214/aos/1056562461MathSciNetCrossrefMATH

13.

Kardar, M., Berker, A.N.: Commensurate-incommensurate phase diagrams for overlayers from a helical potts model. Phys. Rev. Lett. 48, 1552–1555 (1982). doi:10.1103/PhysRevLett.48.1552ADSCrossref

14.

Wu, F.Y.: The potts model. Rev. Mod. Phys. 54, 235–268 (1982). doi:10.1103/RevModPhys.54.235ADSMathSciNetCrossref

15.

White, R.M.: Quantum Theory of Magnetism, 3rd edn. Springer Series in Solid-State Sciences. Springer, Berlin/Heidelberg (2007)Crossref

16.

Swendsen, R.H., Wang, J.S.: Nonuniversal critical dynamics in monte carlo simulations. Phys. Rev. Lett. 58, 86–88 (1987). doi:10.1103/PhysRevLett.58.86ADSCrossref

17.

Wolff, U.: Collective monte carlo updating for spin systems. Phys. Rev. Lett. 62, 361–364 (1989). doi:10.1103/PhysRevLett.62.361ADSCrossref

18.

Evertz, H.G.: The loop algorithm. Adv. Phys. 52, 1–66 (2003). doi:10.1080/0001873021000049195ADSCrossref

19.

Newman, M.E.J., Barkema, G.T.: Monte Carlo Methods in Statistical Physics. Clarendon Press, Oxford (1999)MATH

Footnotes

1

Please note that it is common in the literature to refer even to Eq. (18.12) as a Metropolis-Hastings algorithm, despite the fact that here P p (S′ → S) = P p (S → S′).

2

We calculate the magnetization in a particular spin Q via

(18.18)

3

This are regions in which all spins point in the same direction, the so-called Weiss domains [15].

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_19

19. Data Analysis

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

19.1 Introduction

It is the aim of this chapter to present some of the most important techniques of statistical data analysis which is of interest for experimental as well as theoretical sciences. In particular, the superstition that numerically generated data sets do not need to be analyzed with statistical methods is certainly not justified if the data was generated by Monte Carlo methods. Some simple methods of statistical analysis have already been discussed in previous chapters. For instance, in Chap. 12 we discussed simple quality tests for random number generators, in Chap. 15 we calculated the errors associated with the observables of the Ising model. Here, these simple methods will be summarized and some more advanced techniques will be introduced on a basic level. For a more advanced discussion of this topic we refer the interested reader to Refs. [1–5].

19.2 Calculation of Errors

We repeat briefly the basics of simple estimators which we made use of previously. We approximate the expectation value $$\left \langle x\right \rangle$$ of some variable x

(19.1)

where p(x) is a pdf, by its arithmetic mean

(19.2)

where the numbers x i follow the distribution p(x). It is of conceptual importance to distinguish between the expectation value $$\left \langle x\right \rangle$$ which is a c-number, while the estimator $$\overline{x}$$ is a random number fluctuating around $$\left \langle x\right \rangle$$. The error of approximating $$\left \langle x\right \rangle$$ by $$\overline{x}$$ can be estimated by calculating the variance

(19.3)

if the random numbers x i are uncorrelated (see Appendix E). In case of correlated data the treatment becomes more involved and this will be discussed in Sect. 19.3. The expectation values $$\left \langle x^{2}\right \rangle$$ and $$\left \langle x\right \rangle$$ in Eq. (19.3) may again be replaced by the corresponding estimators $$\overline{x^{2}}$$ and $$\overline{x}$$ in order to obtain a reasonable estimate of the variance $$\text{var}\left (\overline{x}\right )$$. In particular, we approximate

(19.4)

This approximation has already been applied in our investigation of the Ising model, Chap. 15. When dealing with Markov-chain Monte Carlo simulations, the result (19.3) can be interpreted in a rather trivial way: Repeating the simulation under identical conditions results in roughly 68 % of all simulations to yield a mean value $$\overline{x} \in [\overline{x} -\sigma _{\overline{x}},\overline{x} +\sigma _{\overline{x}}]$$, where $$\sigma _{\overline{x}} = \sqrt{\text{var} \left (\overline{x } \right )}$$ is the standard error.

We consider now the, in the meanwhile, quite familiar situation in which the underlying pdf p(x) of a sequence of random numbers {x i } is unknown. In such a case one cannot simply use a particular estimator without some knowledge of the particular form of p(x). A common way to proceed is the poor person’s assumption: The underlying distribution is symmetric. This assumption has its origin in the central limit theorem (see Appendix, Sect. E.8). However, some intuitive checks may be required if fatal misconceptions are to be avoided. Is the data set reasonably large one can retrieve essential information from collecting the data points in form of a histogram or, if the index i refers to time instances, by plotting a time sequence.

We can deduce a first idea about the form of the underlying pdf from a histogram. For instance, if the data set displays only one peak, as in Fig. 19.1, quantities like the mean or the variance could be useful. But if there are two (or more) separate peaks, as in Fig. 19.2, it does not necessarily make sense to calculate the mean or variance by summing over all the data points. Such a situation can, for instance, occur in statistical spin models, with two phases, as we observed it in the q-state Potts model, Fig. 18.​7a, b.

Fig. 19.1

Histogram generated by random sampling of a Gaussian of mean zero and variance one

Fig. 19.2

Histogram generated by random sampling of two Gaussians of mean zero and variance one, displaced by + 3 and − 3, respectively

Time series, in which the data points x i are plotted as a function of discrete time instances t i , can also reveal important information about the properties of the data set. For instance, systematic trends, outliers, or hints for correlations may be observed.

Let us turn our attention to some more advanced estimator techniques. So far we discussed the sample mean and sample variance as candidates for unbiased estimators.¹ In a more general context the calculation of observables from data sets might be more complex. In the following we assume a data set of N data points (x ₁, x ₂, …, x N ). Basically, we would like to estimate a quantity of the form $$f(\left \langle x\right \rangle )$$ where f is some particular function (for instance $$\left \langle x\right \rangle ^{2}$$). A bad (biased) estimate would be to calculate

(19.5)

which is definitely not the quantity we are interested in because for $$N \rightarrow \infty$$ we have $$\overline{f} \rightarrow \left \langle \,f\right \rangle$$ and not $$f(\left \langle x\right \rangle )$$. A better estimate would be to calculate

(19.6)

which converges to $$f(\left \langle x\right \rangle )$$ for $$N \rightarrow \infty$$. We discuss here two different methods to calculate the error attached to $$f(\overline{x})$$, namely the Jackknife method and the statistical bootstrap method.

We define Jackknife averages

(19.7)

and x i J is the average of all values x j ≠ x i . Moreover, we define

(19.8)

and this opens the possibility to estimate $$f(\left \langle x\right \rangle )$$ following

(19.9)

with the statistical error

(19.10)

which can be written as

(19.11)

for uncorrelated f i J (see Appendix E).

In the case of the statistical bootstrap we consider again a set of N data-points $$\{x_{i}\}$$. We randomly choose N elements from this data set without removal which constitutes the set $$\{x_{j}^{(i)}\}$$ and calculate for these N points the observable $$f_{i} = f(1/N\sum _{j}x_{j}^{(i)})$$. This procedure is repeated M-times and we get

(19.12)

and

(19.13)

This method was applied in Chap. 15 to determine estimates for the error-bars of the various observables as a function of temperature in Fig. 15.​6 The methods discussed here can, of course, also be employed to derive estimates for the errors attached to the various observables studied in the Potts model, Chap. 18

Let us close this section with a short comment on systematic errors. As already highlighted within Chap. 1 one also has to be aware of possible systematic errors. Like in experimental data, these errors are more easily overlooked in numerical data since they are rather hard to identify. In general, there is no method available to investigate systematic errors. For instance, in the simulation of the Ising model, the main source of errors was that the Markov-chain was not allowed to completely equilibrate which would have been equivalent to running the simulation forever. The introduction of the concept of an auto-correlation time will, at least, allow for a systematic investigation of this fundamental problem.

19.3 Auto-Correlations

The situation becomes more involved whenever the random numbers of the sequence {x i } are correlated, i.e. $$\text{cov}\left (x_{i},x_{j}\right )\neq 0$$ for i ≠ j [see Appendix, Eq. (E.16)], where the elements of the series {x i } are successive members of a time series. Hence, existing covariances between elements x i and x j account for auto-correlations of a certain observable between different time steps. We rewrite Eq. (19.3):

(19.14)

The first term on the right-hand side of Eq. (19.14) is identified as $$\text{var}\left (x_{i}\right )/N$$ which is assumed to be identical for all i, i.e. $$\text{var}\left (x_{i}\right ) \equiv \text{var}\left (x\right )$$. Furthermore, we rewrite the sum

and obtain

(19.15)

Let us assume time translational invariance:

(19.16)

We apply this relation to Eq. (19.15) and obtain

(19.17)

which can be reformulated as:

(19.18)

We introduced here the (proper) integrated auto-correlation time $$\hat{\tau }_{x}^{i}$$

(19.19)

and the normalized auto-correlation function

(19.20)

In most cases we are interested in the limit $$N \rightarrow \infty$$ of Eq. (19.19):

(19.21)

The form of the auto-correlation function A(x) can be approximated using the results of Sect. 16.​4 There, we observed that the stationary distribution π was the left-eigenvector of the transition matrix P with eigenvalue 1, Eq. (16.​73). Let $$\{\varphi _{\ell}\}$$ denote the set of all left-eigenvectors of the matrix P with eigenvalues $$\lambda _{\ell}$$, i.e. $$\varphi _{\ell}P =\lambda _{\ell}\varphi _{\ell}$$.² Then some arbitrary state q(0) can be expressed in this basis as:

(19.22)

After n consecutive time-steps we arrive at state q(n)

(19.23)

which follows from Eq. (16.​62). We denote the observable we want to calculate by O(n) and expand it according to Ref. [10]

(19.24)

where o i stands for the expectation value of O in the i-th eigenstate $$\varphi _{i}$$. For large n the value of O(n) will be dominated by the largest eigenvalue of P, say $$\lambda _{0}$$, and we denote this value by $$O(\infty ) =\alpha _{0}o_{0}$$. This allows us to rewrite Eq. (19.24) as

(19.25)

Let $$\lambda _{1} \in \mathbb{R}$$ be the second largest eigenvalue and let us define the exponential auto-correlation time τ x e via

(19.26)

and the value of O(n) can, for large values of n, be approximated by

(19.27)

where β is some constant. Hence, the auto-correlation obeys

(19.28)

and we can simply set for the auto-correlation function A(k)

(19.29)

where γ is some constant. We use this result in the expression for the integrated auto-correlation time  (19.21) and arrive at:

(19.30)

For τ x e  ≫ 1 the exponential function can be expanded into a Taylor series . Keeping terms up to first order results in:

(19.31)

However, we note that in general relation (19.31) is only a poor approximation because usually the exponential auto-correlation time is very different from the integrated auto-correlation time.

Let us briefly discuss our results. A comparison between Eqs. (19.3) and (19.18) reveals that due to correlations in the time series, the number of effective (or useful) data points N eff can be determined from

(19.32)

In the limit τ x e  → 0 we obtain $$\tau _{x}^{i} = 1/2$$ and, thus, recover Eq. (19.3). The effective number of measurements is the relevant quantity whenever the error of a Monte Carlo integration is calculated.

In another approach, one can determine the exponential auto-correlation time τ x e and use it to estimate the number of steps that should be neglected between two successive measurements. This can be achieved by fitting the auto-correlation A(k) with an exponential function. (A brief introduction to least squares fits can be found in Appendix H.) We note that in one and the same system the auto-correlation times may be very different for different observables.

19.4 The Histogram Technique

The histogram technique is a method which allows to approximate the expectation value of some observable for temperatures near a given temperature T ₀ without performing further Markov-chain Monte Carlo simulations. The basic idea is easily sketched. Suppose the observable O is solely a function of energy E. We perform a Markov-chain Monte Carlo simulation for a given temperature T ₀ and measure the energy E several times. The resulting measurements are sorted in a histogram with bin width Δ E as was demonstrated in Sect. 18.​3 If n(E) denotes the number of configurations measured within the interval (E, E +Δ E), then the probability that some energy is measured to lay within the interval (E, E +Δ E) is given by

(19.33)

where the index H refers to histogram and $$M =\sum _{E}n(E)$$ is the number of measurements. However, we note that this probability can also be expressed by the Boltzmann distribution

(19.34)

where N(E) denotes the number of micro-states within the interval (E, E +Δ E). N(E) is independent of the temperature T and relation (19.34) is valid for all temperatures T. In particular, for T = T ₀

(19.35)

which immediately yields

(19.36)

where α is some constant and we emphasize that n(E) was measured at T ₀. Inserting Eq. (19.36) into (19.34) yields

(19.37)

for arbitrary T. The expectation value $$\left \langle O\right \rangle _{T}$$ of the observable O at some temperature T can now be determined from

(19.38)

This result implies, that it is not necessary to run an additional Markov-chain Monte Carlo simulation in an attempt to compute the expectation value $$\left \langle O\right \rangle _{T}$$ for temperature T if T is in the vicinity of T ₀. However, if T deviates strongly from T ₀, the above procedure (19.38) does not provide a good approximation because the relevant configurations at T may have been very improbable at T ₀ and may, therefore, not have been reproduced sufficiently often in the original Markov-chain Monte Carlo simulation.

Summary

Data analysis is an important but often neglected part of natural sciences and in particular of numerical simulations. It consists mainly of consistency checks and error analysis. This chapter concentrated in a first step on error analysis. It discussed the most common methods to arrive at an estimate of the error involved whenever expectation values of some property are analyzed. These went beyond all those methods which have already been discussed in some detail throughout this book. In a second step auto-correlations have been discussed. They should be part of consistency checks and give valuable information about possible systematic errors. The auto-correlation analysis was of particular importance whenever the quality of the sequence of random numbers was crucial to a particular simulation. (Experiments in which the events are expected to be random, like radioactive decay, fall also into this category.) Nevertheless, this method proved to be very useful in Markov-chain Monte Carlo simulations as it allowed to define and determine an auto-correlation time which could serve as a measure of the number of sweeps which have to be neglected between two consecutive measurements. Finally, the histogram technique was introduced as a method of data interpolation. It allowed, in addition to applications which have already been presented within this book, to derive the expectation value of some property at some ‘temperature’ T from the already known expectation value of this same property at some other temperature T ₀ if $$T \sim T_{0}$$ and if the equilibrium distribution was known.

Problems

1.

Calculate the auto-correlation function for random numbers generated by the two linear congruential generators discussed in Sect. 12.​2 Check also the random number generator provided by your system. Discuss the results.

2.

Potts model: Calculate the error attached to the specific heat c h and the susceptibility χ using the Jackknife method for all values of q = 1, …, 8. Plot the corresponding diagrams and discuss the results. Determine the exponential and integrated correlation time.

References

1.

Gaul, W., Opitz, O., Schader, M. (eds.): Data Analysis. Springer, Berlin/Heidelberg (2000)

2.

Sivia, D., Skilling, J.: Data Analysis, 2nd edn. Oxford University Press, Oxford (2006)

3.

Adèr, H.J., Mellenbergh, G.J., Hand, D.J. (eds.): Advising on Research Methods: A Consultant’s Companion, chap. 14, 15. Johannes van Kessel, Huizen (2008)

4.

Brandt, S.: Data Analysis. Springer, Berlin/Heidelberg (2014)

5.

von der Linden, W., Dose, V., von Toussaint, U.: Bayesian Probability Theory. Cambridge University Press, Cambridge (2014)

6.

Iversen, G.P., Gergen, I.: Statistics. Springer Undergraduate Textbooks in Statistics. Springer, Berlin/Heidelberg (1997)

7.

Wilcox, R.R.: Basic Statistics. Oxford University Press, New York (2009)

8.

Monahan, J.F.: Numerical Methods of Statistics. Cambridge Series in Statistical and Probabilistic Mathematics. Cambridge University Press, Cambridge (2011)

9.

Wood, S.: Core Statistics. Institute of Mathematical Statistics Textbooks. Cambridge University Press, Cambridge (2015)

10.

Sokal, A.D.: Monte Carlo Methods in Statistical Mechanics: Foundations and New Algorithms. Department of Physics. New York University, New York (1996). www.​stat.​unc.​edu/​faculty/​cji/​Sokal.​pdf

Footnotes

1

Since mean and variance are calculated from the same data points, they are usually not unbiased. Therefore a common choice is the so called bias corrected variance $$\text{var}\left (\overline{x}\right )_{B}$$ which is given by $$\text{var}\left (\overline{x}\right )_{B} = \frac{N} {N-1}\text{var}\left (\overline{x}\right )$$ where N is the number of data points. A more detailed discussion can be found in any textbook on statistics [6–9].

2

Note that since P is a stochastic matrix, it follows that $$\vert \lambda _{\ell}\vert \leq 1$$ for all ℓ. Furthermore, it can be shown that the largest eigenvalue of a stochastic matrix is equal to 1.

© Springer International Publishing Switzerland 2016

Benjamin A. Stickler and Ewald SchachingerBasic Concepts in Computational Physicshttps://doi.org/10.1007/978-3-319-27265-8_20

20. Stochastic Optimization

Benjamin A. Stickler1  and Ewald Schachinger²

(1)

Faculty of Physics, University of Duisburg-Essen, Duisburg, Germany

(2)

Institute of Theoretical and Computational Physics, Graz University of Technology, Graz, Austria

20.1 Introduction

Suppose $$x \in \mathbb{S}$$ is some vector in an n-dimensional search space $$\mathbb{S}$$ and let $$\mathbb{H}: \mathbb{S} \rightarrow \mathbb{R}$$ be a mapping from the search space $$\mathbb{S}$$ onto the real axis $$\mathbb{R}$$. The function $$\mathbb{H}$$ plays a particular role and is usually referred to as the cost function. A minimization problem can be defined in a very compact form:

Find $$x_{0} \in \mathbb{S}$$, such that $$\mathbb{H}(x_{0})$$ is the global minimum of the cost function $$\mathbb{H}$$.

In analogue, a maximization problem with cost function $$\mathbb{H}$$ defines a minimization problem with cost function $$\mathbb{G} = -\mathbb{H}$$. The class of both problems is referred to as the class of optimization problems [1–3] and only minimization problems will be discussed here.

The reader might be aware that there are numerous applications in physics and related sciences. We list a few in order to remind ourselves of their fundamental importance:

The set of linear equations Ax = b is often regarded as the minimization problem: $$\mathbb{H}(x) =\| Ax - b\|^{2}$$ which can be beneficial for high dimensional problems.

The quantum mechanical ground state energy E ₀ is given by

(20.1)

where $$\left \vert \varPsi \right &gt;$$ denotes the wave function and H is the Hamiltonian of the system.

High dimensional and highly non-linear least squares fits. (More details can be found in Appendix H.)

The equilibrium crystal structure of solids is obtained by minimization of the free energy.

Protein folding is described by minimization of the forces in a molecular dynamics problem.

Whenever the cost function is at least once differentiable, methods of deterministic optimization can be applied [4]. (Two simple deterministic optimization methods are presented in Appendix I.) On the other hand, if $$\mathbb{H}$$ is not differentiable or too complex, due to a huge search space $$\mathbb{S}$$ or many local minima, methods of stochastic optimization [5] can be employed. The term stochastic optimization is used for methods which contain at least one step which is based on random number generation. Let us briefly give some examples of problems for which deterministic methods fail:

The Traveling Salesperson Problem [6, 7]: A traveling salesperson has to visit L cities in a tour as short as possible under the constraint that he/she has to return to the starting point in the end. Each city has to be visited only once, hence the cities have to be ordered in such a way that the travel length becomes a global minimum. In particular, the cost function

(20.2)

has to be minimized. Here {i} denotes a certain configuration of cities and we set $$i_{L+1} = i_{1}$$. Obviously, we cannot calculate the first derivative of $$\mathbb{H}$$ with respect to {i}, set it zero, and solve the problem in the classical way. On the other hand, a brute force approach of calculating $$\mathbb{H}(\{i\})$$ for all possible arrangements {i} is not possible since we have L! different possible routes. Since for one particular choice all L starting points and both travel directions yield the same result, we have to calculate $$L!/(2L) = (L - 1)!/2$$ different configurations {i}. We would have about 10¹⁵⁵ different choices for L = 100 cities! This clearly makes such an approach intractable.

The arrangement of timetables under certain constraints. In particular, the design of timetables in schools, universities or at airports. This problem is also referred to as the Nurse Scheduling Problem [8].

The Ising spin glass [9]: In contrast to the classical Ising model, the Ising spin glass is characterized by nearest neighbor interactions J ij which are, in the most simple case, chosen to be $$J_{ij} = +1$$ and $$J_{ij} = -1$$ with the same probability. In this case the ground state below the critical temperature is not simply given by a configuration in which all spins point in the same direction. Of course, the ground state configuration in such a case can be highly degenerate. The fact that such a model can be simulated using Markov-chain Monte Carlo methods as they have been discussed within Chaps. 15 and 18 gives us some idea of how one may employ stochastic methods to solve optimization problems.

The N-Queens Problem [10]: Place N queens on a N × N chessboard in such a way that no two queens attack each other. In particular, this means that two queens are not allowed to share the same row, the same column, and the same diagonal. It can be shown that the problem possesses solutions for N ≥ 4. One defines a function $$\mathbb{H}(\{n\})$$ which counts the number of attacks in a certain configuration {n}. For instance, for N = 4, the configuration

has $$\mathbb{H}(\{n\}) = 2$$. On the contrary, the configuration

solves the 4-queens problem and $$\mathbb{H}(\{n\}) = 0$$.

We concentrate here on some of the most basic methods of stochastic optimization: the method of hill climbing, the method of simulated annealing, and genetic algorithms. Ideas on which several more advanced techniques are based will be sketched in Sect. 20.5.

20.2 Hill Climbing

The method of hill climbing [11] is probably one of the most simple methods of stochastic optimization. Given a cost function $$\mathbb{H}(x)$$, we execute the following steps:

1.

Choose an initial position x ₀.

2.

Randomly pick a new x n from the neighborhood of x n−1.

3.

Keep x n if $$\mathbb{H}(x_{n}) \leq \mathbb{H}(x_{n-1})$$.

4.

Terminate the search if no new x n can be found in the neighborhood of x n−1.

We note that the algorithm requires a neighborhood relation. This relation is to be defined for each particular problem. For instance, in the case of the traveling salesperson problem it is by no means clear what a configuration in the neighborhood of a certain route {i} should mean. To elaborate on this problem we concentrate here on two particular problems which help to demonstrate how such a neighborhood relation can be defined.

In the traveling salesperson problem or in the Ising spin glass model the neighborhood of a route {i} or of a configuration $$\mathcal{C}$$ can be defined as the set of all routes {i} in which two cities have been interchanged or as the set of all configurations $$\mathcal{C}$$ in which one spin has been flipped.

On the other hand, if the search space $$\mathbb{S} = \mathbb{R}^{n}$$ we may define the neighborhood as the number of points within an n-sphere of radius r centered at z ≡ x n−1. It is rather simple to sample points from an n-sphere centered at the origin by applying the method of G. Marsaglia [12]: For an n-dimensional vector we sample all components x ₁, …, x n from the normal distribution $$\mathcal{N}(0,1)$$ with mean zero and variance one. The points are then transformed according to

(20.3)

where $$\|x\|$$ denotes the Euclidean norm of the vector x. The points given by Eq. (20.3) lie on the surface of the n-sphere with radius r. In order to obtain uniformly distributed random points within a sphere with radius r we draw a random number u ∈ [0, 1] and calculate

(20.4)

where the factor 1∕n in the exponent of u ensures that the points are uniformly distributed.

Let us briefly summarize the most important properties of the method of hill climbing:

The way the algorithm is defined it will terminate in a local minimum and not in the global minimum. A classical remedy is the restart of the algorithm from various different initial positions. Information gathered from previous runs can help to make a good choice for the initial positions of restarts.

It depends highly on the choice of initial conditions if and how the global minimum is found. This situation is very similar to the application of deterministic methods of optimization (see Appendix I). Sometimes it may even be of advantage to accept points which result in a slight increase of the cost function’s value just to escape a local minimum.

For most problems this method is very expensive from a computational point of view.

We apply the method of hill climbing to the N-queens problem for N = 8. The algorithm is executed in the following way: In the initial configuration the queens are set randomly on the chessboard and we place only one queen in each row and column. It is then checked whether or not two queens attack each other. If they do, a new configuration is generated by picking two queens at random and by changing their respective positions. This is repeated until a configuration arises in which none of the queens attacks another. Such an algorithm resembles a random walk in a parameter space which spans all possible configurations under the constraint that only one queen is placed in each row and column. The iteration is terminated as soon as no queen is attacked by any other queen. It is rather obvious that this strategy is not very fast, however, one possible solution to the problem for N = 8 can easily be found within a few iteration steps:

However, for large values of N hill climbing is definitely not a recommendable method to solve the N-queens problem.

20.3 Simulated Annealing

Let us turn our attention to simulated annealing [7, 13, 14]. The name of this algorithm stems from the annealing process in metallurgy in which a metal is first heated and then slowly cooled in order to reduce the amount of defects in the material. The reasoning behind this method can quite easily be reconstructed with the help of the Ising model which we discussed in detail in Chap. 15. There we learned from thermodynamics that the equilibrium distribution of possible configurations $$P(\mathcal{C},T)$$ at a certain temperature T is a Boltzmann distribution

(20.5)

where $$H(\mathcal{C})$$ is the Hamilton function of the system. In particular, we expect that the system is in its ground state (let us assume a non-degenerate ground-state for the time being) with probability one in the limit T → 0, provided that we cooled sufficiently slowly so that the system had enough time to equilibrate. This can be used to solve the optimization problem: We take the cost function $$\mathbb{H}(x)$$ and define the probability for the realization of a particular state (configuration) in the search space $$x_{0} \in \mathbb{S}$$ by

(20.6)

where T is some external parameter, which we refer to as temperature for reasons of convenience, and Z denotes the normalization constant:

(20.7)

We start the procedure at some finite initial temperature T ₀ ≠ 0 and construct a Markov-chain of states {x n } which converges towards the distribution (20.6). We choose, of course, a sampling technique which does not require the explicit knowledge of the normalization Z, such as the Metropolis-Hastings algorithm of Sect. 18.​2 As soon as the Markov-chain reaches its stationary distribution for a given temperature T, we slightly decrease the temperature and restart the Markov-chain with the last state of the previous temperature. By slowly cooling the search Markov-chain, we exclude unimportant parts of the search space by decreasing their acceptance probability. Nevertheless, the chain is given enough time to explore the whole remaining search space at each temperature. This procedure is commonly referred to as the classical version of simulated annealing.

It is of advantage to start with an initial temperature which allows to cover the largest part of possible states in the search space $$\mathbb{S}$$. Thus, the acceptance probability for a new state in the Markov-chain is almost equal to one for all $$x \in \mathbb{S}$$. If this were not the case, some regions of the search space might be excluded from our search routine right away due to an unlucky choice of the initial configuration. In particular, the result might be a state in the neighborhood of the initial state of the Markov-chain and it is, therefore, most likely a local minimum rather than the global minimum.

We note that the algorithm consists of the following essential ingredients: (i) a proposal probability for new states x within the search space $$\mathbb{S}$$, (ii) an acceptance probability P a (x → x′) for a proposed x′ from a previous state x, and (iii) a cooling strategy T = T(t), where t is time. Let us briefly elaborate on these points.

(i) Proposal Probability

The question of how to generate new states x from a previous state x′ within the search space $$\mathbb{S}$$ has already been answered in the case of hill climbing, Sect. 20.2 by defining the neighborhood of a state in search space. The corresponding proposal probability will be denoted by P p (x → x′).

(ii) Acceptance of Probability

The acceptance probability has to be chosen in such a way that the sequence of generated states constitutes a Markov-chain which converges toward the distribution (20.6). Hence, detailed balance has to be imposed and the implications of this requirement have been discussed extensively in Chap. 18 Note that the proposal probability has to be included into the definition of the acceptance probability as was outlined in Sect. 18.​2

One particular choice of a Metropolis-Hastings acceptance probability

(20.8)

appears to be quite natural for several reasons:

It is very general and can, thus, also handle asymmetric proposal probabilities.

In the symmetric case P p (x → x′) = P p (x′ → x) and $$\mathbb{H}(x') \leq \mathbb{H}(x)$$ we get

(20.9)

according to our choice (20.6) and the state x′ is accepted with probability one. On the other hand, for $$\mathbb{H}(x') &gt; \mathbb{H}(x)$$, x′ may still be accepted with some finite probability P a (x → x′, T) which offers an opportunity to escape a local minimum.

(iii) Cooling Strategy

The design of a proper cooling strategy includes both, the choice of an appropriate initial temperature T ₀ as well as the formulation of a mathematical rule which defines $$T_{n+1} = f(T_{n})$$ where T n+1 < T n .

First of all we discuss the choice of the initial temperature. A common choice is to choose it in such a way that at least 80 % of all generated states are accepted. The simplest procedure to determine this temperature starts with some arbitrary value T ₀ > 0 and generates N states. If the number of rejected states N r is greater than 0. 2 N, then the temperature T ₀ is doubled and the number of rejected states is measured again.

Another more sophisticated choice is based on the following idea: The best choice would be $$T_{0} \rightarrow \infty $$ because then the acceptance probability would be one for all possible states independent of $$\mathbb{H}(x)$$. This corresponds to a random walk in search space $$\mathbb{S}$$ and we calculate the mean value $$\left \langle \mathbb{H}\right \rangle _{\infty }$$ and the variance $$\text{var}\left (\mathbb{H}\right )_{\infty }$$. Thus, the function values $$\mathbb{H}$$ fluctuate between . We consider now the expectation value $$\left \langle \mathbb{H}\right \rangle _{T_{0}}$$ for large values of T ₀. We define the small parameter $$\epsilon = 1/T_{0} \ll 1$$ and find with p(x, ε) = P(x, T)

(20.10)

Re-substituting $$T_{0} = 1/\epsilon$$ results, finally, in:

(20.11)

The initial temperature T ₀ is now chosen in such a way that the expectation value $$\left \langle \mathbb{H}\right \rangle _{T_{0}}$$ borders the infinite temperature fluctuations from below and we set consequently

(20.12)

with the implication that

(20.13)

We are now in a position to investigate appropriate cooling strategies: The geometric cooling schedule

(20.14)

with 0 ≪ q < 1 is very often used. However, particular cost functions $$\mathbb{H}(x)$$ may develop several phase transitions in the course of the cooling process. Naturally, the expectation value $$\left \langle \mathbb{H}\right \rangle$$ changes rapidly in the region T ≈ T c , with T c the temperature at which the phase transition occurs. It is, therefore, certainly of advantage to take such a possibility into account and to design the cooling strategy accordingly.

Hence, a more appropriate strategy is to use temperature changes which cause only slightly modified acceptance probabilities. In particular, we demand that

(20.15)

with 0 < δ ≪ 1. Assuming a Boltzmann type distribution for P(x, T n ), we obtain

(20.16)

or

(20.17)

Hence, we can choose

(20.18)

where we replaced $$\mathbb{H}(x) \approx 3\sqrt{\text{var} \left (\mathbb{H}\right ) _{T_{n }}}$$. This choice is plausible if one recognizes that we can replace $$\mathbb{H}(x) \rightarrow \mathbb{H}(x) - \mathbb{H}_{\mathrm{min}}$$ in the above calculations, where $$\mathbb{H}_{\mathrm{min}}$$ represents the (unknown) minimum of $$\mathbb{H}(x)$$. This cooling schedule is known as the Aarts schedule.

Finally, we have to discuss how to terminate the algorithm. Typically, there are several choices and we present briefly the most popular ones. The obvious choice is to terminate the algorithm as soon as the acceptance ratio is below some predefined threshold value. A more sophisticated choice is to terminate the algorithm whenever the mean value $$\left \langle \mathbb{H}\right \rangle$$ reaches some constant value. A quite different and more formal approach would be to initially define a maximum number of iterations or to set the final temperature T f to some reasonable value. Nevertheless, the termination condition has to be defined for each particular problem individually.

Before presenting an example, we note some further results associated with cooling strategies. It was demonstrated by S. Kirkpatrik et al. [15] that the optimal cooling strategy for a Boltzmann type distribution is of the form

(20.19)

where n labels the temperature steps. In this case the global minimum is found with probability one. However, the convergence is rather slow. In addition, several extensions of classical simulated annealing have been suggested in the literature. For instance, fast simulated annealing uses a Cauchy distribution

(20.20)

instead of a Boltzmann distribution. Here d is the dimension of the search space $$\mathbb{S}$$. The optimal cooling strategy for such a distribution function is of the form

(20.21)

which signifies a considerable increase in convergence speed in comparison to Eq. (20.19). Another generalization is referred to as generalized simulated annealing and is based on the Tsallis distribution which depends on an external parameter ε:

(20.22)

It can be demonstrated that P ε converges toward the Boltzmann distribution for ε → 0. We mention in passing that the concept of the Tsallis distribution is closely intertwined with the definition of the Tsallis entropy and the formulation of non-extensive thermodynamics by C. Tsallis [16].

As a first illustrative example we discuss the traveling salesperson problem for N = 36 cities on a regular grid because in this case the optimal route is easily identified. We calculate the initial temperature from Eq. (20.13) and employ the geometric cooling schedule (20.14) with q = 0. 99 together with a termination criterion of the form

(20.23)

where η is the required accuracy. Figure 20.1a presents one route for the initial temperature and Fig. 20.1b displays one of many optimal routes after convergence has been reached. This case will be called the first scenario. In the second scenario we place 36 cities in four equally spaced clusters. Results for the optimal route are presented in Fig. 20.2b.

Fig. 20.1

(a) Initial route of the traveling salesperson for 36 cities on a regular grid. (b) One of many optimal routes of the traveling salesperson for 36 cities on a regular grid

Fig. 20.2

(a) Initial route of the traveling salesperson for 36 cities placed in four equally spaced clusters. (b) One of many optimal routes of the traveling salesperson for 36 cities placed in four equally spaced clusters

The possibility of phase transitions to occur during the cooling process has already been mentioned. In a genuine physical system the question whether a phase transition is possible at all or if it is of first or second order is solely determined by the Hamilton function H(x) of the system. As an intriguing example we refer to the q-states Potts model of Sect. 18.​3 where a second order phase transition was observed for q ≤ 4 and a first order phase transition for q > 4. In analogy, the order of a ‘phase transition’ during the iteration process toward the global minimum in simulated annealing is completely determined by the particular properties of the cost function $$\mathbb{H}(x)$$. We want to study such a possibility and determine the expectation values $$\left \langle \mathbb{H}\right \rangle _{T}$$ and the ‘specific heat’ c h as functions of temperature T for the two scenarios of the traveling salesperson problem. Figure 20.3 presents the results for scenario one and Fig. 20.4 those for scenario two. The second scenario develops two second order phase transitions while in the first scenario only one second order phase transition can be observed. The first phase transition of the second scenario (at T ≈ 3. 5) can be related to the optimization of the clusters’ sequence while in the second phase transition (at T ≈ 0. 42) the sequence of cities within the clusters becomes finalized. These two transitions are indicated by down arrows labeled (1) and (2) in Fig. 20.4.

Fig. 20.3

(a) The expectation value $$\left \langle \mathbb{H}\right \rangle _{T}$$ and (b) the ‘specific heat’ c h vs temperature T for scenario one

Fig. 20.4

The same as Fig. 20.3 but for scenario two. Two second order phase transitions are observed. They are indicated by down arrows labeled (1) and (2)

20.4 Genetic Algorithms

The sparkling idea of genetic algorithms has originally been lent from natures survival of the fittest [17]. The basic intentions are quickly summarized by remembering the natural evolution of a particular species within a hostile environment: The individuals of the species reproduce from one generation to another. During this process the genes of the individuals are modified by local mutations. Individuals best accustomed to the environment then survive with higher probability. This very last process is referred to as selection. By iterating this process for large populations the individuals of the whole species will adjust their properties to the environment on average,¹ and, thus, the individuals will be better equipped for survival within the hostile environment. A large population is compulsory in order to obtain a huge variety in the phenotype of the individuals. Algorithms based on such a scheme are referred to as genetic algorithms.

We are not going into the details of the implementation of genetic algorithms because this is beyond the scope of this book. However, the ideas sketched above will be applied to the problem of the traveling salesperson passing through m-cities just to illustrate the method. Let $$s = (s_{1},\ldots,s_{m}) \in \mathbb{N}^{m}$$ denote a list of m integers, which obey s i  ≤ i. For instance, for m = 10, s might be given by

(20.24)

The order of cities is then recovered by setting $$\hat{s} = (s_{m},\ldots,s_{1})$$ and performing the steps illustrated in Table 20.1.

Table 20.1

Sample tour to illustrate the recovery of the order of cities within a genetic algorithm. Elements indicated by [x] are ‘selected’ elements which are added to the column Tour

1

2

3

4

5

6

7

8

9

10

Tour

9

1

2

3

4

5

6

7

8

[9]

10

9

4

1

2

3

[4]

5

6

7

8

10

4

3

1

2

[3]

5

6

7

8

10

3

3

1

2

[5]

6

7

8

10

5

5

1

2

6

7

[8]

10

8

1

[1]

2

6

7

10

1

4

2

6

7

[10]

10

2

2

[6]

7

6

2

2

[7]

7

1

[2]

2

In words: The vector $$\hat{s}$$ labels the elements taken from the list (1, 2, …, m) with removal. The resulting list Tour specifies the optimum sequence of the cities. The genetic algorithm is executed in the following steps:

Define M initial individuals.

Mutation: for each individual we introduce a single random local modification with probability p mut.

Reproduction: We produce M additional individuals by pairwise combining the parents. This is performed by

(a)

Pick two individuals at random.

(b)

Draw a random integer r ∈ [1, m − 1] and replace the first r genes of the first individual by the first r genes of the second individual and vice versa.

In this way, we obtain 2M individuals.

Selection: The M individuals with the highest fitness which corresponds to the lowest value of the cost function survive.

The above steps are repeated until the desired number of generations has been achieved.

In Fig. 20.5 we show the optimal path for the traveling salesperson problem discussed in the previous section, but now for N = 30 cities. It was obtained with the genetic algorithm described here. The number of individuals was chosen to be M = 5000 and the number of generations to be G = 5000.

Fig. 20.5

(a) The random route of one individual out of the population of 5000. (b) One of many optimal routes of the traveling salesperson for N = 30 cities as obtained by a genetic algorithm

Some remarks are appropriate: First of all we note that there are many different permutations of how a genetic algorithm can be realized. In particular, it is the problem which determines the most convenient form to implement the essential ingredients: mutation, reproduction, and selection. However, particular care is required in formulating the algorithm in such a way that it does not produce individuals which are too similar. In such a case the algorithm is very likely to terminate in a local minimum.

Another remark comments on how to treat optimization problems with continuous variables x. Here it might be advantageous to represent the variable x in its binary form because it makes the reproduction step particularly simple.

20.5 Some Further Methods

We briefly list some alternative stochastic optimization techniques without going into detail. Two famous alternatives which are closely related to simulated annealing are:

Threshold Accepting Algorithms: The new configuration x′ is accepted with probability one if $$\mathbb{H}(x') \leq \mathbb{H}(x) + T$$. During the simulation the temperature or threshold level T is continuously decreased. The above choice of an acceptance probability is very effective to allow for an escape from local minima.

Deluge Algorithms: These algorithms are very similar to threshold accepting algorithms. We present it in the original formulation which is suited to find the global maximum of a function $$\mathbb{G}(x)$$. The global minimum of $$\mathbb{H}(x)$$ can be found by searching the maximum of $$\mathbb{G}(x) = -\mathbb{H}(x)$$. One accepts a new state x′ with probability one if $$\mathbb{G}(x') &gt; T$$, where T is continuously increased during the simulation. Hence, the whole landscape of $$\mathbb{G}(x)$$ is flooded with increasing T until only the summits of $$\mathbb{G}(x)$$ are left. Finally, only the biggest mountain will reach out of the water and the global maximum has been found.

Two famous ideas which are closely related to genetic algorithms are:

Grouping Genetic Algorithms: The idea is to put the individuals of the population in distinct groups. These groups may for instance be formed by comparing the genes or grouping individuals with similar cost function values. All members of a group have one part of the genes in common, and all operators acting on genes act on the whole group. Such an approach can significantly improve the convergence rate of a classical genetic algorithm.

Ant Colony Optimization: The idea is, again, borrowed from nature, in particular from an ant colony searching the optimum path between two or more fixed or variable points. In a real world an ant travels from one point to another randomly, leaving a trail of pheromone on its traveled path. Following ants are very likely to follow the pheromone trail, however, some random nature remains. The key point is that with time the pheromone trail starts to evaporate, hence its impact on the path of following ants is reduced if the path is not traveled frequently or often enough so that the pheromones evaporated. In this way one prevents the algorithm to get stuck in a local minimum and the global minimum may be found by sending out artificial ants.

There are many further methods available in the literature (see, for instance, Refs. [2, 18]) to which we refer the interested reader.

Summary

The local maximum/minimum of some cost function $$\mathbb{H}(x)$$ within a search space $$\mathbb{S}$$ can be determined using stochastic methods, thus establishing a particular class of algorithms known as Stochastic Optimization. The most straightforward method was the algorithm of hill climbing which resembled a controlled random walk within a restricted search space $$\mathbb{S}$$ called neighborhood. Because of this feature hill climbing will find in general local minima within this neighborhood and the global minimum has to be found under variation of initial conditions. This made this method too expensive for more complex problems from a computational point of view. To move from a random walk formulation to a formulation on the basis of Markov-chain Monte Carlo was the logical next step. The method of choice was named simulated annealing. It used the Metropolis-Hastings algorithm to generate new configurations within a search space $$\mathbb{S}$$ from a temperature dependent equilibrium distribution. A cooling strategy was used to slowly restrict the search space to the neighborhood of the global minimum. This global minimum was always found, albeit rather slowly. We mentioned some flavors of this basic algorithm which either differed in the definition of the acceptance probability or in the cooling strategy. A completely different class of algorithms was established with the so-called genetic algorithms. They were adapted from nature’s concept of the survival of the fittest. They were based on the notions of: (i) Mutation, a single random local modification of a certain probability. (ii) Reproduction, additional ‘individuals’ were generated by pairwise combining parents. (iii) Selection: Individuals with the lowest value of the cost function survived and mutation started again. Genetic algorithms established a very versatile class of solvers to cover a huge body of optimization problems.

Problems

Solve the traveling salesperson problem for N = 20 cities on a regular grid with the help of simulated annealing. As a cooling schedule, use the geometric cooling as explained in Sect. 20.3. Determine the initial temperature by demanding an acceptance rate of 90 % and terminate the algorithm if the mean value of the cost function $$\left \langle \mathbb{H}\right \rangle$$ remains unchanged for at least 10 successive temperatures. Calculate the expectation value $$\left \langle \mathbb{H}\right \rangle _{T}$$ for different temperatures and identify the transition temperature. In a second step produce a list of 20 cities which are randomly distributed on a two-dimensional grid. Optimize this problem as well. Note that you should produce the list of cities only once in order to obtain comparable and reproducible results.

References

1.

Panos, M.P., Resende, M.G.C. (eds.): Handbook of Applied Optimization. Oxford University Press, New York (2002)MATH

2.

Hartmann, A.H., Rieger, H.: Optimization Algorithms in Physics. Wiley – VCH, Berlin (2002)MATH

3.

Locatelli, M., Schoen, F.: Global Optimization. MPS-SIAM Series on Optimization. Cambridge University Press, Cambridge (2013)CrossrefMATH

4.

Scholz, D.: Deterministic Global Optimization. Springer, Berlin/Heidelberg (2012)CrossrefMATH

5.

Schneider, J.J., Kirkpatrick, S. (eds.): Stochastic Optimization. Springer, Berlin/Heidelberg (2006)MATH

6.

Lawler, E.L., Lenstra, K.K., Rinnooy Kan, A.H.G., Shmoys, D.B.: The Traveling Salesman Problem: A Guided Tour of Combinatorial Optimization. Wiley, New York (1985)MATH

7.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)MATH

8.

Kundu, S., Acharyya, S.: Stochastic local search approaches in solving the nurse scheduling problem. In: Chaki, N., Cortesi, A. (eds.) Computer Information Systems – Analysis and Technologies, Communications in Computer and Information Science, vol. 245, pp. 202–211. Springer, Berlin/Heidelberg (2011)

9.

Marinari, E., Parisi, G., Ritort, F.: On the 3d Ising spin glass. J. Phys. A: Math. Gen. 27, 2687 (1994). doi:10.1088/0305-4470/27/8/008ADSCrossref

10.

Watkins, J.J.: Across the Board: The Mathematics of Chessboard Problems. Princeton University Press, Princeton (2012)MATH

11.

Skiena, S.S.: The Algorithm Design Manual. Springer, Berlin/Heidelberg (2008)CrossrefMATH

12.

Marsaglia, G.: Choosing a point from the surface of a sphere. Ann. Math. Stat. 43, 645–646 (1972). doi:10.1214/aoms/1177692644CrossrefMATH

13.

Bertsimas, D., Tsitsiklis, J.: Simulated annealing. Stat. Sci. 8, 10–15 (1993)CrossrefMATH

14.

Salamon, P., Sibani, P., Frost, R.: Facts, Conjectures, and Improvements for Simulated Annealing. Cambridge University Press, Cambridge (2002)CrossrefMATH

15.

Kirkpatrik, S., Gellat, C.D., Jr., Vecchi, M.P.: Simulated annealing. Science 220, 671 (1983)ADSMathSciNetCrossref

16.

Tsallis, C.: Introduction to Nonextensive Statistical Mechanics. Springer, Berlin/Heidelberg (2009)MATH

17.

Man, K.F., Tang, K.S., Kwong, S.: Genetic Algorithms. Springer, Berlin/Heidelberg (1999)CrossrefMATH

18.

Bäck, T.: Evolutionary Algorithms in Theory and Practice. Oxford University Press, New York (1996)MATH

Footnotes

1

Note that in the real world the environment (in particular the natural enemies of a species) develop as well. Moreover, we do not consider any communication within a species, like the formation of societies, learning, and related processes.

Appendix A: The Two-Body Problem

Consider two mass points with positions $$r_{i}(t) \in \mathbb{R}^{3}$$ , i  = 1, 2 and masses m i , i  = 1, 2. It is assumed that the point masses interact through a central potential $$U = U(\vert r_{1}(t) - r_{2}(t)\vert )$$ and that external forces are neglected. Thus, the system is closed. The explicit notation of time t is now omitted for the sake of a more compact presentation. Furthermore, we introduce with $$p_{i} \in \mathbb{R}^{3}$$ , i  = 1, 2 the point mass’ momentum and the Lagrange function [ 1 – 5 ] of the system takes on the form

(A.1)

The moments p i are replaced by

(A.2)

and this yields for the Lagrange function ( A.1 )

(A.3)

where $$\dot{r}_{i}$$ denotes the time derivative of r i . We note the following symmetries: the Lagrange function is (i) translational invariant, (ii) rotational invariant, and (iii) time invariant. We know from classical mechanics that each symmetry of the Lagrange function corresponds to a constant of motion (a quantity that is conserved throughout the motion) and, thus, results in a reduction of the dimensionality of the 12-dimensional phase space.

Let us demonstrate these symmetries: In order to prove translational invariance, we transform to center of mass coordinates which are defined as

(A.4)

It is easily verified that we can express the original coordinates r ₁ and r ₂ with the help of ( A.4 ) as

(A.5)

The Lagrange function ( A.3 ) is rewritten in these new coordinates ( A.4 ) and this yields

(A.6)

where we introduced the total mass M and the reduced mass m :

(A.7)

Obviously, the center of mass coordinate R plays in Eq. ( A.6 ) the role of a cyclic coordinate: It does not appear explicitly in the Lagrange function. This means that the system is translational invariant and we can deduce from Lagrange ’s equations that

(A.8)

and the center of mass momentum is conserved. Hence, we obtain that

(A.9)

with the solution

(A.10)

where $$A,B \in \mathbb{R}^{3}$$ are constants determined by the initial conditions of the problem. As a result, the center of mass moves along a straight line with constant velocity. We collect all results and reformulate the Lagrange function  ( A.6 ) as

(A.11)

Hence, the problem was reduced to a one-body problem with the Lagrange function $$\tilde{L}(r,\dot{r})$$ . In what follows the tilde is omitted and the Lagrange function

(A.12)

is now studied instead of Eq. ( A.11 ). It is an effective one-body Lagrange function.

In the next step the effect of rotational invariance is investigated. Equation ( A.12 ) resembles the Lagrange function of a particle of mass m which is located at position r and moves in the field of a central force $$F \in \mathbb{R}^{3}$$ . This force points to the center of the coordinate system (or points from the center of the coordinate system to the particle). This situation is clearly invariant under a rotation of the coordinate system since $$U = U(\vert r\vert )$$ depends only on the modulus of r . Consequently, r is parallel to F for all t  ≥ 0. In such a case the vector of angular momentum $$\ell\in \mathbb{R}^{3}$$ is conserved, since

(A.13)

where $$\mathcal{M}$$ is the torque . This allows us to arbitrarily rotate our coordinate system. We take advantage if this property and rotate it in such a way that

(A.14)

where e z is the unit vector in z -direction. Moreover, since the angular momentum ℓ is given by

(A.15)

and because $$\ell\|e_{z}$$ we conclude that r  ⊥  e z . This allows us to set z  = 0 which means that the whole motion of the point mass can be described in the x − y plane. Rotational invariance led us to the conservation of angular momentum and this made the reduction from a three-dimensional problem to a two dimensional problem possible. The particular form ( A.12 ) of the Lagrange function suggests the introduction of polar coordinates $$(\rho,\varphi )$$ :

(A.16)

We solve now Lagrange ’s equations  ( A.6 ) on the basis of Eq. ( A.16 ): The first step deals with the differential equation for the radius ρ

(A.17)

thus

(A.18)

The differential equation for the angle $$\varphi$$ follows from

(A.19)

which corresponds to

(A.20)

Equation ( A.20 ) is trivially fulfilled since according to Eq. ( A.15 )

(A.21)

However, we solve Eq. ( A.21 ) for $$\dot{\varphi }$$

(A.22)

plug ( A.22 ) into ( A.18 ), and obtain

(A.23)

We make use of the time invariance of the Lagrange function ( A.16 ). This equation does not explicitly depend on time t and we have

(A.24)

This implies conservation of energy, as can easily be demonstrated. For this purpose, we regard the total time derivative of the Lagrange function L

(A.25)

and solve for $$\frac{\partial } {\partial t}L$$

(A.26)

Consequently

(A.27)

which states the conservation of energy. We evaluate this expression with the help of Eq. ( A.16 ). We obtain

(A.28)

Here we employed, in the second step, relation ( A.22 ). In summary, time invariance resulted in:

(A.29)

This is a first order differential equation in ρ .

The necessary step required for a solution of the two-body problem can now be outlined: (i) Calculate R ( t ) according to Eq. ( A.10 ), (ii) solve Eq. ( A.29 ) in order to obtain ρ ( t ), (iii) plug ρ ( t ) into Eq. ( A.22 ) and solve for $$\varphi (t)$$ , (iv) since z ( t ) = 0, the original vectors r ₁ ( t ), r ₂ ( t ) can be constructed from ρ ( t ) and $$\varphi (t)$$ . All integration constants are uniquely determined by the initial conditions of the problem at hand.

From Eq. ( A.29 ) we obtain

(A.30)

which results in an implicit equation for ρ

(A.31)

where we defined ρ ₀  ≡  ρ ( t ₀ ), t ₀ is some initial time, and we neglected the negative root. Equation ( A.31 ) defines t as a function of ρ , t  =  t ( ρ ), which has to be inverted to, finally, obtain the required solution ρ  =  ρ ( t ). Whether Eq. ( A.31 ) can be solved analytically depends on the particular form of the potential U ( ρ ). If Eq. ( A.31 ) cannot be solved analytically one has to employ numerical approximations.

Finally, the angle $$\varphi$$ can be expressed as a function of the radius ρ , i.e. $$\varphi =\varphi (\rho )$$ . We get from Eqs. ( A.22 ) and ( A.30 )

(A.32)

integrate over ρ , and find the desired relation

(A.33)

where $$\varphi _{0} \equiv \varphi (t_{0})$$ .

Appendix B: Solving Non-linear Equations: The Newton Method

We give a brief introduction into the solution of non-linear equations with the help of Newton ’s method. ¹ We regard a differentiable function F ( x ) and we would like to find the solution of the equation

(B.1)

The simplest approach is to transform the equation into an equation of the form

(B.2)

which is always possible. This equation could be solved iteratively by simply repeating

(B.3)

where we start with some initial value x ₀ . If this method converges, one can approximate the solution arbitrarily close, however, convergence is not guaranteed and will in fact depend on the transformation from Eqs. ( B.1 ) to ( B.2 ). A more advanced technique is the so called Newton method [ 6 , 7 ]. It is based on the definition of f ( x ) as

(B.4)

which allows the iteration

(B.5)

Here F ′( x ) denotes the derivative of F ( x ) with respect to x . The convergence behavior of the iteration ( B.5 ) highly depends on the form of the function F ( x ) and on the choice of the starting point x ₀ . The routine can be regarded as converged if $$\vert x_{t+1} - x_{t}\vert &lt;\epsilon$$ , where ε is the accuracy required.

If F ( x ) is not differentiable one can use the regula falsi or employ stochastic methods which are discussed in the second part of this book. The iteration of the method known as regula falsi is [ 6 , 7 ]

(B.6)

A more detailed discussion on methods to solve transcendental equations numerically can be found in any textbook on numerical methods, see for instance Refs. [ 8 , 9 ]. We shall also briefly introduce the case of a non-linear system of equations of the form ( B.1 ) where $$F(x) \in \mathbb{R}^{N}$$ and $$x \in \mathbb{R}^{N}$$ . In this case the iteration scheme is given by

(B.7)

where

(B.8)

is the Jacobi matrix of F ( x ). We can also make use of the methods discussed in Chap.  2 to calculate numerically the derivatives in Eqs. ( B.5 ) or ( B.8 ).

Appendix C: Numerical Solution of Linear Systems of Equations

We discuss briefly two of the most important methods to solve non-homogeneous systems of linear equations applying numerical methods. We consider a system of n equations of the form

(C.1)

which is usually transformed into a matrix equation,

(C.2)

The coefficients of the matrix A  = { a ij } as well as the vector b  = { b i } are assumed to be real valued and, furthermore, if

(C.3)

the problem ( C.2 ) is referred to as non-homogeneous (inhomogeneous). The solution of non-homogeneous linear systems of equations is one of the central problems in numerical analysis, since numerous numerical methods, such as the finite difference approach to a boundary value problem, see Chap.  8 , can be reduced to such a problem.

The solution of ( C.2 ) is well defined as long as the matrix A is non-singular, i.e. as long as

(C.4)

Then the unique solution of ( C.2 ) can be written as

(C.5)

However, the inversion of matrix A is very complex for n  ≥ 4 and one would prefer methods which are computationally more effective. Basically, one distinguishes between direct and iterative methods. Since a complete discussion of this huge topic would be too extensive, we will mainly focus on two methods.

In contrast to iterative procedures, direct procedures do not contain any methodological errors and can, therefore, be regarded as exact . However, these methods are often computationally very extensive and rounding errors are in many cases not negligible. As an example we will discuss the LU decomposition. On the other hand, many iterative methods are fast and rounding errors can be controlled easily. However, it is not guaranteed that an iterative procedure converges, even in cases where the system of equations is known to have unique solutions. Moreover, the result is an approximate solution. As an illustration for an iterative procedure we will discuss the Gauss-Seidel method.

C.1 The LU Decomposition

The LU decomposition [ 6 , 10 ] is essentially a numerical realization of Gaussian elimination which is based on a fundamental property of linear systems of equations ( C.2 ). This property states the system ( C.2 ) to remain unchanged when a linear combination of rows is added to one particular row. This property is then employed in order to obtain a matrix in triangular form. It was demonstrated by Doolittle and Crout [ 6 , 10 , 11 ] that the Gaussian elimination can be formulated as a decomposition of the matrix A into two matrices L and U :

(C.6)

Here, U is an upper triangular matrix and L is a lower triangular matrix. In particular, U is of the form

(C.7)

and L is of the form

(C.8)

The factorization ( C.6 ) is referred to as LU decomposition . The corresponding procedure can be easily identified by equating the elements in ( C.6 ). One can show that the following operations yield the desired result: For j  = 1, 2,  … ,  n one computes

(C.9)

(C.10)

with the requirement that u jj ≠ 0. Note that in this notation we used the convention that the contribution of the sum is equal to zero if the upper boundary is less than the lower boundary. We rewrite Eq. ( C.2 ) with the help of the LU decomposition ( C.6 )

(C.11)

and by defining y  =  Ux , we retrieve a system of equations for the variable y :

(C.12)

The particular form of L allows to solve the system ( C.12 ) immediately by forward substitution . We find the solution

(C.13)

and the equation

(C.14)

remains. It can solved by backward substitution :

(C.15)

We note that this method can also be employed to invert the matrix A . The strategy is based on the relation

(C.16)

where $$X = A^{-1}$$ is to be determined and I is the n -dimensional identity. Equation ( C.16 ) is equivalent to the following system of equations:

(C.17)

where the vectors x i are the rows of the unknown matrix X , i.e. X  = ( x ₁ ,  x ₂ ,  … ,  x n ). The n equations of the system ( C.17 ) can be solved with the help of the LU decomposition.

Furthermore, one can easily calculate the determinant of A using the LU decomposition. We note that

(C.18)

since L and U are triangular matrices, the determinants are equal to the product of the diagonal elements, which yields $$\det (L) = 1$$ . Hence we have

(C.19)

In conclusion we remark that there are many specialized methods which have been designed particularly for matrices of specific forms, such as tridiagonal matrices, symmetric matrices, block-matrices, …. Such matrices commonly appear in physics applications. For instance, we remember that the matrix we encountered in Sect.  8.​2 within the context of a finite difference approximation of boundary value problems, was tridiagonal. These specialized methods are usually the first choice if one has a matrix of such a specific form because they are much faster and more stable than methods developed for matrices of more general form. Since a full treatment of these methods is beyond the scope of this book, we refer the interested reader to books on numerical linear algebra, for instance Refs. [ 10 , 11 ].

C.2 The Gauss-Seidel Method

The Gauss-Seidel method is an iterative procedure to approximate the solution of non-homogeneous systems of linear equations [ 6 , 12 ]. The advantage of an iterative procedure, in contrast to a direct approach, is that its formulation is in general much simpler. However, one might have problems with the convergence of the method, even in cases where a solution exists and is unique. We note that the Gauss-Seidel method is of particular interest whenever one has to deal with sparse coefficient matrices. ² This requirement is not too restrictive since most of the matrices encountered in physical applications are indeed sparse. As an example we remember the matrices arising in the context of a finite difference approach to boundary value problems, Sect.  8.​2 .

Again, we use Eq. ( C.1 ) as a starting point for our discussion. It is a requirement of the Gauss-Seidel method that all diagonal elements of A are non-zero. We then solve each row of ( C.1 ) for x i . This creates the following hierarchy

(C.20)

or in general for i  = 1,  … ,  n

(C.21)

We note that Eq. ( C.21 ) can be rewritten as a matrix equation

(C.22)

where we defined the matrix C  = { c ij } via

(C.23)

and the vector b  = { b i } as

(C.24)

We recognize that Eq. ( C.21 ) can be transformed into an iterative form with the help of a trivial manipulation

(C.25)

or

(C.26)

where

(C.27)

Equation ( C.26 ) in combination with ( C.27 ) produces a sequence of vectors

(C.28)

where x ⁽⁰⁾ is referred to as the initialization vector or trial vector. One can prove that if this sequence converges, it approaches the exact solution x arbitrarily close:

(C.29)

We remark that if the terms $$x_{i}^{(t+1)}$$ on the right hand side of Eq. ( C.27 ) are replaced by $$x_{i}^{(t)}$$ the method is referred to as the Jacobi method.

To terminate the Gauss-Seidel method, we need an exit condition: One should terminate the iteration whenever:

The approximate solution x ( t ) obeys the required accuracy ε or $$\tilde{\epsilon }$$ , for instance

(C.30)

where ε is the absolute error, or

(C.31)

where $$\tilde{\epsilon }$$ is the relative error.

When a maximum number of iterations is reached. This condition may be interpreted as an emergency exit which ensures that the iteration terminates even if the process is not convergent or has still not converged.

Let us discuss one final, however, crucial point of this section: In many cases the convergence of the Gauss-Seidel method can be significantly improved by including a relaxation parameter ω to the iterative process. In this case the update routine ( C.26 ) takes on the form

(C.32)

If the relaxation parameter ω obeys ω  > 1 one speaks of over-relaxation , if ω  < 1 of under-relaxation and if ω  = 1 the regular Gauss-Seidel method is recovered. An appropriate choice of the relaxation parameter may fasten the convergence of the method significantly. The best result will certainly be obtained if the ideal value of ω , ω i were known. Unfortunately, it is impossible to determine ω i prior to the iteration in the general case. We remark the following properties:

The method ( C.32 ) is only convergent for 0 <  ω  ≤ 2.

If the matrix C is positive definite and 0 <  ω  < 2, the Gauss-Seidel method converges for any choice of x ⁽⁰⁾ ( Ostrowski-Reich theorem, [ 13 ]).

In many cases, 1 ≤  ω i  ≤ 2. We note that this inequality holds only under particular restrictions for the matrix C [see Eq. ( C.23 )]. However, we note without going into detail, that these restrictions are almost always fulfilled when one is confronted with applications in physics.

If C is positive definite and tridiagonal, the ideal value ω i can be calculated using

(C.33)

where $$\lambda$$ is the largest eigenvalue of C , Eq. ( C.23 ).

Since the calculation of $$\lambda$$ is in many cases quite complex, one could employ the following idea: It is possible to prove that

(C.34)

Hence, one may start with ω  = 1, perform t ₀ (20 <  t ₀  < 100) iterations and then approximate ω i with the help of Eq. ( C.33 ) and

(C.35)

The iteration is then continued with the approximated value of ω i until convergence is reached.

In conclusion we remark that numerous numerical libraries contain sophisticated routines to solve linear systems of equations. In many cases it is, thus, advisable to rely on such routines.

Appendix D: Fast Fourier Transform

Integral transforms are indispensable in modern mathematics and natural science because they can be employed to simplify complex mathematical problems. In this Appendix we will discuss the Fourier transform as one prominent representative of integral transforms in general. Loosely speaking, the Fourier transform is the unambiguous decomposition of a function f ( x ) into its frequency components. Its applications range from the harmonic analysis of periodic signals to the solution of differential equations and the description of wave phenomena in classical mechanics [ 2 , 4 ], electrodynamics [ 14 – 16 ], quantum mechanics [ 17 – 19 ], and many more. Here, we briefly discuss its numerical implementation, the fast Fourier transform (FFT) and its applications in Computational Physics.

We start by recalling the concept of Fourier series: It is asserted by Fourier ’s theorem that every square-integrable, d -periodic function f ( x ), $$f(x + d) = f(x)$$ , can be (uniquely) represented as ³

(D.1)

where the complex coefficients $$\hat{f}_{n} \in \mathbb{C}$$ are related to f ( x ) by the inverse transform

(D.2)

The representation ( D.1 ) of f ( x ) is referred to as the Fourier series of f ( x ) and the coefficient ( D.2 ) is the Fourier coefficient of order n . Equation ( D.1 ) is an unambiguous expansion of the function f ( x ) into contributions which oscillate with an integer multiple of the frequency 2 π ∕ d . There are numerous important properties, examples and applications of Fourier series for which we refer to the literature [ 21 – 24 ].

The concept of Fourier series can be generalized to the idea of the Fourier transform of a square integrable function f ( x ) by formally letting $$d \rightarrow \infty $$ [ 23 ]. The Fourier transform relates the function f ( x ) to its transform $$\hat{f} (k)$$ , $$k \in \mathbb{R}$$ , via ⁴

(D.3)

and the inverse transform is obtained as

(D.4)

The transform ( D.3 ) and its inverse ( D.4 ) can be used to considerably simplify mathematical problems. For instance, a linear differential equation for the function f ( x ) is mapped onto a linear algebraic equation for $$\hat{f} (k)$$ . The solution of the differential equation is then obtained by back-transforming the solution $$\hat{f} (k)$$ of the algebraic equation. Again, we refer to the literature for further applications and the various properties of the transforms ( D.3 ) and ( D.4 ). Instead, let us concentrate on the question of how to compute the Fourier transform ( D.2 ) numerically.

It appears to be reasonable to start with the concepts developed in Chap.  3 ⁵ For this purpose, we assume that the function f ( x ) is solely known on a grid of N equidistant grid-points x ℓ , $$\ell= 0,\ldots,N - 1$$ . In addition, we note that it is sufficient to limit our discussion to 2 π -periodic functions. Thus, we can choose our grid-points to be $$x_{\ell} = x_{0} +\ell h$$ where x ₀  = 0 and $$h = 2\pi /N$$ , so that $$x_{N-1} = 2\pi (1 - 1/N)$$ .

Approximating the integral ( D.2 ) with the help of the forward rectangular rule, Chap.  3 , yields

(D.5)

It follows from this equation that the coefficients $$\hat{f}_{n}$$ are periodic in n with period N due to the finite number of grid-points. Hence, the maximal number of distinct coefficients is equal to the number of grid-points. The inversion of Eq. ( D.5 ) follows directly from Eq. ( D.1 ) and reads ⁶

(D.6)

The transforms ( D.5 ) and ( D.6 ) are referred to as the discrete Fourier transform (DFT) and its inverse, respectively. We cast these relations into matrix form by defining vectors $$F = (\,f_{0},\ldots,f_{N-1})^{T}$$ and $$\hat{F } = (\,\hat{f}_{0},\ldots,\hat{f}_{N-1})^{T}$$ together with the matrix W of elements:

(D.7)

Here, $$\omega _{N} =\exp \left (\frac{2\pi i} {N}\right )$$ denotes the N -th root of unity. The transformation matrix W is known as the Fourier matrix or DFT matrix and it is easy to prove that its inverse W ⁻¹ has the elements

(D.8)

All this allows to rewrite Eqs. ( D.5 ) and ( D.6 ) in compact form:

(D.9)

Thus, we reduced the problem of numerically implementing the Fourier transform ( D.2 ) to the task of multiplying the N × N complex matrix W with the N -element vector F . This means that we have to perform N ² complex multiplications and N ( N − 1) complex additions. However, the symmetry W nm  =  W mn already suggests that there is further room for improvement. In fact, there are methods that do much better and these algorithms are known as fast Fourier transform (FFT) algorithms.

We limit our presentation to the version proposed by Cooley and Tukey [ 6 , 25 , 26 ] which is, with some variations, the most common algorithm. In its simplest form it is based on the observation that one can always split the Fourier transform ( D.5 ) into an even and an odd part

(D.10)

provided that N is even. ⁷ Since $$\omega _{N}^{2k} =\omega _{ N/2}^{n}$$ , we can interpret Eq. ( D.10 ) as the linear combination of two Fourier transforms of length N ∕2. Denoting the Fourier coefficients of the function values f 2 ℓ on even grid-points by $$\hat{A} _{n}$$ and of the values f 2 ℓ +1 on odd grid-points by $$\hat{B} _{n}$$ , we obtain for $$n = 1,\ldots,N/2$$

(D.11)

We now make use of the property that the Fourier coefficients are periodic, i.e. $$\hat{A}_{n+N/2} = \hat{A} _{n}$$ , $$\hat{B}_{n+N/2} = \hat{B} _{n}$$ , and that $$\omega _{N}^{n+N/2} = -\omega _{N}^{n}$$ . Thus, we can calculate the remaining coefficients $$\hat{f}_{n}$$ , $$n = N/2 + 1,\ldots,N$$ with the help of:

(D.12)

Because of Eqs. ( D.11 ) and ( D.12 ) the N Fourier coefficients can be computed as a linear combination of two Fourier transforms of size N ∕2. The recursive application of the very same scheme to $$\hat{A}_{n}$$ and $$\hat{B}_{n}$$ constitutes the core of the FFT algorithm in its simplest variation [ 6 ]. It is also the efficiency of this algorithm that makes the Fourier transform an attractive tool for numerical calculations [ 27 ]. In fact, there are several problems in this book where an algorithm based on FFT could have been evoked. Let us discuss two examples in more detail in order to illustrate this.

(i) In Chap.  9.​3 we could have solved the stationary inhomogeneous heat equation for its Fourier coefficients followed by the back-transform. ⁸ Denoting by $$\hat{T } _{n}$$ the Fourier coefficients of the temperature T ( x ) and by $$\hat{\varGamma }_{n}$$ the Fourier coefficients of the heat source/drain, we obtain from Eq. ( 9.​20 )

(D.13)

where $$\omega = 2\pi /L$$ . Performing the inverse FFT on Eq. ( D.13 ) and adding the homogeneous solution ( 9.​4 ) immediately gives the required temperature profile T ( x ). In a similar fashion, FFT could have been used for solving the partial differential equations discussed in Chap.  11 From the examples in this chapter, the time-dependent Schrödinger equation serves as our second application.

(ii) The Hamiltonian of a free point particle (for simplicity in one dimension) is diagonal in momentum space, $$H = P^{2}/2m$$ , with the momentum operator ( 10.​6 ). Given the position-space representation of the initial state ψ ( x ,  t ), we can then compute the time evolved wave packet ψ ( x ,  t + Δ t ) for arbitrary Δ t  > 0 according to Eq. ( 10.​17 ) as

(D.14)

where $$\hat{\psi }(p,t)$$ is the momentum space representation of the initial state ψ ( x ,  t ), i.e. its Fourier transform with $$k = p/\hslash $$ . Hence, the time evolution of the free wave packet is readily computed numerically with the help of the FFT and its inverse.

It is now certainly interesting to investigate whether or not a similar approach can be applied to solve Eq. ( 10.​1 ) in the presence of a potential V ( x ) which is diagonal in position space. Although this can be achieved by solving the full stationary eigenvalue problem ( 10.​9 ) followed by the application of the eigenvector expansion ( 10.​17 ), we present here a more efficient but approximate solution valid for small time steps Δ t . In order to see this, we transform Eq. ( D.14 ) into a slightly more compact form. Denoting by $$\mathcal{F}$$ the Fourier transform operator, $$\hat{\psi }(p) = \mathcal{F}\psi (x)$$ , we can write Eq. ( D.14 ) as

(D.15)

where $$U_{\varDelta t} =\exp \left (-i\varDelta tp^{2}/2\hslash m\right )$$ is the unitary time evolution operator for the time interval Δ t . ⁹ The correct result can not be obtained by multiplying Eq. ( D.15 ) with the position-space time evolution of the potential $$V _{\varDelta t} =\exp (-i\varDelta tV (x)/\hslash )$$ because the operators V and P do not commute. However, by applying the Baker-Campbell-Hausdorff formula ¹⁰ [ 17 , 19 , 28 ], we can approximate the time evolution ψ ( x ,  t ) →  ψ ( x ,  t + Δ t ) for a small time step Δ t by:

(D.16)

An even better approximation is obtained by the symmetrized form

(D.17)

This method, known as the split operator technique [ 29 ], is a frequently used method to numerically solve time dependent problems in quantum mechanics with the help of FFT.

Appendix E: Basics of Probability Theory

E.1 Classical Definition

It is the aim of this Appendix to summarize the most important definitions and results from basic probability theory as required within this book. For a more in depth presentation we refer to the literature [ 30 – 34 ].

The classical probability P ( A ) for an event A is defined by the number of favorable results n , divided by the number of possible results m ,

(E.1)

For two events A and B we can deduce the following rules ¹¹

(E.2a)

(E.2b)

(E.2c)

(E.2d)

(E.2e)

where P ( A  |  B ) is the probability for the event A under the constraint that event B is true. Moreover, if $$\overline{A}$$ is the complementary event ¹² to A we have

(E.3)

The statistical definition of the probability for an event A is given by:

(E.4)

E.2 Random Variables and Moments

A random variable is a functional which assigns to an event ω a real number x from the set of possible outcomes Ω : x  =  X ( ω ) [ 31 ]. ¹³ Roughly speaking it is a variable whose value is assigned to the observation of some random process. The mean value of a discrete random variable X is defined by

(E.5)

where P ω is the probability for the event ω . For instance, in case of a dice-throw X ( ω ) ≡  n  = 1, 2,  … , 6.

We restrict ourselves now to discrete random variables and, thus, x can only take on discrete values. Furthermore, we introduce the function of random variables Y  =  f ( X ) and define quite generally its mean value:

(E.6)

Note that

(E.7)

Moments of order k of a random variable X are defined by

(E.8)

and central moments are introduced via the relation

(E.9)

Of particular interest is the second central moment, the variance :

(E.10)

Finally, the standard deviation $$\sigma$$ is defined as the square root of the variance:

(E.11)

We study now a discrete set of observations x i where i  = 1,  … ,  N . Then the sample mean value is given by

(E.12)

and the error (standard deviation) of $$\overline{x}\,$$ ( standard error ) can be determined from:

(E.13)

We assumed here the x i to be uncorrelated with the consequence that $$\text{cov}\left (x_{i},x_{j}\right ) = \text{var}\left (x_{i}\right )\delta _{ij}$$ [defined in Eq. ( E.16 )]. Therefore,

(E.14)

where $$\sigma$$ is the standard deviation of the observations as defined above.

In the case of multiple random variables we can proceed as above. For instance, the expectation value of a function of two random variables is given by

(E.15)

and the covariance between two random variables:

(E.16)

The value of the covariance together with its sign determines important properties of the random variables X and Y in their relation to each other:

(E.17)

Random variables whose covariance is zero are called uncorrelated . [This property was used in the derivation of Eq. ( E.13 ).] To give an example, Fig.  E.1 compares schematically uncorrelated and positively correlated random variables X and Y .

Fig. E.1

Uncorrelated ( left panel ) and positively correlated ( right panel ) variables X and Y

E.3 Binomial Distribution and Limit Theorems

The binomial distribution is given by

(E.18)

where $$\binom{n}{k}$$ is the binomial coefficient

(E.19)

For large values of n Stirling ’s approximation can be applied to calculate an estimate of n ! :

(E.20)

Furthermore, it is easy to prove that the mean value and the variance of the binomial distribution are given by

(E.21)

(E.22)

The de Moivre-Laplace theorem states that for var( k ) ≫ 1

(E.23)

where $$k_{0} = \left \langle k\right \rangle$$ and $$\sigma = \sqrt{\text{var} \left (k\right )}$$ . We can also deduce that

(E.24)

for $$n \rightarrow \infty $$ . From this, Bernoulli ’s law of large numbers follows

(E.25)

E.4 Poisson Distribution and Counting Experiments

If the mean expectation value μ is independent of the number of experiments n , i.e. np  =  μ  ≡ const, it follows from Eq. ( E.18 ) that

(E.26)

The distribution P ( k  |  μ ) is called Poisson distribution. We obtain for the Poisson distribution:

(E.27)

(E.28)

It is important to note that counting experiments, as for instance radioactive decay, follow the Poisson statistics. A typical counting experiment observes within the time interval t (in average) μ events. This time interval is now divided into n sub-intervals with $$\varDelta t = t/n$$ . If the counting events can be assumed to be independent, the process follows a binomial distribution and we have μ  =  np . This is equivalent to $$p =\mu /n$$ . We return to the case of radioactive decay: We count μ signals within one minute which are uniformly distributed over the time interval. The experiment is now reduced to a time interval of one second and the probability of detecting a signal consequently reduces to μ ∕60. For p  ≪ 1 but np ​​​ ≫̸ 1 the binomial distribution P ( k  |  n ,  p ) can be approximated by P ( k  |  μ ) and we can use for large values of μ

(E.29)

with

(E.30)

In most experimentally relevant cases is μ unknown and is approximated by:

(E.31)

E.5 Continuous Variables

We define the cumulative distribution function (cdf) [ 31 , 32 ], F ( x ), of a continuous variable x by ¹⁴

(E.32)

where $$\mathcal{B}$$ is a generalized condition ( condition complex ). Moreover, we define the probability density function (pdf), p ( x ) by

(E.33)

It follows that

(E.34)

Hence,

(E.35)

Note that the pdf is normalized

(E.36)

and non-negative

(E.37)

E.6 Bayes ’ Theorem

We regard a set of discrete events A i under the generalized condition $$\mathcal{B}$$ . Then we have the normalization condition

(E.38)

and the marginalization rule

(E.39)

Bayes ’ theorem [ 33 , 35 ] for discrete variables follows from Eq. ( E.2e ) since P ( A ∧ B ) =  P ( B ∧ A ):

(E.40)

In case of continuous variables the above equations modify accordingly. The marginalization and Bayes ’ theorem for pdfs are then given by

(E.41)

and

(E.42)

E.7 Normal Distribution

The normal distribution ( Gauss distribution) is defined by the pdf:

(E.43)

The corresponding cdf

(E.44)

follows. Here Φ ( x ) is given by

(E.45)

and erf( x ) is the error function [ 36 , 37 ]:

(E.46)

Furthermore, we obtain

(E.47)

(E.48)

E.8 Central Limit Theorem

Let S denote a random variable defined by

(E.49)

where the X i are independent and identically distributed random numbers with mean μ and variance $$\sigma ^{2}$$ and

(E.50)

Then,

(E.51)

with

(E.52)

and

(E.53)

for large values of N . The theorem of de Moivre-Laplace is a special case of the central limit theorem, with the result that the X i are binomial distributed.

E.9 Characteristic Function

The characteristic function G ( k ) of a stochastic variable X is defined by [ 31 , 32 ]

(E.54)

where I denotes the range of the pdf p ( x ). It follows that

(E.55)

Expanding Eq. ( E.54 ) in a Taylor series with respect to k yields

(E.56)

Hence, the characteristic function is a moment generating function .

E.10 The Correlation Coefficient

We shall briefly define and discuss the correlation coefficient. Two random variables X and Y form a random vector Z  = ( X ,  Y ) which follows the pdf p ( Z ) =  p ( X ,  Y ) with the normalization

(E.57)

The correlation coefficient r is now defined as

(E.58)

where $$\text{cov}\left (X,Y \right )$$ is the covariance ( E.16 ) of X and Y while $$\text{var}\left (\cdot \right )$$ denotes the variance ( E.10 ) of the respective argument. It follows from the Cauchy-Schwarz inequality that 0 ≤  r ²  ≤ 1 and, therefore, − 1 ≤  r  ≤ 1. ¹⁵

The random variables X and Y are said to be the stronger correlated the bigger r ² becomes because for statistically independent (uncorrelated) variables we have p ( x ,  y ) =  q ₁ ( x ) q ₂ ( y ) with the consequence that $$\text{cov}\left (X,Y \right ) = 0$$ and, thus, r  = 0.

The definition of the correlation coefficient is commonly motivated by the problem of linear regression: Suppose we have a set of data points Y associated with data points X . We would like to find a linear function $$f(X) = a + bX$$ which approximates the data points Y as good as possible. The problem may be stated as

(E.60)

where a and b are real constants. This corresponds to Gauss ’s method of minimizing the square of errors. We have

(E.61)

and

(E.62)

Equations ( E.61 ) and ( E.62 ) result in:

(E.63)

(E.64)

Both are easily solved for a and b and one obtains

(E.65)

where

(E.66)

Thus, the linear function f ( X ) which approximates the data points Y optimally is given by

(E.67)

and it follows immediately for the squared error:

(E.68)

Hence, the best result is achieved for r  = ±1 in which case the association of the data points Y with the data points X is really linear while the worst result is found when r  = 0 (no association what so ever).

E.11 Stable Distributions

A stable distribution is a distribution which reproduces itself [ 32 ]. In particular, consider two random variables X ₁ and X ₂ which are independent copies of the random variable X following the distribution p X . ¹⁶

The pdf p X is referred to as a stable distribution if for arbitrary constants a and b the random variable aX ₁ + bX ₂ has the same distribution as the random variable cX + d for some positive c and some $$d \in \mathbb{R}$$ .

For this case one can write down the characteristic function analytically. We will give a special case, the so called symmetric Lévy distributions [ 38 ]:

(E.69)

Here $$\sigma &gt; 0$$ and 0 <  α  ≤ 2. The pdf of such a distribution shows the asymptotic behavior

(E.70)

The normal distribution follows from Eq. ( E.69 ) for α  = 2. Moreover, we observe from Eq. ( E.70 ) that the variance diverges for all α  < 2. However, the existence of the variance was the criterion for the validity of the central limit theorem formulated in Sect.  E.8 . We note that stable distributions reproduce themselves and are attractors for sums of independent identical distributed random variables. This is referred to as the generalized central limit theorem .

We remark, in conclusion, that for α  = 1 the Cauchy distribution results from Eq. ( E.69 ), and note that stable distributions are also referred to as Lévy α - stable distributions [ 32 ].

Appendix F: Phase Transitions

F.1 Some Basics

In many systems transitions between different phases can be observed if an external parameter, such as the temperature or the particle density, changes. Familiar examples are the liquid-gaseous phase transition or the ferromagnetic-paramagnetic transition. The two phases exhibit different properties and often develop a different physical structure, like in disorder-to-order transitions. This suggests the introduction of an order parameter $$\varphi$$ which is zero in one phase and takes on some finite value $$\varphi \neq 0$$ in the other one. ¹⁷ For instance, in the case of paramagnetic-ferromagnetic transitions the magnetization plays the role of the order parameter [ 43 ].

In order to classify phase transitions we briefly repeat some basics from statistical mechanics [ 39 – 42 , 44 , 45 ]. In a canonical ensemble the probability to find the system in micro-state r (as a function of the external parameters temperature T , volume V and number of particles N ) is proportional to the Boltzmann -factor

(F.1)

Here, $$\beta = 1/(k_{\mathrm{B}}T)$$ , where k B is the Boltzmann constant, T is the temperature, and E r is the energy of micro-state r . The canonical partition function Z ( T ,  V ,  N ),

(F.2)

ensures the normalization of P r ( T ,  V ,  N ) and determines the free energy F ( T ,  V ,  N ) according to

(F.3)

The Ehrenfest classification [ 46 ] of phase transitions is based on the behavior of F near the transition point: If F is a continuous function of its variables at the transition point and its first derivative with respect to some thermodynamic variable is discontinuous we call it a first order phase transition . For instance, transitions from the liquid to the gaseous phase are classified as first order phase transitions because the density, which is proportional to the first derivative of the free energy with respect to the chemical potential, changes discontinuously at the boiling temperature T  =  T B . We remark the following characteristics of first order phase transitions:

1.

The transition involves a latent heat Δ Q : The system absorbs or releases energy. A familiar example is the latent heat of fusion in the case of melting or freezing.

2.

Both phases can coexist at the transition point.

3.

A metastable phase can be observed.

In a second order phase transition the first derivative of the free energy F with respect to some thermodynamic variable is continuous but the second derivative of F exhibits a discontinuity. For instance, in a ferromagnetic phase transition the magnetization (first derivative of F with respect to the external magnetic field B ) changes continuously while the magnetic susceptibility χ (the second derivative of F with respect to B ) is discontinuous at the Curie temperature T c [ 43 ].

The modern classification is based on the behavior of the order parameter near the critical point. The order parameter changes discontinuously for first order phase transitions while it changes continuously for second and higher order phase transitions. Second order transitions are typically related to spontaneous symmetry breaking, as for instance in the paramagnetic-ferromagnetic transition. Based on this observation, Landau developed a general description of second order phase transitions which we briefly discuss in the following section.

F.2 Landau Theory

We regard a second order phase transition characterized by the scalar order parameter $$\varphi$$ [ 47 ]. Since $$\left \langle \varphi \right \rangle$$ changes continuously at T  =  T c , it is convenient to define $$\varphi$$ in such a way that $$\left \langle \varphi \right \rangle \vert _{T\geq T_{c}} = 0$$ while $$\left \langle \varphi \right \rangle \vert _{T&lt;T_{c}}\neq 0$$ .

For the free energy $$F(T,h,\varphi )$$ , one chooses

(F.4)

where a and b are some material constants and h denotes the external field. This ansatz is motivated by the theory of the paramagnetic-ferromagnetic phase transition [ 43 ]. Thus, in equilibrium we have

(F.5)

which results in

(F.6)

For h  = 0 and T  <  T c we obtain

(F.7)

where $$\gamma = 1/2$$ is called the critical exponent . For T  ≥  T c we have $$\left \langle \varphi _{0}\right \rangle = 0$$ . We now regard a weak external field h . The order parameter will change

(F.8)

Again, we obtain for equilibrium:

(F.9)

Neglecting contributions of order $$\mathcal{O}(\delta \varphi ^{2})$$ yields for the susceptibility

(F.10)

where $$\delta = -1$$ is a second critical exponent. This is the Curie-Weiss law [ 43 ]. Finally for T  =  T c we obtain from Eq. ( F.6 )

(F.11)

with the third critical exponent ε . The Landau theory is a mean-field approximation since local fluctuations of the order parameter are neglected. ¹⁸ Although the critical exponents obtained with Landau ’s approach deviate from experimental values, the theory is qualitatively correct. We remark that the critical exponents are universal (a property referred to as universality [ 40 ] ) as they depend only on the dimensionality and the symmetry of the interaction.

Appendix G: Fractional Integrals and Derivatives in 1D

This section introduces briefly the common definitions and notations associated with fractional calculus in one dimension [ 49 ].

The Riemann-Liouville fractional integrals of order $$\alpha \in \mathbb{C}$$ $$[\mathfrak{R}(\alpha ) &gt; 0]$$ , $$I_{a+}^{\alpha }f(x)$$ and $$I_{b-}^{\alpha }f(x)$$ on a finite interval [ a ,  b ] on the real axis $$\mathbb{R}$$ are given by

(G.1a)

(G.1b)

where Γ ( x ) denotes the Gamma function [ 36 , 37 ], $$\mathfrak{R}(\alpha )$$ is the real part of α , and f ( x ) is a sufficiently well behaved continuous, differentiable function for which the integrals in ( G.1 ) exist. The corresponding Riemann-Liouville fractional derivatives $$D_{a+}^{\alpha }f(x)$$ and $$D_{b-}^{\alpha }f(x)$$ of order $$\alpha \in \mathbb{C}$$ $$[\mathfrak{R}(\alpha ) \geq 0]$$ are defined by

(G.2a)

and

(G.2b)

with $$n = [\mathfrak{R}(\alpha )] + 1$$ . Here $$[\mathfrak{R}(\alpha )]$$ denotes the integer part of $$\mathfrak{R}(\alpha )$$ . For $$a \rightarrow -\infty $$ and $$b \rightarrow +\infty $$ the Riemann-Liouville fractional integrals and derivatives are referred to as Weyl fractional integrals and derivatives. In what follows, they will be denoted by $$I_{\pm }^{\alpha }$$ and $$D_{\pm }^{\alpha }$$ , respectively.

If $$\alpha \in \mathbb{C}\ [\mathfrak{R}(\alpha ) \geq 0]$$ and $$[a,b] \in \mathbb{R}$$ is a finite interval, then the left- and right-sided Caputo fractional derivatives $$^{C}D_{a+}^{\alpha }f(x)$$ and $$^{C}D_{b-}^{\alpha }f(x)$$ are defined by

(G.3a)

and

(G.3b)

with

(G.3c)

This is, however, equivalent to

(G.4a)

and

(G.4b)

The symmetric fractional integrals $$I_{\vert x\vert }^{\alpha }$$ and derivatives $$\mathcal{D}_{\vert x\vert }^{\alpha }$$ are referred to as Riesz fractional integrals or derivatives and are of the form

(G.5)

for α  ∈ (0, 1) and

(G.6)

Appendix H: Least Squares Fit

H.1 Motivation

In numerous physics applications a set of corresponding data points ( x k ,  y k ) was measured or calculated and a set of certain parameters { α j } characterizing a function f ( x k , { α j }) is to be determined in such a way that

(H.1)

This is referred to as a least squares fit problem [ 6 , 7 ]. Here, c k  ≥ 0 are weights, which indicate the relevance of a certain data point ( x k ,  y k ) for the fitting routine, and f ( x , { α j }) is referred to as the model function . Besides numerous applications within the context of experimentally obtained data points, we already came across such a problem in our discussion of data analysis in Chap.  19 Here it was of interest to determine the experimental auto-correlation time by fitting an exponential function to the measured auto-correlation coefficient A ( k ), discussed in Sect.  19.​3 Hence, we note that in many applications the parameters { α j } can be associated with a physical property of interest.

We distinguish between two different cases: (i) the function f ( x k , { α j }) is a linear function of the parameters { α j } and (ii) the function f ( x k , { α j }) is not linear in its parameters { α j }. It should be emphasized that in both cases the function does not need to be linear in x k . This section will discuss methods for linear as well as non-linear least squares fits. However, before proceeding some comments on the data points { y k } seem to be required.

Suppose the points ( x k ,  y k ) stem from a measurement which has been repeated N -times. In this case for every value x k we have N different values { y   k j } and we may use the arithmetic mean

(H.2)

instead of y k in expression ( H.1 ). We may also calculate the variance $$\text{var}\left (y_{k}\right )$$ via ¹⁹

(H.3)

If we assume that the data points y   k j follow a normal distribution with mean $$\left \langle y_{k}\right \rangle$$ and variance $$\text{var}\left (y_{k}\right )$$ we may proceed in the following way: The weights c k are chosen as

(H.4)

The resulting fit parameters { α j } are then regarded as mean values of parameters where the variances $$\text{var}\left (\alpha _{i}\right )$$ as well as the covariances $$\text{cov}\left (\alpha _{i},\alpha _{j}\right )$$ can be obtained from the matrix

(H.5)

via inversion, i.e.

(H.6)

and

(H.7)

The matrix C is commonly referred to as covariance matrix .

H.2 Linear Least Squares Fit

In this particular case the model function f ( x k , { α j }) is defined as

(H.8)

where $$\varphi _{j}(x_{k})$$ are linear independent basis functions, which do not have to be linear in x k . The particular case of a linear regression , discussed in Sect.  E.10 , is included. Equation ( H.8 ) specifies the model function f ( x k , { α j }) in ( H.1 ) and this yields

(H.9)

which is supposed to tend to a minimum. We calculate

(H.10)

and arrive at:

(H.11)

This equation can be reformulated as the linear equation

(H.12)

where the vectors α  = ( α ₁ ,  α ₂ ,  … ) T and β  = ( β ₁ ,  β ₂ ,  … ) T with

(H.13)

and the matrix M

(H.14)

have been introduced.

Equation ( H.12 ) can, for instance, be solved with the help of the methods discussed in Appendix . It is also particularly simple to determine the covariances because we have

(H.15)

and the covariances follow from Eqs. ( H.6 ) and ( H.7 ).

H.3 Nonlinear Least Squares Fit

Before we discuss the most general case of a completely arbitrary model function f ( x k , { α j }) we want to point out that it is in most cases of advantage to linearize the model function if at all possible. For instance, if the model function is an exponential function, it may be linearized by taking the data points $$\ln (y_{k})$$ instead of y k .

However, if this is not possible there are numerous alternatives to find a solution of the problem. For instance, the Gauss-Newton method can be employed if the model function f ( x k , { α j }) and its derivatives with respect to the parameters α j are known analytically. Another possibility is offered by the application of an deterministic optimization algorithm as they will be introduced in Appendix  H.3 . If even this method is not applicable, the methods of stochastic optimization, discussed in Chap.  20 , might be an obvious choice.

We describe now the Gauss-Newton method which is essentially a generalization of the Newton method presented in Appendix . The Gauss-Newton method is a method developed to minimize the expression ( H.1 ) iteratively. The derivatives

(H.16)

are assumed to be known analytically. This is an iterative algorithm and, thus, an iteration index is introduced and indicated by a superscript index n like in α j n . The algorithm is described by the following steps:

1.

Choose a set of initial values { α j ⁰ } for the iteration.

2.

Linearize the function f ( x l , { α j n }) and insert the result into Eq. ( H.1 ):

(H.17)

We introduce the following abbreviations for a more compact notation:

(H.18)

and

(H.19)

3.

We have to solve

(H.20)

for all parameters { α j }. Therefore, we introduce vectors α  = ( α ₁ ,  α ₂ ,  … ) T , β  = ( β ₁ ,  β ₂ ,  … ) T with

(H.21)

and the matrix M with elements:

(H.22)

This transforms Eq. ( H.20 ) into a linear system of equations

(H.23)

which is solved for $$\varDelta \alpha ^{n} =\alpha -\alpha ^{n}$$ . Please note that α n denotes the vector α after n iterations. The vector α n +1 for the next iteration step is guessed from:

(H.24)

4.

The iteration is terminated if for all parameters the desired accuracy was achieved. For instance, the condition $$\vert \alpha _{j}^{n+1} -\alpha _{j}^{n}\vert \leq \epsilon$$ can be used with ε a small parameter. A criterion for the relative error can be formulated in analogue.

Some comments concerning the covariance matrix are in order: It is more complicated in the nonlinear case because we also have to consider the second partial derivatives of the model function f ( x k , { α ℓ }). However, if these can for some reason be neglected we obtain, again, that N ij  =  M ij , as in Appendix, Sect.  H.2 . Another, more serious problem is found in the fact that the Gauss-Newton method suffers from severe instability problems. However, a possible remedy was formulated by D. Marquart  [ 54 ] who suggested to multiply the diagonal elements of the matrix M with a factor $$(1+\lambda )$$ where $$\lambda &gt; 0$$ . A detailed analysis shows that one can choose $$\lambda$$ sufficiently large and in such a way that the value of χ n ² decreases monotonically, i.e. χ n +1 ²  ≤  χ n ² for all iteration steps n . However, an increase of $$\lambda$$ decreases the convergence rate and more iterations are necessary until the required accuracy was obtained. It is therefore desirable to choose $$\lambda$$ values in such a way that the error decreases monotonically but that, at the same time, a convergence rate is maintained which is as large as possible. A possible strategy is to start with some given value of $$\lambda$$ and to reduce it after every iteration step by a constant rate. However, if at some point the error χ ² increases, i.e. χ n +1 ²  >  χ n ² , then $$\lambda$$ has again to be increased.

Appendix I: Deterministic Optimization

I.1 Introduction

We use the term deterministic optimization to distinguish these particular optimization methods from the stochastic optimization methods discussed in Chap.  20 . There are numerous different deterministic methods designed to find the minimum (or maximum) of a given function f ( x ), where x can be a vector. Roughly speaking, we can distinguish between methods which require the knowledge of the Hessian, ²⁰ methods which need gradients only, and methods which are based on function values only. For instance, if the gradient of a function is known analytically one may exploit Newton ’s method, as it was introduced in Appendix . Note that such an approach requires the Hessian of the function f ( x ).

We plan to discuss here in some detail two specific methods, namely the method of steepest descent and the method of conjugate gradients . Both methods require the knowledge of the gradient of the function, however, the gradient can also be approximated with the help of finite differences (see Chap.  2 ). A discussion of additional methods is beyond the scope of this book and the interested reader is referred to the available literature [ 55 ].

However, before discussing these two methods in more detail, let us briefly consider the quadratic problem which can be solved analytically. In this case the function f ( x ) can be written as

(I.1)

where $$x \in \mathbb{R}^{N}$$ , $$A \in \mathbb{R}^{N\times N}$$ , $$b \in \mathbb{R}^{N}$$ and $$c \in \mathbb{R}$$ where we restrict the discussion to real valued functions for reasons of simplicity. We demonstrate now that for symmetric and positive definite matrices A , i.e. A T  =  A and x T Ax  > 0 for all x ≠ 0, the minimum of f ( x ) is given by $$x = A^{-1}b$$ . The gradient of f ( x ) is readily evaluated and is given by ²¹ :

(I.2)

This immediately yields the desired result:

(I.3)

It follows that $$x = A^{-1}b$$ is a minimum because we assumed A to be positive definite. It is possible to solve the optimization problem even if A is not symmetric by inverting the symmetrized matrix $$\left (A + A^{T}\right )/2$$ . Finally, the linear equation ( I.3 ) can be solved with the methods discussed in Appendix .

I.2 Steepest Descent

The most simple gradient based method is the method of steepest descent [ 6 ]. It is based on the rather straight forward idea of moving in each iteration step into the opposite direction of the gradient, i.e. downhill . Hence, we may formulate it mathematically in the following way: Let x n be the current position of our search for the minimum. Then we choose

(I.4)

where the step-size in direction of the negative gradient, α n , has to be determined in an additional step. The step-size should be chosen in such a way that we reach the line minimum in direction ∇ f ( x n ):

(I.5)

Hence, we observe that for an optimal choice of α n the search directions are orthogonal. In practice α n is estimated with the help of a separate minimization technique, such as bisection. This technique has already been used in our discussion of the shooting methods in Chap.  10

We provide an example which is supposed to make the method more transparent and to help in the discussion of its caveats: We want to determine the global minimum of the function

(I.6)

Its gradient is easily evaluated

(I.7)

and

(I.8)

We define the algorithm steepest descent with the following steps:

1.

Choose some initial values x ₀ and y ₀ .

2.

Calculate the gradient ∇ f ( x n ,  y n ) in iteration step n .

3.

Determine α n in such a way that

(I.9)

which is equivalent to

(I.10)

This is achieved by a bisection technique similar to the one employed in Sect.  10.​3 ,

a.

Set α n a  = 0 and chose α n b arbitrary.

b.

Increase α n b until g ( α n a ) g ( α n b ) < 0.

c.

Define

(I.11)

and determine g ( α n c ).

d.

If g ( α n a ) g ( α n c ) < 0, set α n b  =  α n c and return to step c. Otherwise, set α n a  =  α n c and return to step c.

e.

The bisection is terminated if |  g ( α n a ) |  <  ε , with ε some required accuracy for the bisection part.

4.

Check whether $$\vert \,f(x_{n+1},y_{n+1}) - f(x_{n},y_{n})\vert \leq \eta$$ with η some required accuracy. Return to step 2 for the next iteration step if the algorithm is not converged.

The above algorithm was executed for the function f ( x ,  y ) given by Eq. ( I.6 ) for three different starting points, (0. 8, − 0. 75), (0. 8, 1. 05), and ( − 1. 05, 1. 05). The function f ( x ,  y ) as well as the iteration sequence towards the minimum for all three starting points is illustrated in Fig.  I.1 .

Fig. I.1

Iteration sequence of the method of steepest descent for three different starting points

We note the following properties of the method: First of all it is a rather slow method due to the orthogonality of subsequent search directions. Moreover, as we observe from Fig.  I.1 , we can only find the local minimum closest to the starting point and not the global minimum of the function f ( x ,  y ). The convergence rate is also highly affected by the choice of the initial position. However, it is a very simple method which works in spaces of arbitrary dimension.

I.3 Conjugate Gradients

The method of conjugate gradients [ 6 , 55 ] is based on the definition of N orthogonal search directions { ψ i } in an N dimensional space. In contrast to steepest descent it is designed in such a way that we take only one step in each search direction and the minimum is found after at most N steps, if the function f ( x ) is of the quadratic form ( I.1 ). In the more general case, however, it will take more steps but will, nevertheless, be much more efficient than the method of steepest descent. Let us formulate the method for a general function f ( x ).

We approximate the function f ( x ), with $$x \in \mathbb{R}^{N}$$ , in the vicinity of the reference point x n in the n -th iteration step up to second order and name the resulting function $$\hat{f}(x)$$ :

(I.12)

Here, A n denotes the Hessian ²² at position x n and b n is the negative gradient at x n . In particular, for a quadratic function f ( x ) the equality $$\hat{f} (x) = f(x)$$ holds. We now write the minimum $$\hat{x}$$ of f ( x ) as a linear combination of search directions { ψ i } with coefficients $$\lambda _{i}$$ and the initial point x ₀ :

(I.13)

Note that in the quadratic case ( I.1 ) this sum will be restricted to $$M = N - 1$$ . At each iteration instance we have the relation

(I.14)

together with the goal

(I.15)

Let us define now a couple of useful quantities. The deviation from the minimum at iteration step n + 1, δ n +1 , is given by

(I.16)

We define, furthermore, the residual

(I.17)

where we employed that

(I.18)

Finding the minimum of the quadratic approximation $$\hat{f}(x)$$ of f ( x ) around x n is equivalent to the condition

(I.19)

In particular, we have to find the product $$\lambda _{n}\psi _{n}$$ in such a way that $$r_{n+1} = 0$$ . Of course, we could invert the Hessian A n in order to obtain this result. However, this would be too expensive from a computational point of view. The idea is to apply the ideal search strategy for quadratic functions to $$\hat{f}_{n}(x)$$ in order to obtain x n +1 . Hence, the method of conjugate gradients executes packages of N steps, where each package solves the quadratic problem around x n , until the minimum of the original function f ( x ) has been found. Therefore, we have to generalize the relations ( I.14 ), ( I.16 ), and ( I.17 ) for iterations within step n .

We have, in particular, for every iteration step n

(I.20)

together with the definitions

(I.21)

where x n +1  ≡  x n N . Furthermore, we define the deviation

(I.22)

and the residual

(I.23)

In contrast to relation ( I.17 ), Eq. ( I.23 ) features the difference $$(x_{n}^{\ell+1} - x_{n})$$ rather than $$(x_{n+1} - x_{n})$$ . We insert the recurrence ( I.21 ) and obtain

(I.24)

Hence, in contrast to relation ( I.17 ) Eq. ( I.24 ) defines a recurrence relation. Again, we want to choose the search directions ψ n ℓ and the step length $$\lambda _{n}^{\ell}$$ in such a way that we find the minimum as quickly as possible. Suppose we already knew the search direction ψ n ℓ . The line minimum in this direction is then given by

(I.25)

and we have

(I.26)

Hence, the remaining unknown quantities in our algorithm are the search directions ψ n ℓ . So far, the only information we obtained is that the search direction ψ n ℓ is orthogonal to the residual $$r_{n}^{\ell+1}$$ , see Eq. ( I.25 ).

However, we also know that

(I.27)

and therefore

(I.28)

for arbitrary k . A sufficient condition to ensure the validity of relation ( I.28 ) is to impose A n -orthogonality :

(I.29)

We note that $$\left \langle \psi _{n}^{k}\,\right \vert \left.\psi _{n}^{\ell}\right \rangle _{A}$$ constitutes indeed a scalar product since A n is positive definite in the neighborhood of a minimum.

Let us briefly demonstrate that the choice ( I.29 ) fulfills Eq. ( I.28 ). First of all we note that we obtain from Eq. ( I.24 )

(I.30)

and, therefore, we derive the coefficients $$\lambda _{n}^{\ell}$$ from Eq. ( I.26 ) in the convenient form:

(I.31)

The condition of orthogonality ( I.29 ) is used to rewrite Eq. ( I.28 ) as

(I.32)

which together with Eq. ( I.31 ) proves the equality ( I.28 ). Hence, the strategy is clear: We choose an initial direction ψ n ⁰ and then construct the further directions in such a way that they fulfill A n -orthogonality ( I.29 ). Before discussing the construction of search directions in more detail we observe the following property:

(I.33)

This means that all search directions ψ n k for k  ≤  ℓ − 1 are orthogonal to the residual r n ℓ , or in other words, all residuals r n ℓ are orthogonal (in the classical sense) to all previous search directions.

We shall now briefly outline the resulting update algorithm for search directions: Let $$\{\varphi _{n}^{\ell}\}$$ be a set of linear independent vectors that span our search space for $$\hat{f}_{n}(x)$$ . ²³ We write the search direction ψ n k as

(I.34)

together with

(I.35)

The expansion coefficients β n ℓ k can be determined recursively by imposing A n -orthogonality for all ℓ  <  k :

(I.36)

and, therefore:

(I.37)

This procedure is known as the Gram-Schmidt conjugation [ 6 , 12 ].

Now, the question arises how one should choose the basis vectors $$\varphi _{n}^{\ell}$$ and whether or not it is advantageous to choose the $$\varphi _{n}^{\ell}$$ as a function of n . A particularly clever choice is to take the residuals, i.e.

(I.38)

In this case we have for ℓ  <  k

(I.39)

where we used recurrence ( I.24 ). We now calculate with the help of Eq. ( I.34 )

(I.40)

for ℓ  <  k due to the orthogonality of the search direction and the residuals, see Eq. ( I.33 ). Hence, we obtain for all ℓ  <  k

(I.41)

Hence, the name conjugated gradients .

We are now in a position to describe the algorithm for the method of conjugated gradients :

1.

Choose an initial position x ₀ .

2.

Determine the vector b n and the matrix A n for a given position x n .

3.

Perform the following N steps in order to calculate x n +1 :

a.

Set

(I.42)

as well as

(I.43)

b.

Calculate for $$k = 1,\ldots,N - 1$$ the residuals,

(I.44)

the new search directions

(I.45)

the step lengths

(I.46)

and, finally, the modified positions

(I.47)

4.

If $$\vert \,f(x_{n+1}) - f(x_{n})\vert &lt;\epsilon$$ , with ε some required accuracy, terminate the iteration, otherwise return to step 2. In case of a convex function f ( x ) terminate also after N steps.

Strictly speaking, this algorithm is only valid for convex functions because we note that one might get into trouble whenever a position is reached at which the Hessian is not positive definite. It is therefore desirable to exclude the Hessian from the algorithm. This can be achieved by an algorithm developed by Fletcher and Reeves [ 56 ]. Based on our previous discussion the generalization is rather obvious: If we do not want to use the Hessian explicitly, we have to determine the step length $$\lambda _{n}^{\ell}$$ by minimizing $$f(x_{n}^{\ell} +\lambda _{ n}^{\ell}\psi _{n}^{\ell})$$ for a given search direction ψ n ℓ numerically. The residuals are then taken to be the exact gradient of the function $$f(x_{n}^{\ell})$$ rather than of $$\hat{f}_{n}(x_{n}^{\ell})$$ . The next search direction $$\psi _{n}^{k+1}$$ is then determined via

(I.48)

Hence, we have the following algorithm ( Fletcher-Reeves algorithm ):

1.

Choose an initial position x ₀ .

2.

Perform the following N steps in order to calculate x n +1 :

a.

Set

(I.49)

b.

Calculate for $$k = 0,\ldots,N - 1$$ $$\lambda _{n}^{k}$$ by minimizing $$f(x_{n}^{k} +\lambda _{ n}^{k}\psi _{n}^{k})$$ , the new position $$x_{n}^{k+1} = x_{n}^{k} +\lambda _{ n}^{k}\psi _{n}^{k}$$ , and the new search direction via

(I.50)

3.

If $$\vert \,f(x_{n+1}) - f(x_{n})\vert &lt;\epsilon$$ , with ε some required accuracy, terminate the iteration, otherwise return to step 2.

Fig. I.2

Iteration sequence of the method of conjugated gradients for three different starting points

The resulting sequence of steps towards the minimum for the same function and initial conditions as were used for Fig.  I.1 is illustrated in Fig.  I.2 . In comparing Figs.  I.1 and  I.2 we note immediately that the search strategy developed for the method of conjugate gradients superbly outperforms the search strategy of the method of steepest descent. In particular, if the ratio between the gradient in x and y direction is large, a strategy of orthogonal search directions is disadvantageous. This particular case is illustrated in Fig.  I.3 for both, steepest descent and conjugate gradients. Here we investigate the convex function

(I.51)

together with an initial position ( x ₀ ,  y ₀ ) = (1. 9, 0. 4). The resulting sequence of points towards the minimum is illustrated in Fig.  I.3 . In the case of steepest descent the sequence approaches the minimum rather slowly since subsequent search directions have to be orthogonal to each other in the classical sense. The advantage of conjugate gradients is that A n -orthonormality accelerates the convergence towards the minimum. In this example we reach it within two steps and a required absolute accuracy of $$\eta = 10^{-7}$$ .

Fig. I.3

Comparison of the iteration sequence between the method of steepest descent and the method of conjugated gradients

As a final remark we note that also the method of conjugate gradients will only find the local minimum closest to the initial position. Hence, the outcome of the method highly depends on the choice of x ₀ . Moreover, the calculation of the gradients may be very tedious and time-consuming from a numerical point of view.

References

1.

Arnol’d, V.I.: Mathematical Methods of Classical Mechanics, 2nd edn. Graduate Texts in Mathematics, vol. 60. Springer, Berlin/Heidelberg (1989)

2.

Fetter, A.L., Walecka, J.D.: Theoretical Mechanics of Particles and Continua. Dover, New York (2004)MATH

3.

Scheck, F.: Mechanics, 5th edn. Springer, Berlin/Heidelberg (2010)CrossrefMATH

4.

Goldstein, H., Poole, C., Safko, J.: Classical Mechanics, 3rd edn. Addison-Wesley, Menlo Park (2013)MATH

5.

Fließbach, T.: Mechanik, 7th edn. Lehrbuch zur Theoretischen Physik I. Springer, Berlin/Heidelberg (2015)MATH

6.

Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P.: Numerical Recipes in C++, 2nd edn. Cambridge University Press, Cambridge (2002)MATH

7.

Ralston, A., Rabinowitz, P.: A First Course in Numerical Analysis, 2nd edn. Dover, New York (2001)MATH

8.

Jacques, I., Judd, C.: Numerical Analysis. Chapman and Hall, London (1987)CrossrefMATH

9.

Burden, R.L., Faires, J.D.: Numerical Analysis. PWS-Kent Publishing Comp., Boston (1993)MATH

10.

Stoer, J., Bulirsch, R.: Introduction to Numerical Analysis, 2nd edn. Springer, Berlin/Heidelberg (1993)CrossrefMATH

11.

Westlake, J.R.: A Handbook of Numerical Matrix Inversion and Solution of Linear Equations. Wiley, New York (1968)MATH

12.

Hazewinkel, M. (ed.): Encyclopaedia of Mathematics. Springer, Berlin/Heidelberg (1994)MATH

13.

Varga, R.S.: Matrix Iterative Analysis, 2nd edn. Springer Series in Computational Mathematics, vol. 27. Springer, Berlin/Heidelberg (2000)

14.

Jackson, J.D.: Classical Electrodynamics, 3rd edn. Wiley, New York (1998)MATH

15.

Greiner, W.: Classical Electrodynamics. Springer, Berlin/Heidelberg (1998)CrossrefMATH

16.

Griffiths, D.J.: Introduction to Electrodynamics, 4th edn. Addison-Wesley, Menlo Park (2013)

17.

Sakurai, J.J.: Modern Quantum Mechanics. Addison-Wesley, Menlo Park (1985)

18.

Sakurai, J.J.: Advanced Quantum Mechanics. Addison-Wesley, Menlo Park (1987)

19.

Ballentine, L.E.: Quantum Mechanics. World Scientific, Hackensack (1998)CrossrefMATH

20.

Courant, R., Hilbert, D.: Methods of Mathematical Physics, vol. 1. Wiley, New York (1989)CrossrefMATH

21.

Schücker, T.: Distributions, Fourier Transforms and Some of Their Applications to Physics. Lecture Notes in Physics, vol. 37. World Scientific, Hackensack (1991)

22.

Kammler, D.W.: A First Course in Fourier Analysis. Cambridge Univerity Press, Cambridge (2008)CrossrefMATH

23.

Hansen, E.W.: Fourier Transforms: Principles and Applications. Wiley, New York (2014)MATH

24.

Bernatz, R.: Fourier Series and Numerical Methods for Partial Differential Equations. Wiley, New York (2010)CrossrefMATH

25.

Cooley, J.W., Tukey, J.W.: An algorithm for the machine calculation of complex Fourier series. Math. Comput. 19 , 297–301 (1965). doi:10.1090/S0025-5718-1965-0178586-1 MathSciNetCrossrefMATH

26.

Nussbaumer, H.J.: Fast Fourier Transform and Convolution Algorithms. Springer Series in Information Sciences, vol. 2. Springer, Berlin/Heidelberg (1981)

27.

Frigo, M., Johnson, S.G.: FFTW, The Fastest Fourier Transform in the West,Vers. 3.3.4 (2015). http://​www.​fftw.​org

28.

Bakhturin, Y.A.: Campell-Hausdorff formula. In: Hazewinkel, M. (ed.) Encyclopaedia of Mathematics. Springer, Berlin/Heidelberg (1994)

29.

McLachlan, R.I., Quispel, G.R.W.: Splitting methods. Acta Numer. 11 , 341–434 (2002). doi:10.1017/S0962492902000053 MathSciNetCrossrefMATH

30.

Rotar, V.: Probability Theory. World Scientific, Singapore (1998)CrossrefMATH

31.

Papoulis, A., Pillai, S.: Probability, Random Variables and Stochastic Processes. McGraw Hill, New York (2001)

32.

Breuer, H.P., Petruccione, F.: Open Quantum Systems, chap. 1 Clarendon Press, Oxford (2010)

33.

von der Linden, W., Dose, V., von Toussaint, U.: Bayesian Probability Theory. Cambridge University Press, Cambridge (2014)CrossrefMATH

34.

Klenke, A.: Probability Theory. Universitext. Springer, Berlin/Heidelberg (2014)CrossrefMATH

35.

Lee, P.M.: Bayesian Statistics: An Introduction. Wiley, New York (2012)MATH

36.

Abramovitz, M., Stegun, I.A. (eds.): Handbook of Mathemathical Functions. Dover, New York (1965)

37.

Olver, F.W.J., Lozier, D.W., Boisvert, R.F., Clark, C.W.: NIST Handbook of Mathematical Functions. Cambridge University Press, Cambridge (2010)MATH

38.

Applebaum, D.: Lévy Processes and Stochastic Calculus. Cambridge Studies in Advanced Mathematics. Cambridge University Press, Cambridge (2006)MATH

39.

Yeomans, J.M.: Statistical Mechanics of Phase Transitions. Clarendon Press, Oxford (1992)

40.

Cardy, J.: Scaling and Renormalization in Statistical Physics. Cambridge Lecture Notes in Physics. Cambridge University Press, Cambridge (1996)CrossrefMATH

41.

Fließbach, T.: Statistische Physik. Lehrbuch zur Theoretischen Physik IV. Springer, Berlin/Heidelberg (2010)CrossrefMATH

42.

Pathria, R.K., Beale, P.D.: Statistical Mechanics, 3rd edn. Academic, San Diego (2011)MATH

43.

White, R.M.: Quantum Theory of Magnetism, 3rd edn. Springer Series in Solid-State Sciences. Springer, Berlin/Heidelberg (2007)Crossref

44.

Mandl, F.: Statistical Physics, 2nd edn. Wiley, New York (1988)

45.

Keener, R.W.: Theoretical Statistics. Springer, Berlin/Heidelberg (2010)CrossrefMATH

46.

Jaeger, G.: The Ehrenfest classification of phase transitions: introduction and evolution. Arch. Hist. Exact Sci. 51–81 (1998). doi:10.1007/s004070050021

47.

Landau, L.D., Lifshitz, E.M.: Course of Theoretical Physics, vol. 5: Statistical Physics. Pergamon Press, London (1963)

48.

Ter Haar, D.: Collected Papers of L. D. Landau, p. 546. Pergamon Press, London (1965)

49.

Kilbas, A.A., Srivastava, H.M., Trujillo, J.J.: Theory and Applications of Fractal Differential Equations. Elsevier, Amsterdam (2006)MATH

50.

Iversen, G.P., Gergen, I.: Statistics. Springer Undergraduate Textbooks in Statistics. Springer, Berlin/Heidelberg (1997)Crossref

51.

Wilcox, R.R.: Basic Statistics. Oxford University Press, New York (2009)MATH

52.

Monahan, J.F.: Numerical Methods of Statistics. Cambridge Series in Statistical and Probabilistic Mathematics. Cambridge University Press, Cambridge (2011)CrossrefMATH

53.

Wood, S.: Core Statistics. Institute of Mathematical Statistics Textbooks. Cambridge University Press, Cambridge (2015)CrossrefMATH

54.

Marquart, D.: An algorithm for least-squares estimation of nonlinear parameters. J. Soc. Ind. Appl. Math. 11 , 431–441 (1963). doi:10.1137/0111030 MathSciNetCrossref

55.

Avriel, M.: Nonlinear Programming: Analysis and Methods. Dover, New York (2003)MATH

56.

Fletcher, R., Reeves, C.M.: Function minimization by conjugate gradients. Comput. J. 7 , 149–154 (1964). doi:10.1093/comjnl/7.2.149 MathSciNetCrossrefMATH

Index

A

Absolute error

SeeError

ADAMS-BASHFORD method

SeeIntegrator

Algorithm

Anomalous diffusion

Antiferromagnetism

Auto-correlation function

Auto-correlation time

exponential

integrated

Auto-correlations

Autonomous system

B

Backward difference

BAKER-CAMPBELL-HAUSDORFF formula

Barometric formula

BAYES’ theorem

BERNOULLI’s law of large numbers

Binomial distribution

SeeProbability density function

BOLTZMANN distribution

SeeProbability density function

BOLTZMANN equation

collision integral

particle density

Boundary conditions

decoupled

DIRICHLET conditions

homogeneous

NEUMANN conditions

of first kind

of second kind

of third kind

periodic

STURM conditions

Brownian motion

BUTCHER tableau

SeeIntegrator

C

Calculus

mean value theorem

Canonical partition function

CAPUTO fractional derivative

CAUCHY distribution

SeeProbability density function

Cdf

SeeCumulative distribution function

Central difference

Central limit theorem

generalized

Chaos

attractor

characteristic length

deterministic

periodic orbit

POINCARÉ map

POINCARÉ section

stability

theory

CHAPMAN - KOLMOGOROV equation

χ ² distribution

Closed integration rule

Cluster algorithm

Computational cost

Configuration space

Conjugate gradients

SeeDeterministic optimization

COOLEY and TUKEY algorithm

COURANT-FRIEDRICHS-LEWY condition

Covariance

CRANK-NICOLSON method

SeeIntegrator

Cumulative distribution function

D

DE MOIVRE-LAPLACE theorem

Derivative

finite difference

backward

central

forward

operator technique

shift operator

three point approximation

fractional

CAPUTO fractional derivative

RIEMANN-LIOUVILLE fractional derivative

RIESZ fractional derivative

WEYL fractional derivative

partial

Detailed balance

Deterministic optimization

conjugate gradients

A n -orthogonality

FLETCHER-REEVES algorithm

GRAM-SCHMIDT conjugation

line minimum

residual

Hessian matrix

steepest descent

convergence rate

line minimum

DFT

SeeFOURIER

Differential equation

harmonic oscillator

LEGENDRE

Diffusion equation

diffusion coefficient

particle density

DIRAC δ -distribution

Double pendulum

chaotic

generalized momenta

HAMILTON equations of motion

HAMILTON function

kinetic energy

LAGRANGE function

POINCARÉ plot

potential energy

RUNGE-KUTTA algorithm

trajectories

E

e - RK -4

Eccentricity

Error

absolute

algorithmic

input

measurement

methodological

output

relative

roundoff

standard

truncation

Estimator

energy expectation value

error

internal energy

EULER methods 57–

Exchange interaction

F

FERRARI’s method

Ferromagnetism

FFT

SeeFOURIER

FIBONACCI sequence

Finite difference

backward

central

forward

Finite volume effects

FLETCHER-REEVES algorithm

SeeDeterministic optimization

Floating-point form

Fluctuation quantities

FOKKER - PLANCK equation

Forward difference

FOURIER

coefficient

DFT

FFT

matrix

series

transform

convolution integral

discrete

fast

inverse

operator

Fractal random walk

diffusion equation

fractal time random walk

Fractional integral

RIEMANN-LIOUVILLE fractional integral

RIESZ fractional integral

WEYL fractional integral

G

GAUSS-HERMITE quadrature

GAUSS-LEGENDRE quadrature

GAUSS-SEIDL method

GAUSS distribution

SeeProbability density function

GAUSS peak

GAUSS-NEWTON method

Gaussian process

Generalized diffusion model

characteristic waiting time

jump length pdf

jump pdf

length variance

waiting time pdf

Genetic algorithm

SeeStochastic optimization

GIBBS sampling

SeeMARKOV-chain Monte-Carlo sampling

Grid-point

distance between

equally spaced

variable spaced

H

HAMILTON

equations of motion

function

HAMILTON operator

SeeOperator

Heat capacity

Heat equation

heat source/drain

homogeneous

inhomogeneous

stationary, one-dimensional

thermal diffusivity

time-dependent heat equation

SeePartial differential equation

HEISENBERG model

Hessian matrix

SeeDeterministic optimization

Hill climbing

SeeStochastic optimization

Histogram technique

Hit and miss integration

I

Ill-conditioned

problems

Implicit midpoint rule

Importance sampling

Induced instability

Integrable system

Integration

SeeQuadrature

Integrator

ADAMS-BASHFORD method

backward EULER method

BUTCHER tableau

CRANK-NICOLSON method

algorithmic form

explicit EULER method

algorithmic form

explicit midpoint rule

algorithmic form

forward EULER method

implicit EULER method

algorithmic form

implicit midpoint rule

leap-frog method

linear multi-step methods

predictor - corrector method

RUNGE-KUTTA method

e - RK - 4

e - RK - 4 , algorithmic form

explicit, algorithmic form

simple integrators

STÖRMER-VERLET method

symplectic integrators

EULER method

flow of the system

RUNGE - KUTTA method

velocity VERLET algorithm

Inverse transformation method

ISING model

antiferromagnetism

exchange interaction

expectation value

energy

energy per particle

ferromagnetism

HAMILTON function

HAMILTON operator

one-dimensional chain

$$ {\mathbb{Z}}_{2}$$ symmetry

heat capacity

magnetic susceptibility

magnetization

mean field approximation

molecular field

nearest neighbor interaction

numerics

auto-correlation

cold start

cooling strategy

error on expectation values

hot start

initial configuration

lattice geometry

measurement

size effect

thermalization

thermalization length

paramagnetism

phase transition

spin correlation function

thermodynamic limit

transfer matrix

eigenvalue

two-dimensional solution

J

Jackknife averages

JACOBI determinant

JACOBI matrix

JACOBI method

K

KEPLER problem

absolute error

conservation

of energy

differential equation

explicit EULER

HAMILTON equations of motion

HAMILTON function

implicit EULER

LAGRANGE equation

LAGRANGE function 341–

pericenter velocity

perihelion

rotational invariance

symplectic EULER

translational invariance

L

L ² -norm

LAGRANGE polynomial

LANDAU theory

LANDÉ factor

LANGEVIN equation

SeeStochastic differential equation

LAPLACE equation

SeePartial differential equation

Law of large numbers

Leap-frog

SeeIntegrator and/or Molecular dynamics

Least squares fit

linear

model/test function

nonlinear

GAUSS-NEWTON method

LEGENDRE polynomial

orthonormality condition

RODRIGUES formula

LENNARD-JONES potential

LÉVY flight

diffusion equation

fat-tailed jump length pdf

jump length pdf

LÉVY process

Linear equations

GAUSS-SEIDL method

relaxation parameter

inhomogeneous

JACOBI method

LU decomposition

non-homogeneous

sparse matrix

tridiagonal matrix

Linear multi-step methods

Loop algorithm

LU decomposition

M

Machine-number

Magnetic susceptibility

Magnetization

Marginalization rule

MARKOV process

CHAPMAN-KOLMOGOROV equation

detailed balance

equilibrium distribution function

global balance

HAMILTON’s equations of motion

hierarchy of pdfs

MARKOV property

master equation

POISSON process

transition probability

waiting time

precursor state

time-homogeneous

transition probability

transition rate

WIENER process

transition probability

MARKOV-chain

absorbing state

aperiodic state

CHAPMAN-KOLMOGOROV equation

closed set of states

continuous state space

continuous time

detailed balance

equilibrium distribution

ergodic state

irreducible

irreducible class

MARKOV property

null recurrent state

periodic state

positive recurrent state

recurrent state

reversible

stationary distribution

transient state

transition matrix

transition probability

MARKOV-chain Monte-Carlo sampling

GIBBS sampling

METROPOLIS algorithm

acceptance probability

asymmetric proposal probability

correlations

initialization

thermalization

METROPOLIS-HASTINGS algorithm

slice sampling

MAXWELL - BOLTZMANN distribution

Mean-value integration

SeeQuadrature

Methodological error

SeeError

METROPOLIS-HASTINGS algorithm

SeeMARKOV-chain Monte-Carlo sampling

METROPOLIS algorithm

SeeMARKOV-chain Monte-Carlo sampling

Midpoint rules

Molecular dynamics

barometric formula

boundary conditions

constant temperature

external potential

finite volume effects

forces

initial conditions

leap-frog method

SeeIntegrator

LENNARD-JONES potential

natural units

NEWTON equations of motion

STÖRMER - VERLET method

system temperature

thermal equilibrium

time-reversal symmetry

total kinetic energy

total velocity shift

two-particle interaction

velocity VERLET algorithm

Monte-Carlo integration

SeeQuadrature

N

NÉEL temperature

NEWTON method

NEWTON-COTES rules

Normal distribution

SeeProbability density function

Normalization condition

O

Open integration rule

Operator

expectation value

HAMILTON operator

Hermitian

kinetic energy

LAPLACE operator

momentum

position

potential energy

time-evolution operator

Ordinary differential equation

collocation point

eigenvalue problem

explicit

homogeneous

homogeneous boundary value problem

initial value problem

integrators

SeeIntegrator

linear boundary value problem

ORNSTEIN-UHLENBECK process

master equation

P

Paramagnetism

Partial differential equation

diffusion equation

SeeDiffusion equation

elliptic

hyperbolic

LAPLACE equation

charge density

parabolic

POISSON equation

charge density

convergence condition

electric field

electrostatic potential

iterative solution

split operator technique

time-dependent heat equation

CRANK-NICOLSON method

explicit EULER method

implicit EULER method

stability

time-dependent SCHRÖDINGER equation

SeeSCHRÖDINGER equation

wave equation

explicit EULER method

one-dimensional

PAULI matrix

Pdf

SeeProbability density function. Stochastic process

Pendulum

period

Phase space

Phase transition

critical exponent

CURIE-WEISS law

CURIE temperature

first order

modern classification

NÉEL temperature

second order

LANDAU theory

order parameter

universality

POINCARÉ map

POINCARÉ section

POISSON distribution

SeeProbability density function

POISSON equation

SeePartial differential equation

POISSON process

Poor person’s assumption

POTTS model

HAMILTON function

heat capacity

magnetic susceptibility

magnetization

phase transition

first order

histogram technique

second order

Predictor-corrector method

SeeIntegrator

Probability

classical

conservation

correlation coefficient

event

certain

complimentary

impossible

Probability density function

binomial distribution

BOLTZMANN distribution

CAUCHY distribution

χ ² distribution

composite pdf

exponential distribution

GAUSS distribution

LÉVY α -stable distributions

normal distribution

piecewise defined

POISSON distribution

stable distribution

TSALLIS distribution

Q

Quadrature

backward rectangular rule

central rectangular rule

closed integration rule

elemental area

forward rectangular rule

GAUSS-HERMITE

GAUSS-LEGENDRE

error

grid-point

weight

improper integrals

integral transform

Monte-Carlo integration

approximation of π

error

expectation value

hit and miss

mean-value

mean-value integration

multiple integrals

NEWTON-COTES rules

closed

open

open integration rule

rectangular rule

error

ROMBERG method

SIMPSON rule

error

three-eight rule

total error

trapezoidal rule

error

total error

R

Random number

non-uniform distribution

pseudo

real

sequence

correlation

moments

moments error

uniform distribution

Random number generator

criteria

FIBONACCI

lagged

linear congruential

PARK-MILLER parameters

shuffling

MARSAGLIA-ZAMAN

carry bit

period

quality

χ ² test

hypothesis test

spectral test

statistical tests

seed

shift register

Random sampling

See alsoMARKOV-chain Monte-Carlo sampling

direct method

importance sampling

inverse transformation

n -sphere

probability mixing

rejection method

acceptance probability

envelope

histogram test

simple sampling

Random variable

central moments

characteristic function

mean value

moments

standard deviation

uncorrelated

variance

Random walk

biased

definition

moments

probability of first return

recurrence

recurrence probability

transition rate

unbiased

variance

Randomness

definition

CHAITIN

event

measurement

probability

Rectangular rules

Reflection principle

Regula falsi

Rejection method

Relative error

SeeError

RIEMANN-LIOUVILLE fractional derivative

RIEMANN-LIOUVILLE fractional integral

RIESZ fractional derivative

RIESZ fractional integral

ROMBERG method

Roundoff error

SeeError

RUNGE-KUTTA methods

S

SCHRÖDINGER equation

basis

dimensionless variables

eigenenergy

eigenfunction

GAUSS wave packet

stationary

one-dimensional

time-dependent

CRANK-NICOLSON method

explicit EULER method

time-evolution operator

total wave-function

wave-function

normalization

Series expansion

LAGRANGE polynomial

LEGENDRE polynomials

TAYLOR

Shooting method

NUMEROV method

SIMPSON rule

Simulated annealing

SeeStochastic optimization

Slice sampling

SeeMARKOV-chain Monte-Carlo sampling

Split operator technique

Stability

COURANT-FRIEDRICHS-LEWY condition

definition

Standard deviation

Standard error

SeeError

Statistical bootstrap

Steepest descent

SeeDeterministic optimization

STIRLING approximation

Stochastic differential equation

random force

Stochastic matrix

Stochastic optimization

ant colony optimization

cost function

deluge algorithms

genetic algorithm

traveling salesperson problem

grouping genetic algorithms

hill climbing

N -queens problem

simulated annealing

AARTS schedule

acceptance probability

fast

generalized

geometric cooling schedule

initial temperature

traveling salesperson problem

threshold algorithms

Stochastic process

auto-correlation function

auto-covariance function

conditional pdf

definition

Gaussian process

hierarchy of pdfs

independent increments

LÉVY process

moments

pdf

random variable

realization

random walk

state space

stationary increments

stationary process

time span

time-homogeneous process

transition probability

WIENER process

Stochastic variable

SeeRandom variable

STÖRMER-VERLET method

Subtractive cancellation

SWENDSEN-WANG algorithm

Symplectic integrators

Symplectic mapping

T

TAYLOR theorem

SeeSeries expansion

Thermodynamic equilibrium

Thermodynamic expectation value

Time series plot

Time-dependent heat equation

SeePartial differential equation

Trapezoidal rule

Traveling salesperson problem

Truncation error

SeeError

Two-body problem

SeeKEPLER problem

V

Variance

velocity VERLET algorithm

Violation of energy conservation

W

Wave equation

SeePartial differential equation

Wave-function

SeeSCHRÖDINGER equation

WEYL fractional derivative

WEYL fractional integral

White noise

Gaussian

WIENER process

continuous limit

drift term

independent increments

self-similarity

standard process

WOLFF algorithm

Footnotes

1

This method is also referred to as the Newton-Raphson method.

2

A matrix A is referred to as sparse, when the matrix is populated primarily by zeros.

3

In other words, the plane waves $$\exp (in2\pi x/d)$$ with period d form a complete, orthonormal basis in the space of d -periodic, square integrable functions with the scalar product ( 10.​10 ). We remark that this also applies to functions which are defined on a compact interval of length d [ 20 ].

4

We work here with the asymmetric definition of the Fourier transform. For other definitions, the pre-factors have to be adapted consistently.

5

If f ( x ) is not periodic we have to truncate the integral ( D.4 ) and restrict the integration to a suitable finite interval so that the problem again reduces to the evaluation of Eq. ( D.2 ).

6

It follows directly from the summation rule of the geometric series that

7

This is not a limitation because we can always choose N to be even.

8

Here we use the fact that the plane waves $$\exp (in2\pi x/d)$$ form a complete, orthonormal basis of the functions defined on a compact interval of length L [ 20 ].

9

U t is the momentum space representation of the free unitary time evolution operator $$U =\exp (-itP^{2}/2\hslash m)$$ .

10

The Baker-Campbell-Hausdorff formula states how the exponential function $$\exp (X + Y )$$ of two non-commuting operators X and Y can be expanded in terms of products of exponentials of their commutators [ 17 , 28 ].

11

Here we use the symbols ∨ and ∧ to denote the Boolean operators OR and AND, respectively.

12

This means that $$A \vee \overline{A} = I$$ and $$A \wedge \overline{A} = Z$$ .

13

A more exact formulation will follow in the course of this Appendix.

14

For convenience we use here the notation F ( x ) for the cumulative distribution function in contrast to the notation P ( x ) used throughout the second part of this book.

15

One defines the scalar product between random variables $$(X,Y ) = \text{cov}\left (X,Y \right )$$ and therefore $$\|X\|^{2} = (X,X) = \text{var}\left (X\right )$$ . The Cauchy-Schwarz inequality reads

(E.59)

and therefore 0 ≤  r ²  ≤ 1.

16

Independent copies of a random variable, are random variables, which are independent and follow the same distribution as the original random variable.

17

The choice of the order parameter may not be unique [ 39 – 42 ].

18

The extension to space dependent order parameters is referred to as Ginzburg - Landau theory [ 48 ].

19

In many cases one employs the bias corrected variance $$\text{var}\left (y_{k}\right )_{B} = \frac{N} {N-1}\text{var}\left (y_{k}\right )$$ . For a detailed discussion of the bias corrected variance the interested reader is encouraged to consult a statistics textbook [ 45 , 50 – 53 ].

20

The Hessian, or Hesse matrix, $$H \in \mathbb{R}^{N\times N}$$ of a function f ( x ), $$x \in \mathbb{R}^{N}$$ is the Jacobian of the Jacobian J ( x ) of f ( x ) defined in Eq. ( B.8 ). Thus, it is the matrix of second order partial derivatives of a function. It describes the local curvature of a function of many variables.

21

We remember from vector analysis that

22

Note that the Hessian is always symmetric for real valued functions f ( x ) due to the symmetry of second order derivatives.

23

In principle these linear independent vectors $$\{\varphi _{n}^{\ell}\}$$ do not need to depend on the index n , i.e. on the actual position x n . However, we consider here the most general case as will soon become clear.