| Preface | 5 |
---|
| 1 Introduction to computer simulation | 21 |
---|
| 1.1 Physics and computational physics | 21 |
| 1.2 Choice of programming language | 25 |
| 1.3 Outfitting your PC for scientific computing | 33 |
| 1.4 History of computing in a nutshell | 37 |
| 1.5 Number representation: bits and bytes in computer memory | 42 |
| 1.5.1 Addition and subtraction of dual integer numbers | 44 |
| 1.5.2 Basic data types | 49 |
| 1.6 The role of algorithms in scientific computing | 61 |
| 1.6.1 Efficient and inefficient calculations | 63 |
| 1.6.2 Asymptotic analysis of algorithms | 71 |
| 1.6.3 Merge sort and divide-and-conquer | 76 |
| 1.7 Theory, modeling and computer simulation | 79 |
| 1.7.1 What is a theory? | 79 |
| 1.7.2 What is a model? | 87 |
| 1.7.3 Model systems: particles or fields? | 92 |
| 1.7.4 The linear chain as a model system | 94 |
| 1.7.5 From modeling to computer simulation | 98 |
| 1.8 Exercises | 101 |
| 1.8.1 Addition of bit patterns of 1 byte duals | 101 |
| 1.8.2 Subtracting dual numbers using two’s complement | 101 |
| 1.8.3 Comparison of running times | 101 |
| 1.8.4 Asymptotic notation | 102 |
| 1.9 Chapter literature | 103 |
| 2 Scientific Computing in C | 104 |
---|
| 2.1 Introduction | 104 |
| 2.1.1 Basics of a UNIX/Linux programming environment | 107 |
| 2.2 First steps in C | 119 |
| 2.2.1 Variables in C | 121 |
| 2.2.2 Global variables | 123 |
| 2.2.3 Operators in C | 124 |
| 2.2.4 Control structures | 128 |
| 2.2.5 Scientific “Hello world!” | 131 |
| 2.2.6 Streams - input/output functionality | 136 |
| 2.2.7 The preprocessor and symbolic constants | 139 |
| 2.2.8 The function scanf() | 142 |
| 2.3 Programming examples of rounding errors and loss of precision | 145 |
| 2.3.1 Algorithms for calculating e-x | 150 |
| 2.3.2 Algorithm for summing 1/n | 153 |
| 2.4 Details on C-Arrays | 157 |
| 2.4.1 Direct initialization of certain array elements (C99) | 161 |
| 2.4.2 Arrays with variable length (C99) | 161 |
| 2.4.3 Arrays as function parameters | 162 |
| 2.4.4 Pointers | 164 |
| 2.4.5 Pointers as function parameters | 172 |
| 2.4.6 Pointers to functions as function parameters | 174 |
| 2.4.7 Strings | 179 |
| 2.5 Structures and their representation in computer memory | 181 |
| 2.5.1 Blending structs and arrays | 183 |
| 2.6 Numerical differentiation and integration | 185 |
| 2.6.1 Numerical differentiation | 186 |
| 2.6.2 Case study: the second derivative of ex | 189 |
| 2.6.3 Numerical integration | 196 |
| 2.7 Remarks on programming and software engineering | 201 |
| 2.7.1 Good software development practices | 201 |
| 2.7.2 Reduction of complexity | 204 |
| 2.7.3 Designing a program | 208 |
| 2.7.4 Readability of a program | 209 |
| 2.7.5 Focus your attention by using conventions | 210 |
| 2.8 Ways to improve your programs | 211 |
| 2.9 Exercises | 213 |
| 2.9.1 Questions | 213 |
| 2.9.2 Errors in programs | 214 |
| 2.9.3 printf()-statement | 217 |
| 2.9.4 Assignments | 218 |
| 2.9.5 Loops | 219 |
| 2.9.6 Recurrence | 219 |
| 2.9.7 Macros | 220 |
| 2.9.8 Strings | 220 |
| 2.9.9 Structs | 221 |
| 2.10 Projects | 223 |
| 2.10.1 Decimal and binary representation | 223 |
| 2.10.2 Nearest machine number | 223 |
| 2.10.3 Calculating e -x | 223 |
| 2.10.4 Loss of precision | 224 |
| 2.10.5 Summing series | 224 |
| 2.10.6 Recurrence in orthogonal functions | 225 |
| 2.10.7 The Towers of Hanoi | 225 |
| 2.10.8 Spherical harmonics and Legendre polynomials | 227 |
| 2.10.9 Memory diagram of a battle | 228 |
| 2.10.10 Computing derivatives numerically | 228 |
| 2.11 Chapter literature | 230 |
| 3 Fundamentals of statistical physics | 231 |
---|
| 3.1 Introduction and basic ideas | 232 |
| 3.1.1 The macrostate | 236 |
| 3.1.2 The microstate | 238 |
| 3.1.3 Information conservation in statistical physics | 239 |
| 3.1.4 Equations of motion in classical mechanics | 245 |
| 3.1.5 Statistical physics in phase space | 249 |
| 3.2 Elementary statistics | 255 |
| 3.2.1 Random Walk | 256 |
| 3.2.2 Discrete and continuous probability distributions | 261 |
| 3.2.3 Reduced probability distributions | 262 |
| 3.2.4 Important distributions in physics and engineering | 264 |
| 3.3 Equilibrium distribution | 269 |
| 3.3.1 The most probable distribution | 271 |
| 3.3.2 A statistical definition of temperature | 273 |
| 3.3.3 The Boltzmann distribution and the partition function | 275 |
| 3.4 The canonical ensemble | 278 |
| 3.5 Exercises | 281 |
| 3.5.1 Trajectories of the one-dimensional harmonic oscillator in phase space | 281 |
| 3.5.2 Important integrals of statistical physics | 281 |
| 3.5.3 Probability, e
|