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 - 20 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

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

Bild der Seite - 20 -

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

Text der Seite - 20 -

20 1 TheFirstFewSteps t = np.linspace(0, 1, 1001) y = v0*t - 0.5*g*t**2 plt.plot(t, y) # plots all y coordinates vs. all t coordinates plt.xlabel(’t (s)’) # places the text t (s) on x-axis plt.ylabel(’y (m)’) # places the text y (m) on y-axis plt.show() # displays the figure This program produces a plot of the vertical position with time, as seen in Fig.1.1. As you notice, the code lines fromtheball.pyprogramin Sect.1.2 have notchangedmuch,but theheight isnowcomputedandplottedfora thousandpoints in time! Let us take a closer look at this program. At the top, we recognize the import statements import numpy as np import matplotlib.pyplot as plt As we know by now, these statements imply that items from numpy and matplotlib.pyplotmustbe prefixedwithnpandplt, respectively. The linspaceFunction Next, there is a call to the functionlinspace from the numpy library. When n evenly spaced floating point numbers are sought on an interval [a,b],linspacemaygenerallybecalled like this: np.linspace(a, b, n) Thismeans that thecall t = np.linspace(0, 1, 1001) creates 1001 coordinates between 0 and 1, inclusive at both ends. The mathemati- cally inclined reader might agree that 1001 coordinates correspond to 1000 equal- Fig. 1.1 Plot generated by the script ball_plot.py showing the vertical position of the ball (computed for a thousand points in time)
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