Theoretical Concepts and Simulations
S. Denisov MNTF, Uni Augsburg
Some words about the course
The lecturer
Sergey Denisov, Theor. Phys. I Dept, MNTF, Uni Augsburg Can be reached by email:
My office is located in the Institute for Physics, North Building, fifth floor, Theor. Phys. I, room517.
Personal web page:
http://www.physik.uni-augsburg.de/~denisose/
The course
Lectures: two times a week (Wednesday, 15 : 45−17 : 15, &
Friday, 14 : 00−15 : 30), audience T-1005
Some words about the course
Suggested textbooks
I H. Gould, J. Tobochnik and W. Christian, Introduction to Computer Simulation Methods (3rd ed., Addison Wesley, Reading MA, 2006) (Java).
I W. Kinzel and G. Reents, Physik per Computer (Physikalischer Probleme mit Mathematica und C)
I P. DeVries and J. Hasbun,A First Course in Computational Physics (2nd ed., Jones & Bartlett Publishers, 2010) (Matlab)
Some words about the course
Suggested on-line courses (reference material)
I R. Fitzpatrick, Computational Physics: An introductory course (C andC + +),
http://farside.ph.utexas.edu/teaching/329/lectures/lectures.html I Computational Physics using MATLAB, http://www.physics.
purdue.edu/~hisao/book/www/Computational_Physics_using_MATLAB.pdf I Computational Physics with Python,
http://www-personal.umich.edu/~mejn/computational-physics/
http://phys.csuchico.edu/ayars/312/Handouts/comp-phys-python.pdf
Some words about the course
Topics
I basic things: numerical precision and accuracy of simulations, random number generation, interpolation, differentiation, integration, roots of an equation, extremes of a function;
I ordinary differential equations (ODEs): Euler method, predictor-corrector methods, Runge-Kutta method, some specific integrators;
I basic matrix operations, linear equations systems, eigenvalue problems and matrix decompositions;
I Fourier analysis, discrete and fast Fourier transform, Fourier transform in higher dimensions;
I Partial differential equations, initial value problems, boundary value problems;
Some words about the course
Topics (continuation)
I molecular dynamics simulations, percolation, diffusion limited aggregation and ab-initio molecular dynamics
I ordinary differential equations (ODEs): Euler method, predictor-corrector methods, Runge-Kutta method, some specific integrators;
I Monte-Carlo simulations, sampling and integration, Metropolis algorithm;
I simulations of open quantum systems: Monte Carlo
wave-function method (also called ’quantum-jump approach’).
Computational physics
Goals
I calculate solutions to physics problems
I Take advantage of the fact that all physics problems are (should be) formulated mathematically
I Solve equations!
I display solutions in a way that helps you (us, them) interpret and understand the underlying physics
Computational physics
Formulate the problem & then solve the equations
I There are many different types of equations:
I algebraic (polynomial)
I trigonometric, logarithmic
I differential, integral
I linear, nonlinear
I you may have a single equation to solve or a set of equations that must be solved simultaneously
I your need to propagate the equation(s) which may depend on initial or boundary conditions
Computational physics
See the results
I In most cases, you need to make a plot of the solution, in order to visualize how certain quantities depend on others.
I xmgrace(simple graphs)
I gnuplot(good for almost everything)
I matlab(very convenient)
I Origin(the best, but very expensive)
I how to visualize the results is an issue itself
Computational physics
The computer does what it was told to do
I The work in solving a problem is still to be done
I derive the equations that represent the system of interest
I understand all the approximations and limitations (conditions for validity)
I determine how to instruct the computer to solve the equations
I undestand all shortcoming and pitfalls of computer simulations
I results of simulations ⇔theoretical predictions
I comparison with measurements
Computational physics
Tools and means
I programs such as Mathematica and MATLAB can help you work with equations analytically
I symbolic manipulation
I might help you obtain analytical solution
I in most cases the equations have to be solved numerically
I smooth functions must be discretized
I derivatives become differences
I integrals become sums
I errors (round-offs, approximation, ect) must be carefully tracked
Computer number representations and numerical precision
An example
Having only floating numbers with 5 decimal digits, we wish to evaluate the function
f(x) = 1−cos(x) sin(x)
for some small value ofx. By multiplying the denominator and numerator with 1 + cos(x) we get
f(x) = sin(x) 1 + cos(x)
Takex = 0.007 (in radians). For the chosen precision we get
≈ × −2 ≈
Computer number representations and numerical precision
An example (continuation)
First expression forf(x) results in f(x) = 1−0.99998
0.69999×10−2 = 0.2×10−4
0.69999×10−2 = 0.28572×10−2 while the second expression results in
f(x) = 0.69999×10−2
1 + 0.99998 = 0.69999×10−2
1.99998 = 0.35000×10−2. The former results iswrong, the latter is theexact. Forx ≈π the situationis reversed.
Not, that if had chosen a precision of 6 leading digits, both expressions yield the same answer.
Computer number representations and numerical precision
IEEE fixed-point numbers
Fixed-point numbers, i. e. numbers with fixed number of digits beyond the decimal point are rare in computational physics (integers mostly, combinatoric problems etc). A fixed-point representation withN bits looks
, wheren+m=N−2.
Their range (forN = 32) is−2147483648≤x ≤2147483647 Anadvantage of this representation is that all numbers have the sameabsolute error 2−m−1. The biggest disadvantage is that small numbers have largerelativeerrors. In real-world applications
Computer number representations and numerical precision
IEEE floating-point numbers
Floating-point numbers are stored as a concatenation of (1) the sign bit s, (2), theexponent e, and (3) the mantissa f,
Singles: 32 bits for all;Doubles: 32 + 32 bits for all A single: s: a single bit, e: 8 bits (0≤e ≤255), f: 23
A double: s: a single bit, e: 11 bits (0≤e ≤2047), f: 52 bits The stored exponente is always positive, and a fixed umberbias is added to the actual exponent before it is stored as the biased exponente. The actual exponent is
p=e−bias Singles: bias= 127, doubles: bias= 1023
Computer number representations and numerical precision
IEEE floating-point numbers (continuation)
The IEEE standard for primitive data types
Computer number representations and numerical precision
Machine precision (an example)
Consider the addition of two single-precision numbers 7 + 1.0×10−7=?
Both numbers are stored as bit sequences
Computer number representations and numerical precision
Machine precision (an example, continuation)
Because the exponent are different, the exponent of the smaller number is made larger by shifting bits to the right (inserting zeros) and progressively decreasing the mantissa,