You can access the online simulation of the same model from here. The model is taken from the paper: Swarmalators with competitive time-varying phase interactions [Gourab K Sar et al].
- You need to install the following packages first:
- numba
- tqdm
- scipy
- The programs are interdependant, so they should be placed in the same folder.
- You can run main.py for plotting and animating data, and scan_parameter.py to scan parameters.
- The files will be named according to their parameters itself, so it is easy for you to find them.
- Thats it, enjoy!
Untitled.video.-.Made.with.Clipchamp.22.1.mp4
define generate_data(parameters):
if data for parameters was already generated:
return already generated data
Initialise x to N random numbers in [-2,2]
Initialise theta to N random numbers in [-pi,pi]
Pack x and theta together into a variable X
n=1000 # number of iterations
h=0.01 # step size for RK-4th order method
# perform Rk-4th order integration
Iterate n times:
k1=df(X)*h
k2=df(X+k1/2)*h
k3=df(X+k2/2)*h
k4=df(X+k3)*h
X=X+(k1+2*k2+2*k3+k4)/6
append this new X to history variable
return the history variable
# dynamical equations of model
define df(X):
unpack X into x and theta
initialise x_dot and sigma_dot to zero
loop i from 0 to N:
S_x,S_sigma_a,S_sigma_r=0 # initialise summations to zero
loop j from 0 to N:
if i same as j:
skip this loop
else:
S_x=S_x+((1+J cos(thetaij))/|xij| -1/|xij|^2)
if agent j is inside vision radius of agent i
N_i=N_i+1
S_sigma_a=S_sigma_a+sin(thetaij)/|xij|
else:
S_sigma_r=S_sigma_r+sin(thetaji)/|xij|
x_dot[i]=S_x/(N-1)
sigma_dot[i]=e_a*S_sigma_a/(N_i)+e_r*S_sigma_r/(N-N_i-1)
pack x_dot and sigma_dot into X_dot
return X_dot