Graduate Texts in Physics Forfurthervolumes: www.springer.com/series/8431 Graduate Texts in Physics Graduate Texts in Physics publishes core learning/teaching material for graduate- and ad- vanced-levelundergraduatecoursesontopicsofcurrentandemergingfieldswithinphysics, both pure and applied. These textbooks serve students at the MS- or PhD-level and their instructorsascomprehensivesourcesofprinciples,definitions,derivations,experimentsand applications(asrelevant)fortheirmasteryandteaching,respectively.Internationalinscope and relevance, the textbooks correspond to course syllabi sufficiently to serve as required reading.Theirdidacticstyle,comprehensivenessandcoverageoffundamentalmaterialalso makethemsuitableasintroductionsorreferencesforscientistsentering,orrequiringtimely knowledgeof,aresearchfield. SeriesEditors ProfessorWilliamT.Rhodes DepartmentofComputerandElectricalEngineeringandComputerScience ImagingScienceandTechnologyCenter FloridaAtlanticUniversity 777GladesRoadSE,Room456 BocaRaton,FL33431 USA [email protected] ProfessorH.EugeneStanley CenterforPolymerStudiesDepartmentofPhysics BostonUniversity 590CommonwealthAvenue,Room204B Boston,MA02215 USA [email protected] ProfessorRichardNeeds CavendishLaboratory JJThomsonAvenue CambridgeCB30HE UK [email protected] Simon Širca (cid:2) Martin Horvat Computational Methods for Physicists Compendium for Students SimonŠirca MartinHorvat FacultyofMathematicsandPhysics FacultyofMathematicsandPhysics UniversityofLjubljana UniversityofLjubljana Ljubljana,Slovenia Ljubljana,Slovenia ISSN1868-4513 ISSN1868-4521(electronic) GraduateTextsinPhysics ISBN978-3-642-32477-2 ISBN978-3-642-32478-9(eBook) DOI10.1007/978-3-642-32478-9 SpringerHeidelbergNewYorkDordrechtLondon LibraryofCongressControlNumber:2012951441 ©Springer-VerlagBerlinHeidelberg2012 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartof thematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation, broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformation storageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodology nowknownorhereafterdeveloped.Exemptedfromthislegalreservationarebriefexcerptsinconnection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’slocation,initscurrentversion,andpermissionforusemustalwaysbeobtainedfromSpringer. PermissionsforusemaybeobtainedthroughRightsLinkattheCopyrightClearanceCenter.Violations areliabletoprosecutionundertherespectiveCopyrightLaw. Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublication doesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevant protectivelawsandregulationsandthereforefreeforgeneraluse. Whiletheadviceandinformationinthisbookarebelievedtobetrueandaccurateatthedateofpub- lication,neithertheauthorsnortheeditorsnorthepublishercanacceptanylegalresponsibilityforany errorsoromissionsthatmaybemade.Thepublishermakesnowarranty,expressorimplied,withrespect tothematerialcontainedherein. Printedonacid-freepaper SpringerispartofSpringerScience+BusinessMedia(www.springer.com) Dedicatedtoourparents Preface ThisbookevolvedfromshortwrittenhomeworkinstructionsforthecourseinCom- putationalPhysicsattheDepartmentofPhysics,UniversityofLjubljana.Thefeed- backreceivedfromthestudentswasusedtograduallysupplementtheinstructions byoralpresentationsintheclassroomandadditionalmaterialontheweb.Theher- itage of this course, established and initially taught for a number of years by Pro- fessor Kodre, represented a basis onto which we attempted to span an even richer manifold,andtobetterelucidatethe“exercises”fromthemathematical,physical,as wellasprogrammingandcomputationalviewpoints.Thesomewhatspartaninstruc- tionsthusevolvedintoamuchmoregeneraltextbookwhichisintendedprimarily forthird-andfourth-yearphysicsstudents,andforPh.D.studentsasanaidforall courses with a mathematical physics tinge. The book might also appeal to mathe- matics students. It was one of our local goals to modestly interweave physics and mathematicsstudies,andthisiswhythebooksteersbetweenmathematicalrigidity andmoreprofaneperspectivesofnumericalmethods,whileittriestopreservethe colorfulcontentofthefieldofmathematicalphysics. We were driven by the realization that physics students are often insufficiently preparedtofacevariousobstaclestheyencounterinnumericalsolutionormodeling ofphysicalproblems.Onlyahandfulofthemtrulyknowhowsomethingcan“ac- tuallybecomputed”orhowtheirworkcanbeefficientlycontrolledanditsresults reliablychecked.EveryonecansolvethematrixsystemAx=b,butalmostnoone has an idea how to estimate the error and relate this estimate to the possible true error. They use explicit integrators of differential equations indiscriminately until theytrytolookcloselyatsolutionsofaproblemassimpleasx¨=−x.Thedireness ofthesituationiscompoundedbymanycommercialtoolsgivingafalseimpression thatallproblemscanbesolvedbyasinglekeystroke.Inpartsofthetextwherebasic approachesarediscussed,weinsistonseeminglyballastnumericaldetailswhile,on theotherhand,wedidwishtoofferatleastsome“serious”methodsandillustrate thembymanageableexamples.Thebookswingsbackandforthbetweentheseex- tremes:ittriestobeneitherfullyelementarynorencyclopedicallycomplete,butat anyraterepresentative—atleastforthefirst-timereader. vii viii Preface The book is structured exactly with such gradations in mind: additional, “non- compulsory”chaptersaremarkedwithstars(cid:2)and(cid:2)canbereadbyparticularlymoti- vatedstudentsorusedasreference.Similarly,the symbolsdenotesimplertasks inthe(cid:3)end-of-chapterproblems,whilemoredemandingonesaremarkedbythesym- bols . The purpose of the appendices is not merely to remove the superfluous contentsfromthemaintext,buttoenhanceprogrammingefficiency(aboveall,Ap- pendicesB,C,E,I,andJ).Thesourapplesweforceourreadertobitearethelack ofdetailedderivationsandreferencestoformulasplacedinremotepartsofthetext, althoughwetriedtodesignthechaptersasself-containedunits.Thisstylerequires moreconcentrationandconsultationwithliteratureonthereader’spart,butmakes thetextmoreconcise.Inturn,thebookdoescallforaninspiredcoursetutor.Ina typical one-semester course, she may hand-pick and fine-tune a dozen or so end- of-chapterproblemsandsupplythenecessarybackground,whilethestudentsmay perusethebookasaconvenientpointofdepartureforwork. Theend-of-chapterproblemsshouldresonatewellwiththemajorityofphysics students. We scooped up topics from most varied disciplines and tried to embed them into the framework of the book. Chapters are concluded by relatively long lists of references, with the intent that the book will be useful also as a stepping stoneforfurtherstudyandasadecentvademecum. Inspiteofallcare,errorsmayhavecreptin.Weshallbegratefultoallreaders turningourattentiontoanyerrortheymightspot,nomatterhowrelevant.TheEr- ratawillbemaintainedatthebook’sweb-pagehttp://cmp.fmf.uni-lj.si,whichalso containsthedatafilesneededinsomeoftheproblems. WewishtoexpressourgratitudetoProfessorClausAscheron,SeniorEditorat Springer, for his effort in preparation and advancement of this book, as well as to DonatasAkmanavicˇiusandhisteamforitsmeticulousproductionatVTeX. The original text of the Slovenian edition was scrutinized by two physicists (ProfessorsAlojzKodreandTomažProsen)aswellasfourmathematicians(Asso- ciateProfessorsEmilŽagar,MarjetkaKrajnc,GašperJaklicˇ,andProfessorValery Romanovski, who carefully examined the section on Gröbner bases). We thank them;fromthenavigationbetweentheScyllaandCharibdisofthesereviewerswe emergedasbettersailorsandarrivedhappily,afteryearsofroamingthestormyseas, toourIthaca. Ljubljana,Slovenia SimonŠirca MartinHorvat Contents 1 BasicsofNumericalAnalysis . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.1 Finite-PrecisionArithmetic . . . . . . . . . . . . . . . . . 1 1.2 ApproximationofExpressions . . . . . . . . . . . . . . . . . . . 6 1.2.1 Optimal(Minimax)andAlmostOptimalApproximations . 6 1.2.2 Rational(Padé)Approximation . . . . . . . . . . . . . . . 9 1.2.3 Summationof SeriesbyUsingPadéApproximations (Wynn’s(cid:3)-Algorithm) . . . . . . . . . . . . . . . . . . . . 12 1.2.4 Approximation of the Evolution Operator for a HamiltonianSystem . . . . . . . . . . . . . . . . . . . . . 14 1.3 PowerandAsymptoticExpansion,AsymptoticAnalysis . . . . . . 16 1.3.1 PowerExpansion . . . . . . . . . . . . . . . . . . . . . . 17 1.3.2 AsymptoticExpansion . . . . . . . . . . . . . . . . . . . . 17 1.3.3 AsymptoticAnalysisofIntegralsbyIntegrationbyParts . . 19 1.3.4 AsymptoticAnalysisofIntegralsbytheLaplaceMethod . 21 1.3.5 Stationary-PhaseApproximation . . . . . . . . . . . . . . 24 1.3.6 DifferentialEquationswithLargeParameters. . . . . . . . 27 1.4 SummationofFiniteandInfiniteSeries . . . . . . . . . . . . . . . 31 1.4.1 TestsofConvergence . . . . . . . . . . . . . . . . . . . . 32 1.4.2 SummationofSeriesinFloating-PointArithmetic . . . . . 33 1.4.3 AccelerationofConvergence . . . . . . . . . . . . . . . . 36 1.4.4 AlternatingSeries . . . . . . . . . . . . . . . . . . . . . . 38 1.4.5 Levin’sTransformations . . . . . . . . . . . . . . . . . . . 42 1.4.6 PoissonSummation . . . . . . . . . . . . . . . . . . . . . 44 1.4.7 BorelSummation . . . . . . . . . . . . . . . . . . . . . . 44 1.4.8 AbelSummation . . . . . . . . . . . . . . . . . . . . . . . 45 1.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 1.5.1 IntegraloftheGaussDistribution . . . . . . . . . . . . . . 46 1.5.2 AiryFunctions . . . . . . . . . . . . . . . . . . . . . . . . 48 1.5.3 BesselFunctions . . . . . . . . . . . . . . . . . . . . . . . 50 ix x Contents 1.5.4 AlternatingSeries . . . . . . . . . . . . . . . . . . . . . . 51 1.5.5 CoulombScatteringAmplitudeandBorelResummation . . 52 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 2 SolvingNon-linearEquations . . . . . . . . . . . . . . . . . . . . . . 57 2.1 ScalarEquations . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2.1.1 Bisection . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2.1.2 The Family of Newton’s Methods and the Newton– RaphsonMethod . . . . . . . . . . . . . . . . . . . . . . . 60 2.1.3 TheSecantMethodandItsRelatives . . . . . . . . . . . . 64 2.1.4 Müller’sMethod . . . . . . . . . . . . . . . . . . . . . . . 65 2.2 VectorEquations . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 2.2.1 Newton–Raphson’sMethod . . . . . . . . . . . . . . . . . 67 2.2.2 Broyden’s(Secant)Method . . . . . . . . . . . . . . . . . 69 2.3 ConvergenceAcceleration(cid:2) . . . . . . . . . . . . . . . . . . . . . 72 2.4 PolynomialEquationsofaSingleVariable . . . . . . . . . . . . . 73 2.4.1 LocatingtheRegionsContainingZeros . . . . . . . . . . . 75 2.4.2 Descartes’RuleandtheSturmMethod . . . . . . . . . . . 77 2.4.3 Newton’sSumsandinVièto’sFormulas . . . . . . . . . . 79 2.4.4 EliminatingMultipleZerosofthePolynomial . . . . . . . 80 2.4.5 ConditioningoftheComputationofZeros . . . . . . . . . 81 2.4.6 GeneralHintsfortheComputationofZeros . . . . . . . . 81 2.4.7 Bernoulli’sMethod . . . . . . . . . . . . . . . . . . . . . 82 2.4.8 Horner’sLinearMethod . . . . . . . . . . . . . . . . . . . 83 2.4.9 Bairstow’s(Horner’sQuadratic)Method . . . . . . . . . . 84 2.4.10 Laguerre’sMethod . . . . . . . . . . . . . . . . . . . . . . 87 2.4.11 Maehly–Newton–Raphson’sMethod . . . . . . . . . . . . 88 2.5 AlgebraicEquationsofSeveralVariables(cid:2) . . . . . . . . . . . . . 89 2.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 2.6.1 Wien’sLawandLambert’sFunction . . . . . . . . . . . . 94 2.6.2 Heisenberg’sModelintheMean-FieldApproximation . . . 96 2.6.3 EnergyLevelsof SimpleOne-DimensionalQuantum Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 2.6.4 PropaneCombustioninAir . . . . . . . . . . . . . . . . . 99 2.6.5 FluidFlowThroughSystemsofPipes. . . . . . . . . . . . 100 2.6.6 AutomatedAssemblyofStructures . . . . . . . . . . . . . 103 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 3 MatrixMethods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 3.1 BasicOperations . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 3.1.1 MatrixMultiplication . . . . . . . . . . . . . . . . . . . . 109 3.1.2 ComputingtheDeterminant . . . . . . . . . . . . . . . . . 111 3.2 SystemsofLinearEquationsAx=b . . . . . . . . . . . . . . . . 111 3.2.1 AnalysisofErrors . . . . . . . . . . . . . . . . . . . . . . 111 3.2.2 GaussElimination . . . . . . . . . . . . . . . . . . . . . . 113 3.2.3 SystemswithBandedMatrices . . . . . . . . . . . . . . . 115