Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def f():
for i in range(N):
coupling_sum = sum( y(3*j)-y(3*i) for j in range(N) if A[i,j] )
coupling_term = k * symengine.sin(t) * coupling_sum
yield -ω[i] * y(3*i+1) - y(3*i+2) + coupling_term
yield ω[i] * y(3*i) + a*y(3*i+1)
coupling_term_2 = k * (sum_z-N*y(3*i+2))
yield b + y(3*i+2) * (y(3*i) - c) + coupling_term_2
def run_benchmark(n):
a0 = symbols("a0")
a1 = symbols("a1")
e = a0 + a1
f = 0;
for i in range(2, n):
s = symbols("a%s" % i)
e = e + sin(s)
f = f + sin(s)
f = -f
t1 = clock()
e = expand(e**2)
e = e.xreplace({a0: f})
e = expand(e)
t2 = clock()
print("%s ms" % (1000 * (t2 - t1)))
def kuramotos_f():
for i in range(n):
coupling_sum = sum(
sin(y(j)-y(i))
for j in range(n)
if A[j,i]
)
yield omega[i] + c/(n-1)*coupling_sum
for _ in range(L):
der = der.diff(_x)
for m in range(L + 1):
pol = (1 - _x ** 2) ** (m/2)
if m: der = der.diff(_x)
leg = phase[m] / den * (pol * der).subs({_x: _z / _r})
if not m:
sh[L][m] = rac * leg
continue
N = 2 ** 0.5 * phase[m]
facs = facts[L - m] / facts[L + m]
norm = facs ** 0.5
phi = (m * _x).subs({_x: 'arctan2(_y, _x)'})
fun = cos(phi)
sh[L][m] = N * rac * norm * leg * fun
fun = sin(phi)
sh[L][-m] = N * rac * norm * leg * fun
return sh
def kuramotos_f():
for i in range(n):
coupling_sum = sum(
sin(y(j)-y(i))
for j in range(n)
if A[j,i]
)
yield omega[i] + c/(n-1)*coupling_sum
def run_benchmark(n):
a0 = symbols("a0")
a1 = symbols("a1")
e = a0 + a1
f = 0;
for i in range(2, n):
s = symbols("a%s" % i)
e = e + sin(s)
f = f + sin(s)
f = -f
t1 = clock()
e = expand(e**2)
e = e.xreplace({a0: f})
e = expand(e)
t2 = clock()
print("%s ms" % (1000 * (t2 - t1)))
def kuramotos():
for i in range(n):
yield ω + c/(n-1)*sum(
sin(y(j,t-Ï„[i,j])-y(i))
for j in range(n)
if A[j,i]
)
"""
from jitcdde import t, y, jitcdde
from symengine import sin
import numpy as np
T = 200
A = 0.9/2/np.pi
Ï„_0 = 1.50
f = lambda z: 4*z*(1-z)
Ï„ = Ï„_0 + A*sin(2*np.pi*t)
model = [ T*( -y(0) + f(y(0,t-Ï„)) ) ]
DDE = jitcdde(model,max_delay=Ï„_0+A,verbose=False)
DDE.past_from_function([0.4+0.2*sin(t)])
DDE.set_integration_parameters(max_step=0.01,first_step=0.01)
DDE.integrate_blindly(Ï„_0+A,0.01)
for time in DDE.t + 100 + np.arange(0,10,0.01):
print(DDE.integrate(time)[0])