Solving system of differential equations with complex variables leads to Type errors


#1

I am trying to solve a set of coupled ODEs where the solution variable is a complex array. When I run the following code, I get an error which says:
LoadError: InexactError: Int64(Int64, 1731//50000)
The Stacktrace sarts from
[1] convert(::Type{Int64}, ::Rational{Int64}) at ./rational.jl:85
[2] OrdinaryDiffEq.Vern9ConstantCache(::Type, ::Type) at /Users/home/.julia/packages/OrdinaryDiffEq/YudGf/src/tableaus/verner_tableaus.jl:2539

I have not used Int64 or Rational anywhere, and this error does not occur when I try to solve, e.g., the Lorenz equations. So I think this might be a problem with how OrdinaryDiffEq handles complex numbers.
All my real numbers are Float64, and the real and imaginary parts of my Complex numbers are also Float64.
I have also confirmed that it doesn’t matter what calculations I actually place inside the function VortexStreet which is being solved by solve; even if I do no calculations inside this function, the same error occurs.
What could be the problem?

using DifferentialEquations
function VortexStreet(dzdt,z,p,t)
	for i = 1:length(z)
		for j = 1:length(z)
		if j != i
			dzdt[i] += cot(z[i]-z[j]);
		end
		end
	end
end

a = 1.0; b = 0.56; L = 2a;
n = 3;

z0 = Array{Complex}(undef,2n);
dzdt = Array{Complex}(undef,2n);
for i in 1:n
	z0[2(i-1)+1] =complex(0.5*a+(i-1)*L,b*0.5);
	z0[2(i-1)+2] =complex(1.5*a+(i-1)*L,b*0.5);
end

for i in 1:2n
	dzdt[i] = 0.0;
end
tspan = (0.0,0.1);
problem = ODEProblem(VortexStreet,z0,tspan);
solution = solve(problem);

#2

Complex is supposed to have a type parameter. Without it, I’m not sure how it would know the element type. It seems you meant to be using Complex{Float64}. When using that the code works. Example:

using DifferentialEquations
function VortexStreet(dzdt,z,p,t)
	for i = 1:length(z)
		for j = 1:length(z)
		if j != i
			dzdt[i] += cot(z[i]-z[j]);
		end
		end
	end
end

a = 1.0; b = 0.56; L = 2a;
n = 3;

z0 = Array{Complex{Float64}}(undef,2n);
dzdt = Array{Complex{Float64}}(undef,2n);
for i in 1:n
	z0[2(i-1)+1] =complex(0.5*a+(i-1)*L,b*0.5);
	z0[2(i-1)+2] =complex(1.5*a+(i-1)*L,b*0.5);
end

for i in 1:2n
	dzdt[i] = 0.0;
end
tspan = (0.0,0.1);
problem = ODEProblem(VortexStreet,z0,tspan)
solution = solve(problem)

#3

That makes a lot of sense, I thought it was sufficient that the individual components of a complex number be themselves Float64 ( and not, say, Int).

Thank you so much!