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

**URL:** https://discourse.julialang.org/t/solving-system-of-differential-equations-with-complex-variables-leads-to-type-errors/17269
**Category:** General Usage
**Created:** [November 7, 2018, 6:16pm UTC](https://discourse.julialang.org/t/solving-system-of-differential-equations-with-complex-variables-leads-to-type-errors/17269 "2018-11-07T18:16:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![EmadMasroor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emadmasroor/32/7527_2.png) [@EmadMasroor](https://discourse.julialang.org/u/EmadMasroor)
#### Post date: [November 7, 2018, 6:16pm UTC](https://discourse.julialang.org/t/solving-system-of-differential-equations-with-complex-variables-leads-to-type-errors/17269/1 "2018-11-07T18:16:36Z")

</div>

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?

```julia
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);

```

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [November 7, 2018, 6:59pm UTC](https://discourse.julialang.org/t/solving-system-of-differential-equations-with-complex-variables-leads-to-type-errors/17269/2 "2018-11-07T18:59:59Z")

</div>

`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:

```julia
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)

```

---

<div class="post-metadata">

### Author: ![EmadMasroor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emadmasroor/32/7527_2.png) [@EmadMasroor](https://discourse.julialang.org/u/EmadMasroor)
#### Post date: [November 7, 2018, 10:28pm UTC](https://discourse.julialang.org/t/solving-system-of-differential-equations-with-complex-variables-leads-to-type-errors/17269/3 "2018-11-07T22:28:37Z")

</div>

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!
