Skip to content

Fixes #9191 - Energy Mass Equivalence #9202

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions physics/energy_mass_equivalence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Calculates the energy equivalent (in J) of a given mass (in kg).

- In physics, mass–energy equivalence is the relationship between mass and energy in a system's rest frame.
- The two quantities differ only by a multiplicative constant and the units of measurement.
- The principle is described by the physicist Albert Einstein's formula: E = mc².

Source: https://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence

"""


def energy_eq(mass: float) -> float:
"""
Calculate energy equivalent.
The energy equivalent of a mass m is mc², where c is the speed of light.

>>> energy_eq(0.001)
89875517873681.77

"""
if mass < 0:
raise ValueError("The mass of a body cannot be negative")
c = 2.99792458e8
return mass * c**2


if __name__ == "__main__":
import doctest

doctest.testmod()