In [1]:
import numpy as np;
import matplotlib.pyplot as plt;
plt.rcParams.update({"text.usetex":True});
%config InlineBackend.figure_format = "svg"
from ipywidgets import interactive
In [2]:
def get_angle(N): # N is the time steps
    return np.random.uniform(0, 2*np.pi, size=(N,))

def get_stride(N):
    return np.ones((N,))

N = 200;
x0, y0 = 0, 0;
x = np.zeros((2,N));

for i in np.arange(1,N):
    l = get_stride(1);
    th = get_angle(1);
    deltax = l*np.cos(th); deltay = l*np.sin(th);
    x[0,i] = deltax
    x[1,i] = deltay
    
xinc = x[0,:]; yinc = x[1,:];
xtraj = np.cumsum(xinc); ytraj = np.cumsum(yinc);
plt.plot(xtraj, ytraj);
2021-02-02T19:02:27.828022 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [3]:
def get_angle(N): # N is the time steps
    return np.random.uniform(0, 2*np.pi, size=(N,))

def get_stride(N):
    return np.ones((N,))

N = 200;
Np = 10;

for j in np.arange(1,Np):
    x0, y0 = 0, 0;
    x = np.zeros((2,N));

    for i in np.arange(1,N):
        l = get_stride(1);
        th = get_angle(1);
        deltax = l*np.cos(th); deltay = l*np.sin(th);
        x[0,i] = deltax
        x[1,i] = deltay

    xinc = x[0,:]; yinc = x[1,:];
    xtraj = np.cumsum(xinc); ytraj = np.cumsum(yinc);
    plt.plot(xtraj, ytraj);
2021-02-02T19:03:08.444525 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [4]:
def get_angle(N): # N is the time steps
    return np.random.uniform(0, 2*np.pi, size=(N,))

def get_stride(N):
    return np.ones((N,))

def get_final_loc(N):
    x0, y0 = 0, 0;
    x = np.zeros((2,N));

    for i in np.arange(1,N):
        l = get_stride(1);
        th = get_angle(1);
        deltax = l*np.cos(th); deltay = l*np.sin(th);
        x[0,i] = deltax
        x[1,i] = deltay

    xinc = x[0,:]; yinc = x[1,:];
    xtraj = np.sum(xinc); ytraj = np.sum(yinc); rorigin = (xtraj**2 + ytraj**2)**0.5;
    return rorigin

N = 200;
Np = 10000;
r = np.zeros((Np,))

for j in np.arange(0,Np):
    r[j] = get_final_loc(N)
In [5]:
bins,counts,_=plt.hist(r, bins = 40, density=True)
2021-02-02T19:08:52.549751 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [28]:
s1= get_angle(10)
s2=get_stride(10);
dx = s2*np.cos(s1); dy = s2*np.sin(s1);
lx = np.sum(dx); ly = np.sum(dy);
print(lx); print(ly);
0.16331775787207148
-2.7688723556677157
In [6]:
def get_angle(N): # N is the time steps
    return np.random.uniform(0, 2*np.pi, size=(N,))

def get_stride(N):
    return np.abs(np.random.standard_cauchy(size=(N,)))

N = 200;
x0, y0 = 0, 0;
x = np.zeros((2,N));

for i in np.arange(1,N):
    l = get_stride(1);
    th = get_angle(1);
    deltax = l*np.cos(th); deltay = l*np.sin(th);
    x[0,i] = deltax
    x[1,i] = deltay
    
xinc = x[0,:]; yinc = x[1,:];
xtraj = np.cumsum(xinc); ytraj = np.cumsum(yinc);
plt.plot(xtraj, ytraj);
2021-02-02T19:22:30.225331 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [7]:
def get_angle(N): # N is the time steps
    return np.random.uniform(0, 2*np.pi, size=(N,))

def get_stride(N):
    return np.abs(np.random.standard_cauchy(size=(N,)))

N = 200;
Np = 10;

for j in np.arange(1,Np):
    x0, y0 = 0, 0;
    x = np.zeros((2,N));

    for i in np.arange(1,N):
        l = get_stride(1);
        th = get_angle(1);
        deltax = l*np.cos(th); deltay = l*np.sin(th);
        x[0,i] = deltax
        x[1,i] = deltay

    xinc = x[0,:]; yinc = x[1,:];
    xtraj = np.cumsum(xinc); ytraj = np.cumsum(yinc);
    plt.plot(xtraj, ytraj);

ax = plt.gca(); ax.set_aspect(1)
2021-02-02T19:22:38.149343 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [9]:
r = np.linspace(0, 10); f = 1/(np.pi**2*r*(1+r**2));
plt.loglog(r, f)
<ipython-input-9-ef9ea969739d>:1: RuntimeWarning: divide by zero encountered in true_divide
  r = np.linspace(0, 10); f = 1/(np.pi**2*r*(1+r**2));
Out[9]:
[<matplotlib.lines.Line2D at 0x23293a6cf70>]
2021-02-02T19:23:34.487897 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [12]:
def get_angle(N): # N is the time steps
    return np.random.uniform(0, 2*np.pi, size=(N,))

def get_stride(N):
    return np.abs(np.random.standard_cauchy(size=(N,)))

def get_final_loc(N):
    l = get_stride(N);
    th = get_angle(N);
    dx = l*np.cos(th); dy = l*np.sin(th);
    xtraj = np.sum(dx); ytraj = np.sum(dy); rorigin = (xtraj**2 + ytraj**2)**0.5;
    return rorigin

N = 200;
Np = 10000;
r = np.zeros((Np,))

for j in np.arange(0,Np):
    r[j] = get_final_loc(N)
In [13]:
binsp = np.linspace(0, 1000);
bins,counts,_=plt.hist(r, bins = binsp, density=True)
2021-02-02T19:31:59.668542 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [ ]: