ebook img

Introduction to Computation in Physical Sciences: Interactive Computing and Visualization with Python™ PDF

264 Pages·2023·3.896 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 Introduction to Computation in Physical Sciences: Interactive Computing and Visualization with Python™

Synthesis Lectures on Computation and Analytics Jay Wang Adam Wang Introduction to Computation in Physical Sciences Interactive Computing and Visualization with PythonTM Synthesis Lectures on Computation and Analytics This series focuses on advancing education and research at the interface of qualitative analysisandquantitativesciences.Currentchallengesandnewopportunitiesareexplored with an emphasis on the integration and application of mathematics and engineering to createcomputationalmodelsforunderstandingandsolvingreal-worldcomplexproblems. Appliedmathematical,statistical,andcomputationaltechniquesareutilizedtounderstand the actions and interactions of computational and analytical sciences. Various perspec- tives on research problems in data science, engineering, information science, operations research, and computational science, engineering, and mathematics are presented. The techniques and perspectives are designed for all those who need to improve or expand their use of analytics across a variety of disciplines and applications. Jay Wang · Adam Wang Introduction to Computation in Physical Sciences Interactive Computing and Visualization with Python™ JayWang AdamWang Dartmouth,MA,USA Nashville,TN,USA ISSN2766-8975 ISSN2766-8967 (electronic) SynthesisLecturesonComputationandAnalytics ISBN978-3-031-17645-6 ISBN978-3-031-17646-3 (eBook) https://doi.org/10.1007/978-3-031-17646-3 ©TheEditor(s)(ifapplicable)andTheAuthor(s),underexclusivelicensetoSpringerNatureSwitzerlandAG 2023 Thisworkissubjecttocopyright.AllrightsaresolelyandexclusivelylicensedbythePublisher,whetherthewhole orpartofthematerialisconcerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation, broadcasting,reproductiononmicrofilmsorinanyotherphysicalway,andtransmissionorinformationstorage andretrieval,electronicadaptation,computersoftware,orbysimilarordissimilarmethodologynowknownor hereafterdeveloped. Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublicationdoes notimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevantprotective lawsandregulationsandthereforefreeforgeneraluse. Thepublisher,theauthors,andtheeditorsaresafetoassumethattheadviceandinformationinthisbookare believedtobetrueandaccurateatthedateofpublication.Neitherthepublishernortheauthorsortheeditorsgive awarranty,expressedorimplied,withrespecttothematerialcontainedhereinorforanyerrorsoromissionsthat mayhavebeenmade.Thepublisherremainsneutralwithregardtojurisdictionalclaimsinpublishedmapsand institutionalaffiliations. ThisSpringerimprintispublishedbytheregisteredcompanySpringerNatureSwitzerlandAG Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland Preface This book introduces computation and modeling of problems in physical sciences with emphasisoninteractivejust-in-timecomputing,dataanalysis,andeffectivevisualization. Computational modeling has long been an established practice in science and engi- neering and is regarded as the third pillar alongside experimentation and theory. It is also becoming increasingly inseparable and integral in a wide range of industry sectors. In education, computational thinking—broadly construed as the mindset and skillset of problem-solvingwithcomputationalmethodologiesincludingmodeling,abstraction,sym- bolic and algorithmic representations, and numeric processing—is being embraced as a standard component, and even a requirement, at all levels.1 Experience and evidence from physics educators and physics education research have shown that computation and integration thereof into physics has many positive ben- efits including increasing student engagement, active learning, and improved learning outcomes and understanding. However, there are also well-documented challenges to effective implementation in terms of pedagogical consideration and practical constraints. We developed this book with the goal of lowering such barriers. In terms of coverage, wehavecarefullyselectedasetoftopics,drawnfromexperienceandbestpracticeinthe physics education community, that is pedagogically significant and also reflective of the current trend in academia and in industry. In terms of access to computing resources, we have adopted a COD (computing on demand) and JIT-C (just-in-time computing) model wherenearlyallprogramsarecloud-based,requiringnosoftwareinstallationofanykind for easily accessing or running them in a web browser on any machine, especially on mobile devices. Running a simulation, or sharing one, is just a click away. We designed most programs as minimally working programs (MWP) as part of intentional scaffolding to help beginners develop computational problem-solving and thinking skills. MWPs are effective pedagogically to teaching and learning computational modeling. They may be used as basis templates to be modified, extended, or combined for further exploration in projects and exercises. 1SeeJ.M.Wing,Computationalthinking, CommunicationsoftheACM,49,33–35(2006). vii viii Preface The book is broadly organized into two parts. Part one consists of Chaps. 1 to 4 and describes basic programming and tools, including programming environments, Python tutorial, interactive computing, and elementary algorithms. Part two includes Chaps. 5 to 9andfocusesonapplicationofcomputationalmodelingofselectproblemsinfundamental areasofphysicalanddatascienceincludingclassicalmechanics,modernphysics,thermal andcomplexsystems,aswellasfromcontemporarytopicsincludingquantumcomputing, neural networks and machine learning, and global warming and energy balance. The materials are arranged as follows. In Chap. 1, we introduce programming and development environments including Jupyter notebook—the recommended environment, its cloud-based counterpart Binder, a close variant Colab, the native Python IDLE—inte- grated development and learning environment, Spyder, and sharing-friendly GlowScript and Trinket. We also describe the online program repository, how to access and run programs in the cloud, and optional software installation to run programs locally. An interactive Python tutorial is given in Chap. 2 on basic programming elements, including the important aspect of error handling, debugging, and troubleshooting. Next, Chap. 3 focuses on interactive computing and visualization methods with Python widgets and VPython animation libraries. Key scientific computing libraries are also described with interactive examples including symbolic and numeric computation with Sympy, Numpy, Scipy,aswellasNumbaforoptimization.Roundingoutpartone,weintroduceinChap.4 common elementary algorithms such as finite difference, numerical integration including that of differential equations, finding of roots and minima or maxima, and curve fitting. We begin part two with Chap. 5 on force and motion where we pedagogically intro- duce kinematic concepts, and discuss projectile motion with and without air resistance, harmonic oscillation, planetary motion, and motion in electromagnetic fields. In Chap. 6 we discuss classical coupled oscillations and wave propagation and introduce linear sys- tems and fundamental modes, leading up to simulations of matter waves in modern and quantum physics next in Chap. 7 where we consider relativity of space and time, diffractionanddouble-slitinterference,formationofdiscretequantumstatesanditsvisu- alization. We also introduce quantum information processing and quantum computing withaninteractivequantumsimulatorandastep-by-stepwalkthroughofanontrivialreal- world example: quantum search—the Grover algorithm. We consider random processes and thermal physics in Chap. 8 such as nuclear decay, Brownian motion, Monte Carlo simulations of thermal energy distribution and spin systems. We close the chapter with a discussion of greenhouse effect, energy balance, and global warming. Lastly, we discuss complex systems in Chap. 9 including cellular automata, traffic modeling, and nonlinear dynamics and chaos. We conclude with an introduction to neutral network and machine learning, and describe a worked example with details in the training and prediction of game of life. Intermsofbackgroundandpreparation,readerswithoutpriorprogrammingexperience shouldstartwithpartone,focusingontheinteractivetutorial(Chap.2)andmovingonto Pythonlibraries(Chap.3)andbasicalgorithms(Chap.4).Togetthemostoutofparttwo, Preface ix thereadershouldbecalculus-ready,havingstudiedprecalculusifnotcalculusalready.We took care to make the book as self-contained as possible in terms of explaining physical concepts necessary for a particular simulation. Even so, a basic understanding of physics atintroductorylevelisveryhelpfulsuchasfamiliaritywithbasicconceptsofmotionand Newton’s second law. We recommend covering Chap. 5, not necessarily in its entirety, before Chap. 6. The other individual chapters are sufficiently decoupled from each other that they may be used as separate modules and studied independently. Integraltothemaincontent,thebookcontainsextensivesetsofcarefullydesignedand testedexercisesattheendofeachchapter.MostexercisesarecloselyrelatedtotheMWPs discussedinthemaintext,andcanbeusedforfurtherexplorationofagivenproblem,as projectassignmentsorself-pacedstudy.Exercisesvaryindepthanddifficultylevels,and the more challenging ones are marked by asterisks. We thank Susanne Filler, Executive Editor at Springer Nature, and her team for the assistance and timely guidance in this project. JW is grateful to his colleagues at UMass DartmouthandinthePICUPcommunity(PartnershipforIntegrationofComputationinto Undergraduate Physics, http://gopicup.org) for their support and inspiration; and to the countless students who participated in research projects or through coursework and pro- vided feedback in various ways: you have had more impact on this project than you ever knew. Finally, we are fortunate to have the unwavering encouragement, understanding, and patience of our loved ones: Huihua, Kathy, and Greg. Thank you. Dartmouth, USA Jay Wang Nashville, USA Adam Wang Contents 1 ProgrammingEnvironments .......................................... 1 1.1 Jupyter Notebook Environments .................................. 1 1.1.1 Jupyter Notebook ........................................ 1 1.1.2 Colaboratory ............................................ 4 1.2 Integrated Development Environments ............................. 4 1.2.1 IDLE .................................................. 5 1.2.2 Spyder ................................................. 5 1.3 GlowScript and Trinket .......................................... 6 1.4 Program Access and Installation .................................. 8 2 PythonTutorial ...................................................... 11 2.1 Python as a Calculator ........................................... 11 2.1.1 Arithmetic Operators ..................................... 11 2.1.2 Types of Numbers ....................................... 12 2.2 Variables ....................................................... 13 2.2.1 Assigning Variables ...................................... 13 2.2.2 Variable Names ......................................... 14 2.3 Comments ..................................................... 14 2.4 Text Strings .................................................... 15 2.4.1 Syntax ................................................. 15 2.4.2 String Operations and Indexing ............................ 16 2.5 Functions ...................................................... 17 2.5.1 Defining Custom Functions ............................... 17 2.5.2 Variable Scope .......................................... 19 2.5.3 Default Argument Values and Keyword Arguments .......... 20 2.6 Conditional Statements .......................................... 20 2.6.1 Comparison and Logical Operators ........................ 21 2.6.2 if Statements ........................................... 21 xi

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.