ebook img

Numerical Methods in Physics with Python PDF

605 Pages·2020·6.508 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 Numerical Methods in Physics with Python

NumericalMethodsinPhysicswithPython Bringing together idiomatic Python programming, foundational numerical methods, and physics applications, this is an ideal standalone textbook for courses on computational physics. All the frequently used numerical methods in physics are explained, including foundational techniques and hidden gems on topics such as linear algebra, differential equations, root-finding, interpolation, and integration. Accompanying the mathematical derivationsarefullimplementationsofdozensofnumericalmethodsinPython,aswellas more than 250 end-of-chapter problems. Numerical methods and physics examples are clearly separated, allowing this introductory book to be later used as a reference; the penultimatesectionineachchapterisanin-depthproject,tacklingphysicsproblemsthat cannot be solved without the use of a computer. Written primarily for students studying computational physics, this textbook brings the non-specialist quickly up to speed with Pythonbeforelookingindetailatthenumericalmethodsoftenusedinthesubject. AlexGezerlisisAssociateProfessorofPhysicsattheUniversityofGuelph.Beforemoving toCanada,heworkedinGermany,theUnitedStates,andGreece.Hehasreceivedseveral research awards, grants, and allocations on supercomputing facilities and is active in teachingatbothundergraduateandgraduatelevels. “I enthusiastically recommend Numerical Methods in Physics with Python by Professor Gezerlis to any advanced undergraduate or graduate student who would like to acquire a solid understanding of the basic numerical methods used in physics. The methods are demonstrated with Python, a relatively compact, accessible computer language, allowing thereadertofocusonunderstandinghowthemethodsworkratherthanonhowtoprogram them.Eachchapteroffersaself-contained,clear,andengagingpresentationoftherelevant numerical methods, and captivates the reader with well-motivated physics examples and interesting physics projects. Written by a leading expert in computational physics, this outstandingtextbookisuniqueinthatitfocusesonteachingbasicnumericalmethodswhile also including a number of modern numerical techniques that are usually not covered in computationalphysicstextbooks.” YoramAlhassid,YaleUniversity “InNumericalMethodsinPhysicswithPythonbyGezerlis,onefindsaresourcethathas been sorely missing! As the usage of Python has become widespread, it is too often the case that students take libraries, functions, and codes and apply them without a solid understandingofwhatistrulybeingdone‘underthehood’andwhy.Gezerlis’bookfills thisgapwithclarityandrigorbycoveringabroadnumberoftopicsrelevantforphysics, describing the underlying techniques and implementing them in detail. It should be an importantresourceforanyoneapplyingnumericaltechniquestostudyphysics.” LuisLehner,PerimeterInstitute “Gezerlis’texttakesavenerablesubject–numericaltechniquesinphysics–andbringsit up to date and makes it accessible to modern undergraduate curricula through a popular, open-source programming language. Although the focus remains squarely on numerical techniques,eachnewlessonismotivatedbytopicscommonlyencounteredinphysicsand concludes with a practical hands-on project to help cement the students’ understanding. The net result is a textbook which fills an important and unique niche in pedagogy and scope,aswellasavaluablereferenceforadvancedstudentsandpracticingscientists.” BrianMetzger,ColumbiaUniversity Numerical Methods in Physics with Python ALEX GEZERLIS UniversityofGuelph UniversityPrintingHouse,CambridgeCB28BS,UnitedKingdom OneLibertyPlaza,20thFloor,NewYork,NY10006,USA 477WilliamstownRoad,PortMelbourne,VIC3207,Australia 314–321,3rdFloor,Plot3,SplendorForum,JasolaDistrictCentre,NewDelhi–110025,India 79AnsonRoad,#06–04/06,Singapore079906 CambridgeUniversityPressispartoftheUniversityofCambridge. ItfurtherstheUniversity’smissionbydisseminatingknowledgeinthepursuitof education,learning,andresearchatthehighestinternationallevelsofexcellence. www.cambridge.org Informationonthistitle:www.cambridge.org/9781108488846 DOI:10.1017/9781108772310 ©AlexandrosGezerlis2020 Thispublicationisincopyright.Subjecttostatutoryexception andtotheprovisionsofrelevantcollectivelicensingagreements, noreproductionofanypartmaytakeplacewithoutthewritten permissionofCambridgeUniversityPress. Firstpublished2020 PrintedintheUnitedKingdombyTJInternationalLtd,PadstowCornwall AcataloguerecordforthispublicationisavailablefromtheBritishLibrary. ISBN978-1-108-48884-6Hardback ISBN978-1-108-73893-4Paperback Additionalresourcesforthispublicationatwww.cambridge.org/gezerlis CambridgeUniversityPresshasnoresponsibilityforthepersistenceoraccuracy ofURLsforexternalorthird-partyinternetwebsitesreferredtointhispublication anddoesnotguaranteethatanycontentonsuchwebsitesis,orwillremain, accurateorappropriate. For Marcos Ahumanisashadow’sdream. Butwhenradiancefromtheheavenscomes, aglowingsplendoruponmankind,andserenelife. Pindar Contents Preface pagexiii Listofcodes xvii 1 IdiomaticPython 1 1.1 WhyPython? 2 1.2 CodeQuality 3 1.3 SummaryofPythonFeatures 4 1.3.1 Basics 4 1.3.2 ControlFlow 5 1.3.3 DataStructures 6 1.3.4 User-DefinedFunctions 8 1.4 Core-PythonIdioms 10 1.4.1 ListComprehensions 10 1.4.2 IteratingIdiomatically 11 1.5 BasicPlottingwithmatplotlib 13 1.6 NumPyIdioms 15 1.7 Project:VisualizingElectricFields 21 1.7.1 ElectricFieldofaDistributionofPointCharges 21 1.7.2 PlottingFieldLines 22 1.8 Problems 25 2 Numbers 28 2.1 Motivation 28 2.2 Errors 29 2.2.1 AbsoluteandRelativeError 30 2.2.2 ErrorPropagation 32 2.3 RepresentingRealNumbers 38 2.3.1 Basics 38 2.3.2 Overflow 39 2.3.3 MachinePrecision 40 2.3.4 RevisitingSubtraction 41 2.3.5 ComparingFloats 44 2.4 RoundingErrorsintheWild 45 2.4.1 AreRoundoffErrorsRandom? 45 2.4.2 CompensatedSummation 47 2.4.3 NaivevsManipulatedExpressions 49 vii viii Contents 2.4.4 ComputingtheExponentialFunction 50 2.4.5 AnEvenWorseCase:Recursion 55 2.4.6 WhenRoundingErrorsCancel 58 2.5 Project:theMultipoleExpansioninElectromagnetism 60 2.5.1 PotentialofaDistributionofPointCharges 60 2.5.2 ExpansionforOnePointCharge 65 2.5.3 ExpansionforManyPointCharges 71 2.6 Problems 76 3 Derivatives 85 3.1 Motivation 85 3.1.1 ExamplesfromPhysics 85 3.1.2 TheProblemtoBeSolved 86 3.2 AnalyticalDifferentiation 86 3.3 FiniteDifferences 87 3.3.1 Noncentral-DifferenceApproximations 87 3.3.2 Central-DifferenceApproximation 91 3.3.3 Implementation 93 3.3.4 MoreAccurateFiniteDifferences 95 3.3.5 SecondDerivative 96 3.3.6 PointsonaGrid 97 3.3.7 RichardsonExtrapolation 101 3.4 AutomaticDifferentiation 105 3.4.1 DualNumbers 105 3.4.2 AnExample 106 3.4.3 SpecialFunctions 107 3.5 Project:LocalKineticEnergyinQuantumMechanics 109 3.5.1 Single-ParticleWaveFunctionsinOneDimension 109 3.5.2 SecondDerivative 114 3.6 Problems 117 4 Matrices 121 4.1 Motivation 121 4.1.1 ExamplesfromPhysics 121 4.1.2 TheProblemstoBeSolved 123 4.2 ErrorAnalysis 125 4.2.1 FromaposterioritoaprioriEstimates 126 4.2.2 MagnitudeofDeterminant? 127 4.2.3 NormsforMatricesandVectors 129 4.2.4 ConditionNumberforLinearSystems 131 4.2.5 ConditionNumberforSimpleEigenvalues 135 4.2.6 SensitivityofEigenvectors 141 4.3 SolvingSystemsofLinearEquations 146 4.3.1 TriangularMatrices 147 Contents ix 4.3.2 GaussianElimination 152 4.3.3 LUMethod 159 4.3.4 Pivoting 165 4.3.5 JacobiIterativeMethod 171 4.4 Eigenproblems 175 4.4.1 PowerMethod 177 4.4.2 Inverse-PowerMethodwithShifting 181 4.4.3 QRMethod 187 4.4.4 AllEigenvaluesandEigenvectors 204 4.5 Project:theSchro¨dingerEigenvalueProblem 206 4.5.1 OneParticle 206 4.5.2 TwoParticles 211 4.5.3 ThreeParticles 223 4.5.4 Implementation 226 4.6 Problems 233 5 Roots 243 5.1 Motivation 243 5.1.1 ExamplesfromPhysics 243 5.1.2 TheProblem(s)toBeSolved 244 5.2 NonlinearEquationinOneVariable 246 5.2.1 Conditioning 247 5.2.2 OrderofConvergenceandTerminationCriteria 248 5.2.3 Fixed-PointIteration 250 5.2.4 BisectionMethod 256 5.2.5 Newton’sMethod 260 5.2.6 SecantMethod 265 5.2.7 Ridders’Method 269 5.2.8 SummaryofOne-DimensionalMethods 272 5.3 ZerosofPolynomials 272 5.3.1 Challenges 273 5.3.2 OneRootataTime:Newton’sMethod 274 5.3.3 AlltheRootsatOnce:EigenvalueApproach 277 5.4 SystemsofNonlinearEquations 279 5.4.1 Newton’sMethod 280 5.4.2 DiscretizedNewtonMethod 282 5.4.3 Broyden’sMethod 283 5.5 Minimization 287 5.5.1 One-DimensionalMinimization 287 5.5.2 MultidimensionalMinimization 289 5.5.3 GradientDescent 292 5.5.4 Newton’sMethod 295 5.6 Project:ExtremizingtheActioninClassicalMechanics 297 5.6.1 DefiningandExtremizingtheAction 297

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.