Correct way to declare and use vector parameters in ModelingToolkit and PDE


I’m experimenting with PDE and the MethodOfLines.jl. I’m trying to figuring out how to correctly declare and use a parameter which is a float64 vector of variable size.

Here is very basic (and useless) code sample where the system is parametrised by a function fc which takes a vector as argument.

using DifferentialEquations, ModelingToolkit

@parameters α
@variables t X(t)

Dt = Differential(t)

function fc(t,α::Vector{Float64})
    y = 0.0
    for var in α
        y += var * sin(t)
    return y
@register fc(t,α::Vector{Float64})

eq = Dt(X) ~ fc(t,α) * X

@named sys= ODESystem(eq);

X0 = [X=>1.0]

p = [α => [1.0,2.0]];

Howerver, it fails with the error

ERROR: MethodError: no method matching fc(::Num, ::Num)
Closest candidates are:
  fc(::Num, ::SymbolicUtils.Symbolic{<:Vector{Float64}}) at ~/.julia/packages/Symbolics/UrqtQ/src/register.jl:51
  fc(::Real, ::SymbolicUtils.Symbolic{<:Vector{Float64}}) at ~/.julia/packages/Symbolics/UrqtQ/src/register.jl:51
  fc(::Num, ::Vector{Float64}) at ~/.julia/packages/Symbolics/UrqtQ/src/register.jl:51
 [1] top-level scope
   @ ~/Documents/SISTest.jl:18

when defining eq.

I’m new to ModelingToolkit and Symbolics, I guess I’m not using the parameter \alpha correctly.
Is there a correct and standard way to use vector parameters ?
BTW, the example doesn’t make use of MethodOfLines.jl but it’s the final goal to solve PDE involving functions taking vectors as argument.

1 Like

you can’t right now.