Page - 117 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 117 -
Text of the Page - 117 -
5.4 MakingOurOwnModule 117
DESCRIPTION
Module for computing vertical motion
characteristics for a projectile.
FUNCTIONS
max_height(v0)
Compute maximum height reached, given the initial vertical
velocity v0. Assume negligible air resistance.
time_of_flight(v0)
Compute time in the air, given the initial vertical
velocity v0. Assume negligible air resistance.
y(v0, t)
Compute vertical position at time t, given the initial vertical
velocity v0. Assume negligible air resistance.
We recognize thedocstrings in theprintoutandshould realize that it is agood idea
tokeep thosedocstrings informative.
With the following interactive session, comparing the answers to hand calcula-
tions (using the formulasand a calculator),we confirm that the modulenow seems
toworkas intended,
In [1]: import vertical_motion as vm
In [2]: vm.y(v0=5, t=0.6)
Out[2]: 1.2342
In [3]: vm.time_of_flight(v0=5)
Out[3]: 1.019367991845056
In [4]: vm.max_height(v0=5)
Out[4]: 1.27420998980632
We now have a useful version of our own vertical motion module, from which
imports work just like from built-in modules. Still, there is room for useful
modifications,aswe will turn tonext.
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