lab1-extra¶
Topics: Python functions with more complicated application examples.
box_surface
re-iterates the concept of function
usage with less trivial equations.
distance
can be solved with an if-statement or the abs()
function.
impact_velocity
and fall_time
exercise the known Python concepts in the context of
engineering problems (might also appeal to people with interest in physics, space exploration, geophysics),
and relate to the mechanics of object’s in Earth’s gravitational field.
interval_point()
relates to linear interpolation as be found in data
analysis, data-based model descriptions, or finite element calculations.
distance(a, b)
¶
Write a function distance(a, b)
that returns the distance between
numbers a and b.
Examples:
In [ ]: distance(3, 4)
Out[ ]: 1
In [ ]: distance(3, 1)
Out[ ]: 2
Hints: One possible solution make use of the abs(x)
function in Python to compute
the absolute value of the number x
. Another solution involves a if
statement.
fall_time(h)
¶
Write a function fall_time(h)
that returns the time \(t\) (in
seconds) needed for an object falling from a tower of height \(h\)
(in meters) to hit the ground (ignoring air friction).
The relevant equation is
being the gravitational constant on the Earth’s surface. As we need to compute \(t(h)\), we solve the equation for \(t\):
Examples:
In [ ]: fall_time(10)
Out[ ]: 1.4278431229270645
In [ ]: fall_time(1)
Out[ ]: 0.4515236409857309
Meaning of the first example: an object falling from 10 meters height, falls for 1.43 seconds (rounded)
impact_velocity(h)
¶
Implement a function impact_velocity(h)
that returns the velocity
\(v\) (in metre per second) with which an object falling from a
height of \(h\) meters will hit the ground. Use \(v(t)=gt\),
with \(v(t)\) the velocity at time \(t\), and
\(g=9.81 \frac{\mathrm{m}}{\mathrm{s}^2}\).
You need to compute the fall time \(t\) from a given height
\(h\). You can re-use the fall_time
function you wrote earlier
to compute \(t(h)\).
Examples:
In [ ]: impact_velocity(0.1)
Out[ ]: 1.4007141035914503
In [ ]: impact_velocity(0.5)
Out[ ]: 3.132091952673165
In [ ]: impact_velocity(1)
Out[ ]: 4.4294469180700204
Please include the extra tasks in your file lab1.py
and submit as lab1 assignment.
Back to lab1.
End of lab1-extra.