Closed ThomasChaffey closed 5 years ago
function f(du,u,p,t)
du = 1.01*u
end
That is not an in-place definition. There is no such thing as in-place mutation of a number since a number is a stack-allocated bitstype. Only something that is mutable, like an array, can be mutated in-place for this to make sense. So closing since there's nothing actionable here, but feel free to ask questions.
Maybe you'll find this tutorial helpful: http://juliadiffeq.org/DiffEqTutorials.jl/html/introduction/optimizing_diffeq_code.html
Thanks. I read up on mutable/immutable objects in Julia and it makes sense that this isn't an in-place definition.
Solving a first order ODE (that is, scalar state variable
u
) with an in-place definition produces the errorMethodError: no method matching similar(::Float64)
.A small example is solving Example 1 from the Ordinary Differential Equations Tutorial with an in-place definition:
No error is produced when the ODE definition is replaced with
f(u,p,t) = 1.01*u
.I am using Julia 1.1.1 on Mac OS X 10.14.3.