Skip to content

Commit 6b973f9

Browse files
authored
Relativistic velocity summation function
The formula v2=(v1+v)/(1+v1*v/c^2) is implemented.
1 parent 9ea690e commit 6b973f9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
c = 299792458
2+
3+
"""
4+
The relativistic velocity summation formula calculates the combined velocity v2
5+
of an object moving at speed v1 relative to a frame that is itself moving at velocity v
6+
relative to an observer. I take the last one to be strictly lower than the speed of
7+
light.
8+
The formula is v2 = (v1 + v)/(1 + v1 * v / c^2)
9+
"""
10+
11+
def relativistic_velocity_summation (v1: float, v: float) -> float:
12+
"""
13+
>>> relativistic_velocity_summation(200000000, 200000000)
14+
276805111.0636436
15+
>>> relativistic_velocity_summation(299792458, 100000000)
16+
299792458.0
17+
>>> relativistic_velocity_summation(100000000, 299792458)
18+
Traceback (most recent call last):
19+
...
20+
ValueError: Speeds must not exceed light speed, and the frame speed must be lower than the light speed!
21+
"""
22+
if v1 > c or v >= c or v1 < -c or v <= -c:
23+
raise ValueError("Speeds must not exceed light speed, and the frame speed must be lower than the light speed!")
24+
return (v1 + v)/(1 + v1 * v / (c * c))
25+
26+
if __name__ == "__main__":
27+
from doctest import testmod
28+
29+
testmod()

0 commit comments

Comments
 (0)