# ParameterizedFunctions for setting up systems of ODEs

Hi,

I am trying out an example to set up a system of ODE’s for solution using the ParameterizedFunctions package - looks quite useful. I keep getting an error and could do with some help. It seems the set of the method has changed and there is conflicting documentation around the method (see below). Does anyone know the correct format?

``````
using DifferentialEquations,OrdinaryDiffEq, Plots, ParameterizedFunctions

g = @ode_def LorenzExample begin

dx = σ*(y-x)

dy = x*(ρ-z) - y

dz = x*y - β*z

end σ ρ β

σ=10.0

ρ=28.0

β=(8/3)

u0 = [1.0;0.0;0.0]

tspan = (0.0,1.0)

println(σ)

prob = ODEProblem(g,u0,tspan)

# Since we used =>, σ and ρ are kept as mutable parameters. For example we can do:

# g.σ = 11.0

# to change the value of σ to 11.0. β is not able to be changed since we defined it using =.

# We can create a new instance with new parameters via the name used in the @ode_def command:

# h = LorenzExample(σ=11.0,ρ=25.0)

sol = solve(prob)

plot(sol)```

10.0
ERROR: LoadError: Parameters were indexed but the parameters are `nothing`. You likely forgot to pass in parameters to the DEProblem!
Stacktrace:
[1] error(::String) at .\error.jl:33``````

You didn’t pass any parameters.

Chris it looks to me that I defined all inputs. What am I missing? Apologize if the question is trivial to you. I having been writing fortran programs for over 40 years and am struggling a bit with the Julia syntax. Peter

You have assigned some values to the global variables `σ`, `ρ`, `β`, but then these parameters are not passed to the constructor `ODEProblem`. You should try

``````prob = ODEProblem(g, u0, tspan, (σ, ρ, β))
``````

Then it works and produces this plot:

I guess the comments that you have at the end are referring to the syntax explained here, but for me writing

``````g = @ode_def LorenzExample begin
dx = σ*(y-x)
dy = x*(ρ-z) - y
dz = x*y - β*z
end σ=>10.0 ρ=>28.0 β=8/3
``````

throws the error

``````ERROR: LoadError: The syntax for ParameterizedFunctions has changed.
Simply list the parameters at the end, i.e. `a b c d`, instead of `a=5.0 b=>3.0 ...`.
Parameters are defined in the problem type.
``````

so I guess this feature has been discontinued (it doesn’t appear in the new version of the docs).

Thank you. I thought the parameters had been passed in g. I will try tomorrow. Its 10.00 pm in Brisbane. Once I am happy with this method I need to set up a system of 130 ODEs with lots of coefficients on the RHS. In time I want to attach an optimization engine to investigate the impact of these coefficients on the performance of the system. Any references to similar problems would be appreciated. Regards Peter

If your system is so big (~130 unknowns), I imagine it would be better to either define a standard function (by defining `f(u,p,t)`/`f(du,u,p,t)` as explained here), or generate the right hand side programmatically via a macro. Using `@ode_def` doesn’t seem very beneficial since you would have to manually type out the full system of ODEs.

1 Like

Spot on. Your suggestion worked and I was wrong footed by the documentation you outlined above, that gave different syntax. I am still getting my head around the fact that the language is still somewhat in development and that what you read may not always work. Anyway, I appreciate you taking the time to sort me out on this issue. Thanks

1 Like

This is exactly the issue I am facing - where to start with presenting such a large system to the Julia ODE solver. I do have a program running to solve the 130 equation system, written in VBA using a Runge-Kutta 4th order solver, however it runs very slowly. The reasons for this is the system is stiff, requiring a very small time step, and the fact that VBA is not the environment for such a large system. Also, VBA does not have a stiff solver either. I could have easily gone to FORTRAN (my native language) but consensus amongst the team was to go to Julia and keep up with the times … a big learning curve for me though, as the syntax is so far removed from what I know. Once I find my direction I will be alright. Again, thanks for your help. Peter

It’s not discontinued, you can use it via the ParameterizedFunctions.jl package

But it’s not something we emphasize anymore. It’s a nice small DSL but it won’t do the big grand plans we had for it. If you want a full DSL, ModelingToolkit is what’s being developed, though it’s not quite complete yet.

2 Likes

Chris thanks for update. I guess I will go toward the Modelling Toolkit then. I have now transferred all my VBA source code into Julia (basic syntax transposed), but how to link it and present it to the solver will take some time.

The RHS of my system of equations (130) have a lot of interlinked terms and also external parameters fixed at run time, although in due course I want to investigate the impact of some of these parameters(or coefficients) in front of the dependant variables through an optimization engine, which I am yet to define. Do you have a recommendation for a Julia optimization engine that could ultimately call my Julia simulation program and optimize a user defined Objective Function, subject to a list of constraints (equalities and inequalities)? I would like to develop my ODE solver approach so that it won’t limit my ability to do the optimization work, which is the final objective of the project.

Any thoughts appreciated

Thanks,
Peter

https://diffeqflux.sciml.ai/dev/ has a bunch of examples, but for equality and inequality constraints you swap in the https://github.com/JuliaOpt/NLopt.jl optimizers. We’re putting this all together in https://github.com/SciML/GalacticOptim.jl but it’s not all documented yet.

Ok thanks for the response. Regards Peter