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

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

Bild der Seite - 120 -

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

Text der Seite - 120 -

120 5 SomeMorePythonEssentials an object’s initial vertical velocity, and then computes height (as it develops with time),maximumheightandflightduration. Themoreflexibleversionofvertical_motion.py then reads, """ Module for computing vertical motion characteristics for a projectile. """ def y(v0, t): """ Compute vertical position at time t, given the initial vertical velocity v0. Assume negligible air resistance. """ g = 9.81 return v0*t - 0.5*g*t**2 def time_of_flight(v0): """ Compute time in the air, given the initial vertical velocity v0. Assume negligible air resistance. """ g = 9.81 return 2*v0/g def max_height(v0): """ Compute maximum height reached, given the initial vertical velocity v0. Assume negligible air resistance. """ g = 9.81 return v0**2/(2*g) def application(): import numpy as np import matplotlib.pyplot as plt import sys print("""This program computes vertical motion characteristics for a projectile. Given the intial vertical velocity, it computes height (as it develops with time), maximum height reached, as well as time of flight.""") try: v_initial = float(input(’Give the initial velocity: ’)) except: print(’You must give a valid number!’) sys.exit(1) H = max_height(v_initial) T = time_of_flight(v_initial) print(’Maximum height: {:g} m, \nTime of flight: {:g} s’.format(H, T)) # compute and plot position as function of time dt = 0.001 # just pick a "small" time step N = int(T/dt) # number of time steps t = np.linspace(0, N*dt, N+1)
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