# How can I specify a vector of coupled ODEs symbolically (for use in ModelingToolkit)?

**URL:** <https://discourse.julialang.org/t/how-can-i-specify-a-vector-of-coupled-odes-symbolically-for-use-in-modelingtoolkit/89211>\
**Category:** Modelling & Simulations\
**Tags:** differentialequation\
**Created:** [October 24, 2022, 9:22pm UTC](https://discourse.julialang.org/t/how-can-i-specify-a-vector-of-coupled-odes-symbolically-for-use-in-modelingtoolkit/89211 "2022-10-24T21:22:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yohan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yohan/32/31462_2.png) [@yohan](https://discourse.julialang.org/u/yohan)\
**Post date:** [October 24, 2022, 9:22pm UTC](https://discourse.julialang.org/t/how-can-i-specify-a-vector-of-coupled-odes-symbolically-for-use-in-modelingtoolkit/89211/1 "2022-10-24T21:22:50Z")

</div>

I am new to Julia and trying to learn ModelingToolkit. I have looked at the tutorials and they are bit simpler than the use case I have: I would like to implement coupled ODEs for a firing rate-based neuronal network model.

Here’s a minimal example of an equation I’d like to implement.

dx/dt = (1-x) \* E - x \* (W\*E)

Where x and E are vectors and W is a connectivity or adjacency matrix. (I keep getting an error when I upload an image to show an example of the equations.)

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [October 24, 2022, 11:05pm UTC](https://discourse.julialang.org/t/how-can-i-specify-a-vector-of-coupled-odes-symbolically-for-use-in-modelingtoolkit/89211/2 "2022-10-24T23:05:51Z")

</div>

How about something like this.

```julia
julia> using ModelingToolkit

julia> @variables t
1-element Vector{Num}:
 t

julia> D = Differential(t)
(::Differential) (generic function with 2 methods)

julia> @variables x(t)[1:3] E[1:3]
2-element Vector{Symbolics.Arr{Num, 1}}:
 (x(t))[1:3]
 E[1:3]

julia> @parameters W[1:3, 1:3]
1-element Vector{Symbolics.Arr{Num, 2}}:
 W[1:3,1:3]

julia> collect(D.(x) .~ (1 .- x) .* E .- x .* (W*E))
3-element Vector{Equation}:
 Differential(t)((x(t))[1]) ~ (1 - (x(t))[1])*E[1] + (-E[1]*W[1, 1] - E[2]*W[1, 2] - E[3]*W[1, 3])*(x(t))[1]
 Differential(t)((x(t))[2]) ~ (1 - (x(t))[2])*E[2] + (-E[1]*W[2, 1] - E[2]*W[2, 2] - E[3]*W[2, 3])*(x(t))[2]
 Differential(t)((x(t))[3]) ~ (1 - (x(t))[3])*E[3] + (-E[1]*W[3, 1] - E[2]*W[3, 2] - E[3]*W[3, 3])*(x(t))[3]

```

---

<div class="post-metadata">

**Author:** ![yohan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yohan/32/31462_2.png) [@yohan](https://discourse.julialang.org/u/yohan)\
**Post date:** [October 25, 2022, 8:20pm UTC](https://discourse.julialang.org/t/how-can-i-specify-a-vector-of-coupled-odes-symbolically-for-use-in-modelingtoolkit/89211/3 "2022-10-25T20:20:38Z")

</div>

Thanks so much! I was missing ‘collect’.
