Example: stock market

Physics Simulations in Python

Physics Simulations in PythonA Lab ManualDaniel V. SchroederPhysics DepartmentWeber State UniversityAugust 2021 Copyrightc 2018 2021, Daniel V. fromPhysics Simulations in Java, copyrightc 2005 work is licensed under the Creative Commons Attribution Interna-tional License. To view a copy of this license, send a letter to Creative Commons, PO Box 1866,Mountain View, CA 94042, can obtain the latest version of this manual There you can also find the LATEX source and il-lustration files, to facilitate adapting this manual to different .. ivProject 1: Making Shapes .. 1 Project 2: Projectile Motion .. 11 Project 3: Pendulum.

ruler, and a small three-ring binder to hold this manual. How to use this manual This manual is divided into six main chapters, corresponding to six separate projects. In each project you will write a computer program or (more often) a small number of closely related computer programs. Rather than giving you complete programs to

Tags:

  Manual, Binder

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Physics Simulations in Python

1 Physics Simulations in PythonA Lab ManualDaniel V. SchroederPhysics DepartmentWeber State UniversityAugust 2021 Copyrightc 2018 2021, Daniel V. fromPhysics Simulations in Java, copyrightc 2005 work is licensed under the Creative Commons Attribution Interna-tional License. To view a copy of this license, send a letter to Creative Commons, PO Box 1866,Mountain View, CA 94042, can obtain the latest version of this manual There you can also find the LATEX source and il-lustration files, to facilitate adapting this manual to different .. ivProject 1: Making Shapes .. 1 Project 2: Projectile Motion .. 11 Project 3: Pendulum.

2 25 Project 4: Orbits .. 35 Project 5: Molecular Dynamics .. 47 Project 6: Random Processes .. 61 Project 7: Final Project .. 73iiiPrefaceIntroductory Physics courses are full of simplifications: projectiles fly without airresistance, pendulums swing only at small angles, orbits are always circular, andno more than two particles move at any time. These kinds of simplifications arenecessary and appropriate when you re first trying to understand the basic laws ofnature. But the real world is far more complex, and far more interesting. Becausethe ultimate goal of Physics is to understand the real world, students deserve acourse that applies the laws of Physics to more complex , modern electronic computers make it possible to perform extremelylengthy calculations in a negligible amount of time.

3 These days, therefore, com-puters offer the best avenue toward applying the basic laws of nature to complexand realistic physical systems. A computer program that models the behavior ofa physical system is called acomputer simulation. Creating and using computersimulations is an integral part of modern science and manual is intended for a hands-on introductory course in computer simu-lations of physical systems, using the Python programming language. The goals ofthe course are as follows: Learn enough of the Python language and the VPython and matplotlib graph-ics packages to write programs that do numerical calculations with graphicaloutput; Learn some step-by-step procedures for doing mathematical calculations (suchas solving differential equations) on a computer; Gain a better understanding of Newton s laws and other physical principles.

4 Study a variety of physical systems that are too complex for simple pencil-and-paper calculations, and see what sorts of behavior emerge in such working through the projects in this manual you should have completed asemester of introductory Physics , covering Newton s laws of motion, conservationprinciples, and a bit of thermodynamics. You should also have taken at least onesemester of calculus. Prior expertise in writing computer programs isnotrequired,but you should be fairly comfortable using a web browser, word processor, andspreadsheet, and you should have some experience at being careful with computersyntax (in any programming language).

5 IvPrefacevRequired materialsNaturally, you ll need a computer. The first five projects use a cloud-based versionof Python called GlowScript, so for those you can use any computer with an internetconnection and a modern web browser. (A tablet device without a physical keyboardis not adequate.) For Project 6, you may need to install a free version of the Pythonlanguage and environment (if you re not using a computer on which it is installedalready).Your GlowScript programs will be automatically saved on Google s servers, butfor any other files you ll need to use either some other type of cloud storage or aUSB memory stick for pocket calculator (perhaps on your mobile phone) will sometimes come , you ll need a few low-tech materials such as scratch paper, pencils, aruler, and a small three-ring binder to hold this to use this manualThis manual is divided into six main chapters, corresponding to six separate each project you will write a computer program or (more often) a small numberof closely related computer programs.

6 Rather than giving you complete programs torun, the project instructions will provide only code fragments and general guidelineson how to write your programs. This way, once you have completed each program,it will be you create your computer programs, you will inevitably have questions andencounter difficulties. While you should try to think things through for yourselfwhenever possible, don t spend too much time being stuck and getting your instructor or your lab partner or your other classmates for help. This isnot a and questions will be sprinkled among the instructions in this manual ,with space for you to write your answers.

7 Please make every effort to work eachexercise and answer each question immediately, before you read general premise of this manual is that you ll learn more bytryingsome-thing than by reading a comprehensiveexplanationof it. Computer languages arelike ordinary languages in this respect: We normally learn new words by hearing,reading, and using them in context, not by studying a dictionary. But if you wantto see a term clearly defined, feel free to ask your instructor or look it up programming is fun because it s so open-ended. You ll constantlythink of things to try that go beyond the explicit instructions. By all means, tryanything you want!

8 If you re not sure how to add a certain feature to one of yoursimulations, or if you re not sure whether it s practical to do so within a limitedamount of time, be sure to ask your you finish a project, gather the instruction pages and staple them togetherwith any printed output from your programs. This stapled packet, together withviPrefacethe source code of your computer programs, will be your lab report. What this manual is notThis manual is not a comprehensive introduction to the Python programming lan-guage. Many features of the language are not needed for the types of simulationswe ll be doing, so we ll ignore them.

9 Several other features will be used once ortwice but never fully distributions of Python come with dozens of packages (libraries) forcarrying out a wide variety of common tasks. This manual will describe only a tinyfraction of some point you might want to distribute your finished Python programs asweb apps or stand-alone applications. This manual won t tell you how to do ve tried to design the examples in this manual to illustrate good programmingpractices that are appropriate to the relatively small scale of the projects. This isnot a treatise on the principles of professional software manual is not a textbook on numerical analysis, nor is it a reference workon numerical algorithms.

10 We ll try out just a few algorithms, make some crudecomparisons, and leave it at projects in this manual touch on some fascinating fields of Physics , includingnonlinear dynamics, celestial mechanics, and phase transformations. But this is nota textbook on any of these most importantly, this manual is not intended to be of any use what-soever to someone who merely reads it without actually working through all of theprojects and Python , VPython, and GlowScript?Choosing a computer programming language always involves trade-offs. Fortu-nately, there are more choices today than ever obvious choice for this course would be one of the traditional computerlanguages like Fortran, C, or C++.


Related search queries