The ode_def macro
ParameterizedFunctions.@ode_def — Macro
@ode_def [name] begin
dstate = expression
# additional derivative assignments
end parameter_names...Define a parameterized ordinary differential equation and return an SciMLBase.AbstractParameterizedFunction suitable for an ODEProblem. The macro generates in-place and out-of-place right-hand sides, a time gradient, and a Jacobian through ModelingToolkit.
Arguments
name: optional name for the generated function type. Omit it to return an anonymous parameterized function.- derivative assignments: a
beginblock whose statements have the formdstate = expression. The identifier afterdbecomes a state variable. The independent variable ist. parameter_names...: symbols used as parameters in the derivative expressions. Their numerical values are supplied by the problem'spargument.
Keywords
This macro does not accept keyword arguments.
Returns
An AbstractParameterizedFunction with generated f, tgrad, and jac methods. Pass it as the f argument of an ODEProblem.
Examples
lotka_volterra = @ode_def begin
dx = a * x - b * x * y
dy = -c * y + d * x * y
end a b c dParameterizedFunctions.@ode_def_bare — Macro
@ode_def_bare [name] begin
dstate = expression
# additional derivative assignments
end parameter_names...Define a parameterized ODE without generating symbolic derivative functions.
Arguments
name: optional name for the generated function type.- derivative assignments: the same assignment-based ODE DSL accepted by
@ode_def. parameter_names...: symbols used as parameters in the expressions.
Keywords
This macro does not accept keyword arguments.
Returns
An AbstractParameterizedFunction with a generated right-hand side and nothing for generated derivative-function fields. Use it when symbolic Jacobian and time gradient generation is unnecessary.
Examples
linear = @ode_def_bare begin
dx = a * x
end aParameterizedFunctions.@ode_def_all — Macro
@ode_def_all [name] begin
dstate = expression
# additional derivative assignments
end parameter_names...Define a parameterized ODE and request every derivative function supported by this DSL, including factorized W functions for small systems.
Arguments
name: optional name for the generated function type.- derivative assignments: the same assignment-based ODE DSL accepted by
@ode_def. parameter_names...: symbols used as parameters in the expressions.
Keywords
This macro does not accept keyword arguments.
Returns
An AbstractParameterizedFunction with generated right-hand side, time-gradient, Jacobian, and supported factorized-W functions.
Examples
linear = @ode_def_all begin
dx = a * x
end ausing ParameterizedFunctions
linear = @ode_def begin
dx = a * x
end a
linear([2.0], [3.0], 0.0)1-element Vector{Float64}:
6.0