clear;

k = 2;
r = zeros(1,k-1);

% global samples
N = 1000;


for j = 1: k-1
    

% randomly walking observer probabilities
% left, stay right probabilities

p_  = [.1 .1  .8];
pu_ = [.1 .1  .8];
%p_ = [ 0 (1-j/k)  j/k];

p_u  =  cumsum(p_);
p_l  =  [ 0 p_u(1:2)];

v = sum(p_ .* [ -1 0 1]);


% observer walking randomly on rest frame
motion_toward  = rmotion(p_, N);
                   
                  
% rest frame moving randomly away from observer
motion_away  =  rmotion(p_,N);
                   

% particle is moving one pixel at a time

Smotion_toward =  rmotion(po_,N);
Smotion_away   =  rmotion(po_,N);
                   
                   
% relative distance between randomly walking observer and light-speed particle
% in the rest frame
drwl  =  Smotion  -  motion_toward;

% relative distance between randomly moving rest frame and the light speed particle
% in the observer's frame
drwr  =  Smotion  +  motion_away;


% "Analysis" : BETA 
% instantenous relative displacement drw(n) has to  1 or 0 

% if drw(n) is 2, the displacement of the rest frame has to be delayed by 2
% since a particle can at most travel 1 space in time instant

% if drw(n) is 1, the displacement of the rest frame has to be delayed by 1
% it is consisent

% if drw(n) is 0, the displacement of the rest frame has to be delayed by 0 
% because  a light like particle always has to move 1 space by 1 time instant 
% by defintion

% relative distance between randomly moving observer and light-speed particle
% in observer's frame.



% constracted length

Spmotion =  drwr .* drwl;

% The sqrt() is unresolved and unclear;
% in the rest frame, the light like particle is supposed to be at n at time instant n

% sum(Spmotion(n))/n is gamma^2

% Some issues still unresolved

r(j) =  sqrt( mean(Spmotion));

end;

j = (1:k-1)/k;

%length contraction graph

plot(j, r, j, sqrt( 1 - j.^2));

legend('simulation', 'theory');
xlabel('velocity');
ylabel('Contraction factor');





 

