# Extracting base symbol from array of symbols

**URL:** <https://discourse.julialang.org/t/extracting-base-symbol-from-array-of-symbols/115476>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit, symbolics\
**Created:** [June 11, 2024, 2:23pm UTC](https://discourse.julialang.org/t/extracting-base-symbol-from-array-of-symbols/115476 "2024-06-11T14:23:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johannesnauta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johannesnauta/32/47434_2.png) [@johannesnauta](https://discourse.julialang.org/u/johannesnauta)\
**Post date:** [June 11, 2024, 2:23pm UTC](https://discourse.julialang.org/t/extracting-base-symbol-from-array-of-symbols/115476/1 "2024-06-11T14:23:06Z")

</div>

I am having trouble creating a dictionary from symbols to numbers for defining an `ODEProblem`. In essence, the problem boils down to having to extract the “base” symbol from a symbolic array. My code is structured in such a way that the function as input gets an `ODESystem` from `ModelingToolkit.jl`. So I need to be able to make the `symbol => value` map using only this system.

A sketch of this issue can be seen as follows. It considers two modules, one that creates the system, and one that should create and `ODEProblem` from it to simulate it using `DifferentialEquations`. The specific system at hand does not matter, so I just use a simple linear system for now.

```julia
# create_sys.jl
function create_system(S)
    @variables t
    @variables (x(t))[1:S]
    @variables a[1:S] b[1:S]
    D = Differential(t)
   
    eqns = [D(x[i]) ~ a[i]*x[i] + b[i] for i in 1:S] 
    @named odesys = ODESystem(eqns, t)
    return odesys
end

```

and then the function that I do not know how to write

```julia
# create_prob.jl
function create_problem(system, X0, avals, bvals, tspan)
    params = parameters(system)
    # Filter parameters and assign [a[i] => avals[i] ...] and [b[i] => bvals[i] ...]
    # [...]
    # pmap = ...
    prob = ODEProblem(complete(system), X0, tspan, pmap)
end

```

I am aware of the `Symbolics.arguments(...)` function, which could potentially be used to filter, but it returns a `SymbolicUtils.BasicSymbolic{Matrix{Real}}` for some reason, and I do not know how to do something like, e.g., `:r == argument(symbol) ? ... : ...`

Any help on this topic is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![johannesnauta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johannesnauta/32/47434_2.png) [@johannesnauta](https://discourse.julialang.org/u/johannesnauta)\
**Post date:** [June 11, 2024, 2:45pm UTC](https://discourse.julialang.org/t/extracting-base-symbol-from-array-of-symbols/115476/2 "2024-06-11T14:45:25Z")

</div>

I just figured out that I can use the `@unpack` macro, possibly in combination with the `hasproperty(odesys, :a)` command, to get the parameters in question.
