# MTK system based on symbolic arrays fails: type Array has no field lhs

**URL:** https://discourse.julialang.org/t/mtk-system-based-on-symbolic-arrays-fails-type-array-has-no-field-lhs/110455
**Category:** Modelling & Simulations
**Created:** [February 20, 2024, 2:31pm UTC](https://discourse.julialang.org/t/mtk-system-based-on-symbolic-arrays-fails-type-array-has-no-field-lhs/110455 "2024-02-20T14:31:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fabianmueller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabianmueller/32/202905_2.png) [@fabianmueller](https://discourse.julialang.org/u/fabianmueller)
#### Post date: [February 20, 2024, 2:31pm UTC](https://discourse.julialang.org/t/mtk-system-based-on-symbolic-arrays-fails-type-array-has-no-field-lhs/110455/1 "2024-02-20T14:31:36Z")

</div>

I struggle a little bit with a relatively simple MTK model that contains matrix vector multiplications. My example code is the following:

```julia
using ModelingToolkit

Am = [1 0 3; 2 0 1; 0 1 4]
Bm = [4 5; 3 2; 1 4]

@parameters t
Dt = Differential(t)

@assert size(Am, 1) == size(Bm, 1)
nr_of_components = size(Am, 1) # 3
nr_of_incoming_feeds = size(Am, 2) # 3
nr_of_independent_rates = size(Bm, 2) # 2

@parameters begin
    A[1:nr_of_components, 1:nr_of_incoming_feeds] # [3 x 3] matrix
    B[1:nr_of_components, 1:nr_of_independent_rates] # [3 x 2] matrix
end

@variables begin
    u_1(t)[1:nr_of_incoming_feeds] # [2 x 1] vector
    c(t)[1:nr_of_components] # [3 x 1] vector
    q_i(t)[1:nr_of_independent_rates] # [2 x 1] vector
end

eqns = [
    Dt.(c) ~ A * u_1 + B * q_i * c[1] 
]
# This gives:
# 1-element Vector{Symbolics.Arr{Any, 1}}:
# (broadcast(~, broadcast(Differential(t), c(t)), broadcast(+, A*u_1(t), B*broadcast(*, q_i(t), Ref((c(t))[1])))))[Base.OneTo(3)]

@named mdl = ODESystem(eqns)

```

With this I get the error:

```julia
ERROR: type Array has no field lhs
Stacktrace:
 [1] getproperty(x::Vector{Equation}, f::Symbol)
   @ Base ./Base.jl:37
 [2] ODESystem(eqs::Vector{Symbolics.Arr{Any, 1}}, iv::Num; kwargs::@Kwargs{name::String})
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/diffeqs/odesystem.jl:255
 [3] top-level scope
   @ ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/abstractsystem.jl:1127

```

Does somebody knows what this error means and how to fix it? The dimensions of the matrices and vectors should be correct.  
Is it possible to solve this system using symbolic arrays?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 4, 2024, 1:38am UTC](https://discourse.julialang.org/t/mtk-system-based-on-symbolic-arrays-fails-type-array-has-no-field-lhs/110455/2 "2024-03-04T01:38:44Z")

</div>

See the updated docs on symbolic arrays:

> **[Symbolic Arrays · Symbolics.jl](https://symbolics.juliasymbolics.org/stable/manual/arrays/)**
>
> Documentation for Symbolics.jl.

For now I highly recommend the array of structs form though in the near future I will be working on making the non-scalarized form much better.

---

<div class="post-metadata">

### Author: ![fabianmueller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabianmueller/32/202905_2.png) [@fabianmueller](https://discourse.julialang.org/u/fabianmueller)
#### Post date: [June 14, 2024, 4:48pm UTC](https://discourse.julialang.org/t/mtk-system-based-on-symbolic-arrays-fails-type-array-has-no-field-lhs/110455/3 "2024-06-14T16:48:22Z")

</div>

Hey @ChrisRackauckas, thanks again for the advice. Just wanted to point out that these types of vectorized models now work perfectly fine after the v9 update. Keep up the great work, highly appreciate it!
