Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - 19 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 19 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 19 -

Image of the Page - 19 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 19 -

1.5 APythonProgramwithVectorizationandPlotting 19 Here,pyplot is a module in thematplotlibpackage15 that is namedpltwhen imported.Thus,whenimportedthisway,all itemsfrompyplotmusthavetheprefix plt.Wewill sticktothis importandnamingstandardforpyplotalsoin thepresent book,wheneverplotting is on the agenda. 1.4.5 TheModules/PackagesUsedinThisBook Somereadersmightbe curious to knowwhich librariesare used in thisbook(apart fromthemoduleswe makeourselves).Well, here theyare: • math—see,e.g.,ball_angle.py,Sect.1.3. • numpy—see,e.g.,check_functions.pyabove. • matplotlib.pyplot—see,e.g.,ball_plot.py,Sect.1.5. • random—see,e.g.,throw_2_dice.py inSect.2.4. • sympy—see,e.g.,Sect.5.3. • timeit—see,e.g.,Sect.5.6. • sys—see,e.g.,Sect.7.2.2. These libraries are all well known to Python programmers. The three first ones (math, numpy and matplotlib.pyplot) are used repeatedly throughout the text, while the remaining ones (random, sympy, timeit and sys) appear just occasionally. Not listed, are two modules that are used just once each, thekeywordmodule (Sect.2.2) and theosmodule (Sect.9.2.4). It shouldbe mentioned that we also use a package calledodespy (Sect.8.4.6), previously developed by one of the authors (Langtangen). 1.5 APythonProgramwithVectorizationandPlotting Wereturn to theproblemwhereaball is thrownupin theairandwehavea formula fortheverticalpositionyoftheball.Sayweareinterestediny ateverymilli-second for the first second of the flight. This requires repeating the calculation of y = v0t−0.5gt2 one thousandtimes.Aswewill see, thecomputedheightsappearvery informativewhen presentedgraphicallywith time, as opposed to a long printoutof all the numbers. The Program In Python, the calculations and the visualization of the curve may bedonewith theprogramball_plot.py, reading import numpy as np import matplotlib.pyplot as plt v0 = 5 g = 9.81 15 The matplotlib package (https://matplotlib.org/) comes with Anaconda. If you have not installedAnaconda, you may have to installmatplotlib separately.
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python