import numpy as np;
import matplotlib.pyplot as plt;
plt.rcParams.update({"text.usetex":True});
%config InlineBackend.figure_format = "svg"
from ipywidgets import interactive
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);
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);
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)
bins,counts,_=plt.hist(r, bins = 40, density=True)
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
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);
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)
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));
[<matplotlib.lines.Line2D at 0x23293a6cf70>]
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)
binsp = np.linspace(0, 1000);
bins,counts,_=plt.hist(r, bins = binsp, density=True)