-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Added the algorithm to compute the terminal velocity of an object fal… #10237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tianyizheng02
merged 6 commits into
TheAlgorithms:master
from
pluto-tofu:terminal_velocity
Oct 23, 2023
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e4f652
added the algorithm to compute the terminal velocity of an object fal…
pluto-tofu 71f3534
fixed spelling mistake
pluto-tofu e21bbaa
fixed issues in topic description
pluto-tofu 0ca5e82
imported the value of g from scipy and changed the doctests accordingly
pluto-tofu 2cd825f
fixed formatting
pluto-tofu c806605
Apply suggestions from code review
tianyizheng02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from scipy.constants import g | ||
|
||
""" | ||
Title : Computing the terminal velocity of an object falling | ||
through a fluid. | ||
|
||
Terminal velocity is defined as the highest velocity attained by an | ||
object falling through a fluid. It is observed when the sum of drag force | ||
and buoyancy is equal to the downward gravity force acting on the | ||
object. The acceleration of the object is zero as the net force acting on | ||
the object is zero. | ||
|
||
Vt = ((2 * m * g)/(ρ * A * Cd))^0.5 | ||
|
||
where : | ||
Vt = Terminal velocity (in m/s) | ||
m = Mass of the falling object (in Kg) | ||
g = Acceleration due to gravity (value taken : imported from scipy) | ||
ρ = Density of the fluid through which the object is falling (in Kg/m^3) | ||
A = Projected area of the object (in m^2) | ||
Cd = Drag coefficient (dimensionless) | ||
|
||
Reference : https://byjus.com/physics/derivation-of-terminal-velocity/ | ||
""" | ||
|
||
|
||
def terminal_velocity( | ||
mass: float, density: float, area: float, drag_coefficient: float | ||
) -> float: | ||
""" | ||
>>> terminal_velocity(1, 25, 0.6, 0.77) | ||
1.3031197996044768 | ||
>>> terminal_velocity(2, 100, 0.45, 0.23) | ||
1.9467947148674276 | ||
>>> terminal_velocity(5, 50, 0.2, 0.5) | ||
4.428690551393267 | ||
>>> terminal_velocity(-5, 50, -0.2, -2) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: mass, density, area and the drag coefficient all need to be positive | ||
>>> terminal_velocity(3, -20, -1, 2) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: mass, density, area and the drag coefficient all need to be positive | ||
>>> terminal_velocity(-2, -1, -0.44, -1) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: mass, density, area and the drag coefficient all need to be positive | ||
""" | ||
if mass <= 0 or density <= 0 or area <= 0 or drag_coefficient <= 0: | ||
raise ValueError( | ||
"mass, density, area and the drag coefficient all need to be positive" | ||
) | ||
return ((2 * mass * g) / (density * area * drag_coefficient)) ** 0.5 | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.