Created
September 19, 2022 16:12
-
-
Save mbudisic/50c71eeff5f9eacf50fca3f807ab020e to your computer and use it in GitHub Desktop.
Random walker with damping and inertia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def xyindependent(x,b,c,dt,randomfun): | |
for idx in range(2,len(x)): | |
x[idx] =(2-b*dt)*x[idx-1] + (b*dt-c*dt*dt-1)*x[idx-2] + dt*dt*randomfun() | |
return x | |
import matplotlib.pyplot as plt | |
x0 = np.zeros(100,) | |
y0 = np.zeros(100,) | |
dt = 0.01 | |
damping = -0.5 # play around | |
mass = 1/3 # play around | |
x0 = xyindependent(x0,-damping,1./mass,dt, lambda : np.random.uniform(-0.1,0.5)) | |
y0 = xyindependent(y0,-damping,1./mass,dt, lambda : np.random.uniform(-0.1,0.5)) | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
plt.plot(x0,y0,label="x/y") | |
ax.set_aspect(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment