I’ve never seen a version where no parameter is present in the function definition. Maybe there is one, but personally, i would just define
function F!(dx,x,p,t)
dx.=[x[1]+x[2];x[2]];
end
And simply not use p.
That way if you ever need to use params which happens a lot, it’s straight forward to extend.
When solving this, you need to pass the solver the params. Here you can put in anything since the function doesn’t do anything with it but I would probably pass nothing.
Edit: note that If performance matters, you should not allocate a small array on the right hand side the way you do, but probably rather use a tuple or similar.
No, the time argument always comes last and the parameters always comes after the state variables x. This signature: F!(t,dx,x) does not exist, where have you seen that?
I was just trying it myself, but yes thanks for letting me know that function signature doesn’t exist. I still don’t know how to define a function without using a parameter though. F!(dx,x,t) doesn’t work for me, it gives an error, but I do use F!(dx,x,p,t) and then not use p in the function, but that seems like a workaround than a proper way.
Thanks! I have been doing that since it’s the one which works for me but seems like a workaround. Is it not possible to define a differential equation function simply like F!(dx,x,t)?
My understanding is that the parameter vector needs to be passed into the function regardless if it is actually used or not; I have never seen a working DifferentialEquations.jl (or anything SciML, for that matter) example without a parameter vector being passed in (similarly to @salmon). I believe that this is a design choice specifically by the SciML team to make their packages all operate in a similar way, with similar syntax. It’s not required to pass anything into the problem constructor for the parameter vector (i.e., to prob = ODEProblem(... as can be seen from this example.
TL;DR: I believe it’s a design choice that p is included, but it’s been made so that if it isn’t used, it has minimal impact on model definition.