File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments