ebook img

Computational Physics - A Practical Introduction to Computational Physics and Scientific Computing PDF

682 Pages·2014·20.97 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computational Physics - A Practical Introduction to Computational Physics and Scientific Computing

Computational Physics Konstantinos N. Anagnostopoulos COMPUTATIONAL PHYSICS A P I  C P  S C A, 2014 KONSTANTINOS N. ANAGNOSTOPOULOS National Technical University of Athens N T U  A PUBLISHEDBYKONSTANTINOSN.ANAGNOSTOPOULOS PhysicsDepartment,NationalTechnicalUniversityofAthens,ZografouCampus,15780Zografou,Greece [email protected],www.physics.ntua.gr/˜konstant/ andtheNATIONALTECHNICALUNIVERSITYOFATHENS BookWebsite: www.physics.ntua.gr/˜konstant/ComputationalPhysics ©KonstantinosN.Anagnostopoulos2014 FirstPublished2014 Version¹1.0.20140726222900 Cover: DesignbyK.N.Anagnostopoulos. ThefrontcoverpictureisasnapshottakenduringMonteCarlosim- ulationsofhexaticmembranes. WorkdonewithMarkJ.Bowick. Relevantvideoatyoutu.be/Erc7Q6YXfLk ⃝CC This book and its cover(s) are subject to copyright. They are licensed under the Creative Commons Attribution-ShareAlike4.0InternationalLicense. Toviewacopyofthislicense,visit creativecommons.org/licenses/by-sa/4.0/ Thisisahuman-readablesummaryof(andnotasubstitutefor)thelicense,see creativecommons.org/licenses/by-sa/4.0/legalcode Youarefreeto: • Share—copyandredistributethematerialinanymediumorformat • Adapt—remix,transform,andbuilduponthematerialforanypurpose,evencommercially. Thelicensorcannotrevokethesefreedomsaslongasyoufollowthelicenseterms. Underthefollowingterms: • ⃝BY: Attribution — You must give appropriate credit, provide a link to the license, and indicate if changesweremade. Youmaydosoinanyreasonablemanner,butnotinanywaythatsuggeststhe licensorendorsesyouoryouruse. • ⃝c ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributionsunderthesamelicenseastheoriginal. Notices: Youdonothavetocomplywiththelicenseforelementsofthematerialinthepublicdomainorwhereyour useispermittedbyanapplicableexceptionorlimitation. No warranties are given. The license may not give you all of the permissions necessary for your intended use. Forexample,otherrightssuchaspublicity,privacy,ormoralrightsmaylimithowyouusethematerial. Thebookisaccompaniedbysoftwareavailableatthebook’swebsite. Allthesoftware,unlessthecopyright doesnotbelongtotheauthor,isopensource,coveredbytheGNUpubliclicense,seewww.gnu.org/licenses/. Thisisexplicitlymentionedattheendoftherespectivesourcefiles. ISBN978-1-312-31812-0(lulu.com) ¹The first number is the major version, corresponding to an “edition” of a conventional book. Versions differing by major numbers have been altered substantially. Chapter numbers and page references are not guaranteedtomatchbetweendifferentversions. Thesecondnumberistheminorversion. Versionsdiffering by a minor version may have serious errors/typos corrected and/or substantial text modifications. Versions differing by only the last number may have minor typos corrected, added references etc. When reporting errors,pleasementiontheversionnumberyouarereferringto. Contents Foreword vii 1 The Computer 1 1.1 The Operating System . . . . . . . . . . . . . . . . . . . . . 3 1.1.1 Filesystem . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1.2 Commands . . . . . . . . . . . . . . . . . . . . . . . 11 1.1.3 Looking for Help . . . . . . . . . . . . . . . . . . . . 14 1.2 Text Processing Tools – Filters . . . . . . . . . . . . . . . . 16 1.3 Programming with Emacs . . . . . . . . . . . . . . . . . . . 21 1.3.1 Calling Emacs . . . . . . . . . . . . . . . . . . . . . . 21 1.3.2 Interacting with Emacs . . . . . . . . . . . . . . . . 23 1.3.3 Basic Editing . . . . . . . . . . . . . . . . . . . . . . 24 1.3.4 Cut and Paste . . . . . . . . . . . . . . . . . . . . . . 27 1.3.5 Windows . . . . . . . . . . . . . . . . . . . . . . . . 29 1.3.6 Files and Buffers . . . . . . . . . . . . . . . . . . . . 30 1.3.7 Modes . . . . . . . . . . . . . . . . . . . . . . . . . . 31 1.3.8 Emacs Help . . . . . . . . . . . . . . . . . . . . . . . 32 1.3.9 Emacs Customization . . . . . . . . . . . . . . . . . 34 1.4 The Fortran Programming Language . . . . . . . . . . . . 35 1.4.1 The Foundation . . . . . . . . . . . . . . . . . . . . 35 1.4.2 Details . . . . . . . . . . . . . . . . . . . . . . . . . . 45 1.4.3 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 50 1.5 Gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 1.6 Shell Scripting . . . . . . . . . . . . . . . . . . . . . . . . . 62 2 Kinematics 77 2.1 Motion on the Plane . . . . . . . . . . . . . . . . . . . . . . 77 2.1.1 Plotting Data . . . . . . . . . . . . . . . . . . . . . . 85 2.1.2 More Examples . . . . . . . . . . . . . . . . . . . . . 88 2.2 Motion in Space . . . . . . . . . . . . . . . . . . . . . . . . 99 2.3 Trapped in a Box . . . . . . . . . . . . . . . . . . . . . . . . 107 iii iv CONTENTS 2.3.1 The One Dimensional Box . . . . . . . . . . . . . . 108 2.3.2 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . 114 2.3.3 The Two Dimensional Box . . . . . . . . . . . . . . 117 2.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 2.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 3 Logistic Map 145 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 3.2 Fixed Points and 2n Cycles . . . . . . . . . . . . . . . . . . 147 3.3 Bifurcation Diagrams . . . . . . . . . . . . . . . . . . . . . 154 3.4 The Newton-Raphson Method . . . . . . . . . . . . . . . . 157 3.5 Calculation of the Bifurcation Points . . . . . . . . . . . . . 163 3.6 Liapunov Exponents . . . . . . . . . . . . . . . . . . . . . . 167 3.7 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 4 Motion of a Particle 191 4.1 Numerical Integration of Newton’s Equations . . . . . . . . 191 4.2 Prelude: Euler Methods . . . . . . . . . . . . . . . . . . . . 192 4.3 Runge–Kutta Methods . . . . . . . . . . . . . . . . . . . . . 204 4.3.1 A Program for the 4th Order Runge–Kutta . . . . . 208 4.4 Comparison of the Methods . . . . . . . . . . . . . . . . . . 212 4.5 The Forced Damped Oscillator . . . . . . . . . . . . . . . . 215 4.6 The Forced Damped Pendulum . . . . . . . . . . . . . . . . 222 4.7 Appendix: On the Euler–Verlet Method . . . . . . . . . . . 229 4.8 Appendix: 2nd order Runge–Kutta Method . . . . . . . . 233 4.9 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 5 Planar Motion 241 5.1 Runge–Kutta for Planar Motion . . . . . . . . . . . . . . . 241 5.2 Projectile Motion . . . . . . . . . . . . . . . . . . . . . . . . 246 5.3 Planetary Motion . . . . . . . . . . . . . . . . . . . . . . . . 252 5.4 Scattering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 5.4.1 Rutherford Scattering . . . . . . . . . . . . . . . . . 260 5.4.2 More Scattering Potentials . . . . . . . . . . . . . . . 267 5.5 More Particles . . . . . . . . . . . . . . . . . . . . . . . . . . 270 5.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 6 Motion in Space 285 6.1 Adaptive Stepsize Control for Runge–Kutta Methods . . . . 286 6.2 Motion of a Particle in an EM Field . . . . . . . . . . . . . 295 6.3 Relativistic Motion . . . . . . . . . . . . . . . . . . . . . . . 296 CONTENTS v 6.4 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 7 Electrostatics 311 7.1 Electrostatic Field of Point Charges . . . . . . . . . . . . . . 311 7.2 The Program – Appetizer and ... Desert . . . . . . . . . . . 314 7.3 The Program – Main Dish . . . . . . . . . . . . . . . . . . . 323 7.4 The Program - Conclusion . . . . . . . . . . . . . . . . . . . 329 7.5 Electrostatic Field in the Vacuum . . . . . . . . . . . . . . . 334 7.6 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 7.7 Poisson Equation . . . . . . . . . . . . . . . . . . . . . . . . 342 7.8 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 8 Diffusion Equation 353 8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 8.2 Heat Conduction in a Thin Rod . . . . . . . . . . . . . . . . 355 8.3 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . 356 8.4 The Program . . . . . . . . . . . . . . . . . . . . . . . . . . 358 8.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 8.6 Diffusion on the Circle . . . . . . . . . . . . . . . . . . . . . 363 8.7 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 8.8 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 9 The Anharmonic Oscillator 373 9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 9.2 Calculation of the Eigenvalues of H ((cid:21)) . . . . . . . . . . 375 nm 9.3 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 9.4 The Double Well Potential . . . . . . . . . . . . . . . . . . . 390 9.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 10 Time Independent Schrödinger Equation 401 10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 10.2 The Infinite Potential Well . . . . . . . . . . . . . . . . . . . 404 10.3 Bound States . . . . . . . . . . . . . . . . . . . . . . . . . . 413 10.4 Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . 422 10.5 The Anharmonic Oscillator - Again... . . . . . . . . . . . . 428 10.6 The Lennard–Jones Potential . . . . . . . . . . . . . . . . . 431 10.7 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442 11 The Random Walker 447 11.1 (Pseudo)Random Numbers . . . . . . . . . . . . . . . . . . 448 11.2 Using Pseudorandom Number Generators . . . . . . . . . . 460 vi CONTENTS 11.3 Random Walks . . . . . . . . . . . . . . . . . . . . . . . . . 467 11.4 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 12 Monte Carlo Simulations 479 12.1 Statistical Physics . . . . . . . . . . . . . . . . . . . . . . . . 480 12.2 Entropy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 12.3 Fluctuations . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 12.4 Correlation Functions . . . . . . . . . . . . . . . . . . . . . 489 12.5 Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 12.5.1 Simple Sampling . . . . . . . . . . . . . . . . . . . . 492 12.5.2 Importance Sampling . . . . . . . . . . . . . . . . . 493 12.6 Markov Processes . . . . . . . . . . . . . . . . . . . . . . . . 494 12.7 Detailed Balance Condition . . . . . . . . . . . . . . . . . . 495 12.8 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 13 Simulation of the d = 2 Ising Model 499 13.1 The Ising Model . . . . . . . . . . . . . . . . . . . . . . . . 499 13.2 Metropolis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 13.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 508 13.3.1 The Program . . . . . . . . . . . . . . . . . . . . . . 513 13.3.2 Towards a Convenient User Interface . . . . . . . . . 519 13.4 Thermalization . . . . . . . . . . . . . . . . . . . . . . . . . 531 13.5 Autocorrelations . . . . . . . . . . . . . . . . . . . . . . . . 533 13.6 Statistical Errors . . . . . . . . . . . . . . . . . . . . . . . . 540 13.6.1 Errors of Independent Measurements . . . . . . . . 541 13.6.2 Jackknife . . . . . . . . . . . . . . . . . . . . . . . . 544 13.6.3 Bootstrap . . . . . . . . . . . . . . . . . . . . . . . . 546 13.7 Appendix: Autocorrelation Function . . . . . . . . . . . . . 547 13.8 Appendix: Error Analysis . . . . . . . . . . . . . . . . . . . 555 13.8.1 The Jackknife Method . . . . . . . . . . . . . . . . . 555 13.8.2 The Bootstrap Method . . . . . . . . . . . . . . . . . 559 13.8.3 Comparing the Methods . . . . . . . . . . . . . . . . 562 13.9 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 14 Critical Exponents 577 14.1 Critical Slowing Down . . . . . . . . . . . . . . . . . . . . . 579 14.2 Wolff Cluster Algorithm . . . . . . . . . . . . . . . . . . . . 580 14.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 587 14.3.1 The Program . . . . . . . . . . . . . . . . . . . . . . 589 14.4 Production . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 14.5 Data Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 597 CONTENTS vii 14.6 Autocorrelation Times . . . . . . . . . . . . . . . . . . . . . 605 14.7 Temperature Scaling . . . . . . . . . . . . . . . . . . . . . . 608 14.8 Finite Size Scaling . . . . . . . . . . . . . . . . . . . . . . . 614 14.9 Calculation of (cid:12) . . . . . . . . . . . . . . . . . . . . . . . . 616 c 14.10Studying Scaling with Collapse . . . . . . . . . . . . . . . . 621 14.11Binder Cumulant . . . . . . . . . . . . . . . . . . . . . . . . 631 14.12Appendix: Scaling . . . . . . . . . . . . . . . . . . . . . . . 634 14.12.1Binder Cumulant . . . . . . . . . . . . . . . . . . . . 634 14.12.2Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . 640 14.12.3Finite Size Scaling . . . . . . . . . . . . . . . . . . . 642 14.13Appendix: Critical Exponents . . . . . . . . . . . . . . . . . 645 14.13.1Definitions . . . . . . . . . . . . . . . . . . . . . . . . 645 14.13.2Hyperscaling Relations . . . . . . . . . . . . . . . . . 646 14.14Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646 Bibliography 650 Index 658 viii CONTENTS This book has been written assuming that the reader executes all the commands presented in the text and follows all the instructions at the same time. If this advice is neglected, then the book will be of little help and some parts of the text may seem incomprehensible. The book’s website is at http://www.physics.ntua.gr/˜konstant/ComputationalPhysics/ From there, you can can download the accompanying software, which con- tains, among other things, all the programs presented in the book. Some conventions: Text using the font shown below refers to com- mands given using a shell (the “command line”), input and output of programs, code written in Fortran (or any other programming language), as well as to names of files and programs: > echo Hello world Hello world When a line starts with the prompt > then the text that follows is a command, which can be given from the command line of a terminal. The second line, Hello World, is the output of the command. The contents of a file with Fortran code is listed below: program add z = 1.0 y = 2.0 x = z + y print *, x end program add What you need in order to work on your PC: CONTENTS ix • An operating system of the GNU/Linux family and its basic tools. • A Fortran compiler. The gfortran compiler is freely available for all major operating systems under an open source license at http://www.gfortran.org. • An advanced text editor, suitable for editing code in several pro- gramming languages, like Emacs². • A good plotting program, suitable for data analysis, like gnuplot³. • The shell tcsh⁴. • The programs awk⁵, grep, sort, cat, head, tail, less. Make sure that they are available in your computer environment. If you have installed a GNU/Linux distribution on your computer, all of the above can be installed easily. For example, in a Debian like distribution (Ubuntu, ...) the commands > sudo apt(cid:0)get install tcsh emacs gnuplot(cid:0)x11 gnuplot(cid:0)doc > sudo apt(cid:0)get install gfortran gawk gawk(cid:0)doc binutils > sudo apt(cid:0)get install manpages(cid:0)dev coreutils liblapack3 install all the necessary tools. If you don’t wish to install GNU/Linux on your computer, you can try the following: • Bootyourcomputerusingausb/DVDliveGNU/Linux, likeUbuntu⁶. This will not make any permanent changes in your hard drive but it will start and run slower. On the other hand, you may save all your computing environment and documents and use it on any computer you like. • Install Cygwin⁷ in your Microsoft Windows. It is a very good solu- tion for Microsoft-addicted users. If you choose the full installation, then you will find all the tools needed in this book. ²http://www.gnu.org/software/emacs/ ³http://www.gnuplot.info ⁴http://www.tcsh.org ⁵http://www.gnu.org/software/gawk ⁶http://www.ubuntu.com ⁷http://www.cygwin.com

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.