DifferentialEquations inexact error

Hello
I am trying to learn the Differential Equations and I end up with a stupid newbie mistake can anybody help me:

function Diffusive(du,u,p,t)
du = p*(100.0-u)
end
u0=0.1
tspan=(0, 10)
p=0.2
prob2 =ODEProblem(Diffusive,u0,tspan,p)
solve(prob2)

Error message after last line:
)
ERROR: InexactError: Int64(161//1000)
Stacktrace:
[1] Type at ./rational.jl:87 [inlined]
[2] convert(::Type{Int64}, ::Rational{Int64}) at ./number.jl:7
[3] OrdinaryDiffEq.Tsit5ConstantCache(::Type, ::Type) at /home/franb/.julia/packages/OrdinaryDiffEq/rdNK0/src/tableaus/low_order_rk_tableaus.jl:604
[4] alg_cache(::Tsit5, ::Float64, ::Float64, ::Type, ::Type, ::Type, ::Float64, ::Float64, ::ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}, ::Int64, ::Int64, ::Float64, ::Float64, ::Bool, ::Val{true}) at /home/franb/.julia/packages/OrdinaryDiffEq/rdNK0/src/caches/low_order_rk_caches.jl:348
[5] (::getfield(OrdinaryDiffEq, Symbol(“##193#194”)){Float64,Float64,DataType,DataType,DataType,Float64,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Int64,Int64,Float64,Float64,Bool})(::Tsit5) at /home/franb/.julia/packages/OrdinaryDiffEq/rdNK0/src/caches/basic_caches.jl:22
[6] map(::getfield(OrdinaryDiffEq, Symbol(“##193#194”)){Float64,Float64,DataType,DataType,DataType,Float64,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Int64,Int64,Float64,Float64,Bool}, ::Tuple{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType}}) at ./tuple.jl:140
[7] alg_cache(::CompositeAlgorithm{Tuple{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType}},AutoSwitch{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType},Rational{Int64},Int64}}, ::Float64, ::Float64, ::Type, ::Type, ::Type, ::Float64, ::Float64, ::ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}, ::Int64, ::Int64, ::Float64, ::Float64, ::Bool, ::Val{true}) at /home/franb/.julia/packages/OrdinaryDiffEq/rdNK0/src/caches/basic_caches.jl:21
[8] #__init#329(::Array{Int64,1}, ::Array{Int64,1}, ::Array{Int64,1}, ::Nothing, ::Bool, ::Bool, ::Bool, ::Bool, ::Nothing, ::Bool, ::Bool, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool, ::Rational{Int64}, ::Nothing, ::Nothing, ::Rational{Int64}, ::Int64, ::Int64, ::Int64, ::Rational{Int64}, ::Bool, ::Int64, ::Nothing, ::Nothing, ::Int64, ::typeof(DiffEqBase.ODE_DEFAULT_NORM), ::typeof(LinearAlgebra.opnorm), ::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), ::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Int64, ::String, ::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), ::Nothing, ::Bool, ::Bool, ::Bool, ::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:default_set,),Tuple{Bool}}}, ::typeof(DiffEqBase.__init), ::ODEProblem{Float64,Tuple{Int64,Int64},true,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType}},AutoSwitch{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType},Rational{Int64},Int64}}, ::Array{Float64,1}, ::Array{Int64,1}, ::Array{Any,1}, ::Type{Val{true}}) at /home/franb/.julia/packages/OrdinaryDiffEq/rdNK0/src/solve.jl:255
[9] (::getfield(DiffEqBase, Symbol(“#kw##__init”)))(::NamedTuple{(:default_set,),Tuple{Bool}}, ::typeof(DiffEqBase.__init), ::ODEProblem{Float64,Tuple{Int64,Int64},true,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType}},AutoSwitch{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType},Rational{Int64},Int64}}, ::Array{Float64,1}, ::Array{Int64,1}, ::Array{Any,1}, ::Type{Val{true}}) at ./none:0 (repeats 5 times)
[10] #__solve#328(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:default_set,),Tuple{Bool}}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Float64,Tuple{Int64,Int64},true,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType}},AutoSwitch{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType},Rational{Int64},Int64}}) at /home/franb/.julia/packages/OrdinaryDiffEq/rdNK0/src/solve.jl:4
[11] (::getfield(DiffEqBase, Symbol(“#kw##__solve”)))(::NamedTuple{(:default_set,),Tuple{Bool}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Float64,Tuple{Int64,Int64},true,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType}},AutoSwitch{Tsit5,Rosenbrock23{0,false,DefaultLinSolve,DataType},Rational{Int64},Int64}}) at ./none:0
[12] #__solve#2(::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Float64,Tuple{Int64,Int64},true,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing) at /home/franb/.julia/packages/DifferentialEquations/2PnT0/src/default_solve.jl:15
[13] #__solve at ./none:0 [inlined]
[14] #__solve#1 at /home/franb/.julia/packages/DifferentialEquations/2PnT0/src/default_solve.jl:5 [inlined]
[15] __solve at /home/franb/.julia/packages/DifferentialEquations/2PnT0/src/default_solve.jl:2 [inlined]
[16] #solve_call#433(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.solve_call), ::ODEProblem{Float64,Tuple{Int64,Int64},true,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at /home/franb/.julia/packages/DiffEqBase/4V8I6/src/solve.jl:40
[17] solve_call at /home/franb/.julia/packages/DiffEqBase/4V8I6/src/solve.jl:37 [inlined]
[18] #solve#434 at /home/franb/.julia/packages/DiffEqBase/4V8I6/src/solve.jl:59 [inlined]
[19] solve(::ODEProblem{Float64,Tuple{Int64,Int64},true,Float64,ODEFunction{true,typeof(Diffusive),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at /home/franb/.julia/packages/DiffEqBase/4V8I6/src/solve.jl:45
[20] top-level scope at none:0

You chose to use Int values for time. I updated the default handling to throw a warning in this case:

┌ Warning: Integer time values are incompatible with adaptive integrators. Utilize floating point numbers instead of integers in this case, i.e. (0.0,1.0) instead of (0,1).
â”” @ DiffEqBase C:\Users\accou\.julia\dev\DiffEqBase\src\solve.jl:157

So you need to use tspan = (0.0,10.0) for what you’re trying to do.

Also, your equation doesn’t make sense.

function Diffusive(du,u,p,t)
  du = p*(100.0-u)
end

is not a mutating function. If you want to not use a mutating function, then use the 3-argument form:

function Diffusive(u,p,t)
  p*(100.0-u)
end

otherwise, if you want to use the in-place functions, then you need to be using a mutable type as your integration state.

In total, your fixed example is:

using DifferentialEquations
function Diffusive(u,p,t)
  p*(100.0-u)
end
u0=0.1
tspan=(0.0, 10.0)
p=0.2
prob2 =ODEProblem(Diffusive,u0,tspan,p)
solve(prob2)
2 Likes

Thanks…

Out of curiosity, why not just dispatch on Int t-spans and promote them to float? i.e. float.(tspan).

Because not all differential equations work in continuous time, and so that assumption is incorrect in some important cases.

2 Likes