Skip to content

Commit 4cba4a3

Browse files
kvadrikpre-commit-ci[bot]cclauss
authored
Relativistic velocity summation function (#14357)
* Relativistic velocity summation function The formula v2=(v1+v)/(1+v1*v/c^2) is implemented. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Lines divided * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Long line cut * relativistic_velocity_summation function parameters explained * Gave meaningful names to function parameters * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Comment put to a top * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Put # in comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Line shortened * Enhance docstring with reference link Updated docstring to include a reference link for the velocity addition formula. * updating DIRECTORY.md * updating DIRECTORY.md * Fix grammar in relativistic kinetic energy comments Corrected minor grammatical errors in comments and documentation. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: cclauss <cclauss@users.noreply.github.com>
1 parent 87074cf commit 4cba4a3

3 files changed

Lines changed: 60 additions & 6 deletions

File tree

DIRECTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,8 @@
10141014
* [Coulombs Law](physics/coulombs_law.py)
10151015
* [Doppler Frequency](physics/doppler_frequency.py)
10161016
* [Escape Velocity](physics/escape_velocity.py)
1017+
* [Faraday Lenz Law](physics/faraday_lenz_law.py)
1018+
* [First Law Of Thermodynamics](physics/first_law_of_thermodynamics.py)
10171019
* [Grahams Law](physics/grahams_law.py)
10181020
* [Hamiltonian](physics/hamiltonian.py)
10191021
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
@@ -1023,6 +1025,7 @@
10231025
* [Kinetic Energy](physics/kinetic_energy.py)
10241026
* [Lens Formulae](physics/lens_formulae.py)
10251027
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)
1028+
* [Magnetic Flux](physics/magnetic_flux.py)
10261029
* [Malus Law](physics/malus_law.py)
10271030
* [Mass Energy Equivalence](physics/mass_energy_equivalence.py)
10281031
* [Maxwells Equations](physics/maxwells_equations.py)
@@ -1035,9 +1038,12 @@
10351038
* [Photoelectric Effect](physics/photoelectric_effect.py)
10361039
* [Potential Energy](physics/potential_energy.py)
10371040
* [Rainfall Intensity](physics/rainfall_intensity.py)
1041+
* [Relativistic Kinetic Energy](physics/relativistic_kinetic_energy.py)
1042+
* [Relativistic Velocity Summation](physics/relativistic_velocity_summation.py)
10381043
* [Reynolds Number](physics/reynolds_number.py)
10391044
* [Rms Speed Of Molecule](physics/rms_speed_of_molecule.py)
10401045
* [Shear Stress](physics/shear_stress.py)
1046+
* [Snells Law](physics/snells_law.py)
10411047
* [Speed Of Sound](physics/speed_of_sound.py)
10421048
* [Speeds Of Gas Molecules](physics/speeds_of_gas_molecules.py)
10431049
* [Terminal Velocity](physics/terminal_velocity.py)

physics/relativistic_kinetic_energy.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
2222
y = 1 / sqrt(1 - v^2 / c^2)
2323
24-
is the Lorentz factor. At speeds much smaller than c, this expression reduces to the
24+
is the Lorentz factor. At speeds much lower than c, this expression reduces to the
2525
classical formula K ≈ (1/2) m v^2, so the relativistic result agrees with Newtonian
26-
kinetic energy in the low velocity limit.The standard unit of kinetic energy is the
26+
kinetic energy in the low-velocity limit. The standard unit of kinetic energy is the
2727
joule, while the English unit of kinetic energy is the foot-pound.
2828
29-
Reference : https://en.wikipedia.org/wiki/Kinetic_energy
29+
Reference: https://en.wikipedia.org/wiki/Kinetic_energy
3030
"""
3131

3232
from math import sqrt
@@ -56,9 +56,8 @@ def relativistic_kinetic_energy(mass: float, velocity: float) -> float:
5656

5757
if mass < 0:
5858
raise ValueError("The mass of a body cannot be negative")
59-
else:
60-
gamma = 1 / sqrt(1 - (velocity**2 / c**2))
61-
return (gamma - 1) * mass * c**2
59+
gamma = 1 / sqrt(1 - (velocity**2 / c**2))
60+
return (gamma - 1) * mass * c**2
6261

6362

6463
if __name__ == "__main__":
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
The relativistic velocity summation formula calculates the combined velocity v2 of
3+
an object moving at speed v1 relative to a frame that is itself moving at velocity v
4+
relative to an observer. I take the last one to be strictly lower than the speed of
5+
light.
6+
The formula is v2 = (v1 + v)/(1 + v1 * v / c**2)
7+
v1 - speed of the object relative to a moving frame
8+
v - speed of the moving frame
9+
c - speed of light in a vacuum
10+
v2 - speed of the object relative to an observer
11+
12+
https://en.wikipedia.org/wiki/Velocity-addition_formula
13+
"""
14+
15+
c = 299792458
16+
17+
18+
def relativistic_velocity_summation(
19+
object_velocity: float, frame_velocity: float
20+
) -> float:
21+
"""
22+
>>> relativistic_velocity_summation(200000000, 200000000)
23+
276805111.0636436
24+
>>> relativistic_velocity_summation(299792458, 100000000)
25+
299792458.0
26+
>>> relativistic_velocity_summation(100000000, 299792458)
27+
Traceback (most recent call last):
28+
...
29+
ValueError: Speeds must not exceed light speed...
30+
"""
31+
if (
32+
object_velocity > c
33+
or frame_velocity >= c
34+
or object_velocity < -c
35+
or frame_velocity <= -c
36+
):
37+
raise ValueError(
38+
"Speeds must not exceed light speed, and "
39+
"the frame speed must be lower than the light speed!"
40+
)
41+
numerator = object_velocity + frame_velocity
42+
denominator = 1 + object_velocity * frame_velocity / c**2
43+
return numerator / denominator
44+
45+
46+
if __name__ == "__main__":
47+
from doctest import testmod
48+
49+
testmod()

0 commit comments

Comments
 (0)