Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 5 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 5 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 5 -

Bild der Seite - 5 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 5 -

1.2 APythonProgramwithVariables 5 To download Anaconda, you must pick the Anaconda version suitable for your machine (Windows/Mac/Linux) and choose which version of Python you want (3.6 is used for this book). When the download has completed, proceed with the installationofAnaconda. After installation, you may want to (search for and) start up Spyder to see what it looks like (see also Appendix A). Spyder is an excellent tool for developing Pythoncode.So,unlessyouhavegoodreasonstochooseotherwise,werecommend Spyder tobeyourmain“working”environment,meaningthat to read,writeandrun code you start Spyder and do it there. Thus, it is a good idea to make Spyder easy accessibleonyourmachine. With Anaconda installed, the only additional package you need to install is Odespy.3 Odespy is relevant for thesolvingofdifferentialequations thatwetreat in Chaps.8and9. In Appendix A you will find more information on the installation and use of Python. 1.2 APythonProgramwithVariables Our first example regards programming a mathematical model that predicts the height of a ball thrown straight up into the air. From Newton’s 2nd law, and by assuming negligible air resistance, one can derive a mathematical model that predicts theverticalpositiony of the ball at time t: y=v0t−0.5gt2. Here,v0 is the initialupwardsvelocityandg is theaccelerationofgravity,forwhich 9.81ms−2 is a reasonable value (even if it depends on things like location on the earth). With this formula at hand, and when v0 is known, you may plug in a value for timeandgetout thecorrespondingheight. 1.2.1 TheProgram Letusnext lookat aPythonprogramforevaluating this simple formula.Todo this, we need some values for v0 and t, so we pick v0 = 5ms−1 and t = 0.6s (other choiceswouldof coursehave been just as good).Assume the programis contained as text inafile namedball.py, reading # Program for computing the height of a ball in vertical motion v0 = 5 # Initial velocity g = 9.81 # Acceleration of gravity 3 The original version of Odespy (https://github.com/hplgit/odespy) was written in Python 2.7 by H.P. Langtangen and L. Wang. However, since the sad loss of Prof. Langtangen in 2016, Ode- spy has been updated to Python 3.6 (https://github.com/thomasantony/odespy/tree/py36/odespy), thanks to Thomas Antony. Thisversion is theone used herein.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python