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

Hi,

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)
    end
    return y
end
@register fc(t,α::Vector{Float64})

#α=[1.0,2.0]
eq = Dt(X) ~ fc(t,α) * X

@named sys= ODESystem(eq);

X0 = [X=>1.0]

p = [α => [1.0,2.0]];
tspan=(0.0,10.0)
prob=ODEProblem(sys,X0,tspan,p);

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
  
Stacktrace:
 [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.

Sorry for pinging an old thread. Is there a still no way? Even if the Vector is of fixed length? Or do I need to cut into smaller parameters? I currently get the error:

ERROR: MethodError: no method matching hasmetadata(::Vector{Num}, ::Type{Symbolics.VariableDefaultValue})

@xtalax this should be handled now right?