MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / beta

Function beta

physics/lorentz_transformation_four_vector.py:41–61  ·  view source on GitHub ↗

Calculates β = v/c, the given velocity as a fraction of c >>> beta(c) 1.0 >>> beta(199792458) 0.666435904801848 >>> beta(1e5) 0.00033356409519815205 >>> beta(0.2) Traceback (most recent call last): ... ValueError: Speed must be greater than or equal to

(velocity: float)

Source from the content-addressed store, hash-verified

39
40# Vehicle's speed divided by speed of light (no units)
41def beta(velocity: float) -> float:
42 """
43 Calculates β = v/c, the given velocity as a fraction of c
44 >>> beta(c)
45 1.0
46 >>> beta(199792458)
47 0.666435904801848
48 >>> beta(1e5)
49 0.00033356409519815205
50 >>> beta(0.2)
51 Traceback (most recent call last):
52 ...
53 ValueError: Speed must be greater than or equal to 1!
54 """
55 if velocity > c:
56 raise ValueError("Speed must not exceed light speed 299,792,458 [m/s]!")
57 elif velocity < 1:
58 # Usually the speed should be much higher than 1 (c order of magnitude)
59 raise ValueError("Speed must be greater than or equal to 1!")
60
61 return velocity / c
62
63
64def gamma(velocity: float) -> float:

Callers 2

gammaFunction · 0.85
transformation_matrixFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected