Skip to content

Commit

Permalink
docs: document kinetic_energy constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumJHays committed Oct 26, 2022
1 parent 4154d4e commit 04990da
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mathpad/mech.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@

@mathpad_constructor
def kinetic_energy(*, m: X[Mass], v: X[Velocity]) -> Energy:
"Energy of a moving object"
return m * v ** 2 / 2 # type: ignore
"""
Calculate the kinetic energy of a particle.
Args:
m: Mass of the particle
v: Velocity of the particle
Returns:
Kinetic energy of the particle in joules
Example:
>>> kinetic_energy(m=1 * kg, v=2 * m/s)
2 joules
>>> kinetic_energy(m="m" * kg, v="v" * m/s)
0.5*mv**2 joules
"""
return (m * v ** 2 / 2).in_units(joules) # type: ignore


@mathpad_constructor
Expand Down

0 comments on commit 04990da

Please sign in to comment.