Skip to content

Commit 6e4f652

Browse files
committed
added the algorithm to compute the terminal velocity of an object falling in a fluid
1 parent 788e4ed commit 6e4f652

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Diff for: physics/terminal_velocity.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Terminal velocity is defined as the highest velocity attained by an
3+
object falling through a fluid. It is observed when the sum of drag force
4+
and buoyancy is equal to the downward gravity force acting on the
5+
object. The acceleration of the object is zero as the net force acting on
6+
the object is zero.
7+
8+
Vt = ((2 * m * g)/(ρ * A * Cd))^0.5
9+
10+
where :
11+
Vt = Terminal velocity (in m/s)
12+
m = Mass of the falling object (in Kg)
13+
g = Acceleration due to gravity (value taken : 9.8 m/s^2)
14+
ρ = Density of the fluid through which the object is falling (in Kg/m^3)
15+
A = Projected area of the object (in m^2)
16+
Cd = Drag coefficient (dimensionless)
17+
"""
18+
19+
20+
def terminal_velocity(
21+
mass: float, density: float, area: float, drag_coefficient: float
22+
) -> float:
23+
"""
24+
>>> terminal_velocity(1, 25, 0.6, 0.77)
25+
1.3026778945578592
26+
>>> terminal_velocity(2, 100, 0.45, 0.23)
27+
1.9461345311993645
28+
>>> terminal_velocity(5, 50, 0.2, 0.5)
29+
4.427188724235731
30+
>>> terminal_velocity(-5, 50, -0.2, -2)
31+
Traceback (most recent call last):
32+
...
33+
ValueError: mass, density, area and the drag coeffiecient all need to be positive
34+
>>> terminal_velocity(3, -20, -1, 2)
35+
Traceback (most recent call last):
36+
...
37+
ValueError: mass, density, area and the drag coeffiecient all need to be positive
38+
>>> terminal_velocity(-2, -1, -0.44, -1)
39+
Traceback (most recent call last):
40+
...
41+
ValueError: mass, density, area and the drag coeffiecient all need to be positive
42+
"""
43+
if mass <= 0 or density <= 0 or area <= 0 or drag_coefficient <= 0:
44+
raise ValueError(
45+
"mass, density, area and the drag coeffiecient all need to be positive"
46+
)
47+
return ((2 * mass * 9.8) / (density * area * drag_coefficient)) ** 0.5
48+
49+
50+
if __name__ == "__main__":
51+
import doctest
52+
53+
doctest.testmod()

0 commit comments

Comments
 (0)