# Kuramoto model using DifferentialEquations.jl

Hi everyone,

I wonder if you can help me with this one.

I am trying to model a simple Kuramoto model using OrdinaryDiffEq and I get an error because the code is trying to Float a complex number. Sorry if I am too ignorant.

Here is the code:

``````function parametrized_kuramoto(du,u,p,t)
# NumberOfOscillators, CouplingConstant, and NaturalFreqs
N,K,w = p
# Centroid
u = 0
for i in 1:N
u += cos(u[i+1]) + sin(u[i+1])*im ## This seems to be the problem
end
u = u/N
r = abs(u)
ψ = angle(u)
# Oscillators
for i in 1:N
du[i+1] = w[i] + K*r*sin(ψ-u[i+1])
end
end

fs = 250 #Sampling frequency
N = 20 # NumberOfOscillators
tspan = (0.0,1.0) #Time
u0 = zeros(N+1) #initial conditions
p = (N=N, K=0.1, w=rand(Uniform(0,10),N)) # just wrap everything up
prob = ODEProblem(parametrized_kuramoto,u0,tspan,p)
sol = solve(prob,RK4(),saveat=collect(0:1/fs:T),progress=true)
``````

and I get : ` InexactError: Float64(0.9999935742904003 + 0.0035848818543689786im)`

If I change `u += cos(u[i+1]) + sin(u[i+1])*im` for anything Real it works.

Can I run a system with Complex and real variables together?
Or should i separate the real and imaginary parts to simulate only real variables?

Thank you.

`u0` is a vector of `Float64`. Therefore, you can’t store `Complex` numbers in it. If you make `u0 = zeros(Complex{Float64}, N+1)`, it would work.

Thanks @Oscar_Smith . I knew it was me.