DifferentialEquations Parameters

When passing parameters p to the function f of an ODEProblem (or any problem type in the DiffEq universe), does p always have to be an array? Is there a “best practices” reason for why I shouldn’t use Dicts to hold my parameters in my function definition f?

As a concrete example, I tried modifying the ODE tutorial

p = Dict()
p[:c] = 1.01
f(u,p,t) = p[:c]*u
u0 = 1/2
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)

but I get ERROR: MethodError: no method matching getindex(::Nothing, ::Symbol) related to p on the solve, so I was curious why parameters have to be “list”-like.

1 Like

It can be any type.

You didn’t pass your parameters.

1 Like

Oh gosh, thank you…

No worries. If you use a version of DiffEq released within the last year this error message is better and explicitly says the parameters were not passed in (by using a fancy default)

4 Likes