DifferentialEquations.jl Error

#1

I get the error MethodError: objects of type Float64 are not callable when trying to run sol = solve(prob). I have checked solutions to this error and none have worked.

using DifferentialEquations
const σ = 0.002; const θ = -0.5

function s(val)
return 1+exp(-(val - θ) / σ)^-1
end

function model(du,u,p,t)
x1, x2, y1, y2, xJ, yJ = u
τJ, τE, ε, γ, γJ, β, βJ, δ, δJ, λ, λJ, gexc, ginh, xinh, xexc = p
du[1] = ẋ1 = 3*x1 - x1^3 + y1 - ginh*s(xJ*(t - τJ))(x1 - xinh)
du[2] = ẏ1 = ε*(λ - γ*tanh(β*(x1 - δ)) - y1)
du[3] = ẋ2 = 3*x2 - x2^3 + y2 - ginh*s(xJ*(t - τJ))(x2 - xinh)
du[4] = ẏ1 = ε*(λ - γ*tanh(β*(x2 - δ)) - y2)
du[5] = ẋJ = 3*xJ - xJ^3 + yJ - gexc*(s(du[1]*(t - τE)) + s(du[3]*(t-τE)))(xJ - xexc)
du[6] = ẏJ = ε*(λJ - γJ*tanh(βJ*(xJ - δ)) - yJ)
end

u0 = [-1, -0.3, 0.2, 0.02, -1.1, 0.1]
p = [0, 0, 0.025, 5, 5, 10, 10, -1.1, -1.1, 1, 0, 1, 1, -3, 3]
tspan = (0.0,200.0)
prob = ODEProblem(model,u0,tspan,p)
sol = solve(prob)
using Plots
plot(sol)

Any help is appreciated.

#2

You might want to format you code with ```

But looking at that, s(du[3]* (t-τE))) returns a Float64, and so this is like calling a function on that number, which doesn’t make sense and throws that error. Did you mean for this to be s(du[3]* (t-τE)))*(xJ - xexc)? I see multiple cases where implicit multiplication is assumed.

#3

Hi Chris.

I did not realize Julia did not support implicit multiplication.

However, a new issue has arisen. I am getting the following error:

julia> sol = solve(prob)
┌ Warning: Instability detected. Aborting
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/PvfXM/src/integrator_interface.jl:162
retcode: Unstable
Interpolation: 3rd order Hermite
t: 1-element Array{Float64,1}:
 0.0
u: 1-element Array{Array{Float64,1},1}:
 [-1.0, -0.3, 0.2, 0.02, -1.1, 0.1]

I assumed this was because a number returned as NaN, but I cannot figure it out. Any ideas?

#4

Yes, a returned NaN is likely the cause of this, so t only returns the initial condition. I’d need to see what you ran to help.

#6

Hi Chris.

Below is the updated code I’ve been trying.

This is a model I am attempting to port from XPP to Julia, but it’s harder than anticipated.

using DifferentialEquations
# parameters
const τJ = 10; const τE = 0
const ε = 0.025; const γ = 5; const γJ = 5; const β = 10; const βJ = 10; const δ = -1.1; const δJ = -1.1; const λ = 1; const λJ = 0
const σ = 0.002; const θ = -0.5
const gexc = 1; const ginh = 1; const xinh = -3; const xexc = 3
# const x1 = -1; const x2 = -0.3; const y1 = 0.2; const y2 = 0.02; const xJ = -1.1; const yJ = 0.1

function s(val)
  return 1+exp(-(val - θ) / σ)^-1
end

function model(du,u,h,p,t)
  x1, x2, y1, y2, xJ, yJ = u # initial conditions
  du[1] = ẋ1 = 3x1 - x1^3 + y1 - ginh*s(xJ*(h(p, t-τJ)))*(x1 - xinh)
  du[2] = ẏ1 = ε*(λ - γ*tanh(β*(x1 - δ)) - y1)
  du[3] = ẋ2 = 3x2 - x2^3 + y2 - ginh*s(xJ*(h(p, t-τJ)))*(x2 - xinh)
  du[4] = ẏ1 = ε*(λ - γ*tanh(β*(x2 - δ)) - y2) 
  du[5] = ẋJ = 3xJ - xJ^3 + yJ - gexc(s(du[1]*(h(p, t-τE))) + s(du[3]*(h(p, t-τE))))*(xJ - xexc)
  du[6] = ẏJ = ε*(λJ - γJ*tanh(βJ*(xJ - δ)) - yJ)
end

h(p, t) = ones(6) # temporary history
tspan = (0.0,10.0)
u0 = [-1, -0.3, 0.2, 0.02, -1.1, 0.1] # initial conditions
prob = DDEProblem(model,u0,h,tspan)
alg = MethodOfSteps(BS3())
sol = solve(prob,alg) 
using Plots; plot(sol)

Thanks for taking a look :slightly_smiling_face: . If you’d like to see my XPP model, I am more than happy to share that as well.

#7

What’s the issue with the model?

#8

This is the error I am getting:

ERROR: MethodError: no method matching -(::Array{Float64,1}, ::Float64)
Closest candidates are:
  -(::Float64, ::Float64) at float.jl:397
  -(::Complex{Bool}, ::Real) at complex.jl:298
  -(::Missing, ::Number) at missing.jl:97
  ...

Clearly I am supplying incorrect arguments to the solver, but I am not sure why. I followed the example problems and documentation closely.

#9

h(p, t-τJ) is an array. When you subtract a scalar from it you get an error. Did you need intend for it to be an array?