lorentz addition of velocities in matlab

Velocity addition in special relativity is known as Lorentz addition. In MATLAB, the Lorentz addition of velocities can be implemented using the following code:

main.m
function v3 = lorentzAddition(v1, v2, c)
    % LORENTZADDITION calculates the Lorentz addition of velocities.
    %   v1, v2 - velocities to be added in m/s
    %   c - speed of light in m/s
    %   Returns the resultant velocity in m/s
    
    v3 = (v1 + v2) / (1 + ((v1*v2)/(c^2)));
end
290 chars
9 lines

The lorentzAddition function takes in two velocities, v1 and v2, along with the speed of light c, and returns their Lorentz sum v3. The formula used to calculate v3 is the Lorentz transformation:

$$ v_3 = \frac{v_1 + v_2}{1 + \frac{v_1v_2}{c^2}} $$

Example Usage:

main.m
>> lorentzAddition(0.5*299792458, 0.25*299792458, 299792458)

ans =

   0.654840886767033e+08
94 chars
6 lines

In this example, we are adding two velocities, 0.5c and 0.25c, where c is the speed of light. The resulting velocity, calculated using lorentzAddition, is 0.65484c.

gistlibby LogSnag