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

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.)

How about something like this.

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]
2 Likes

Thanks so much! I was missing ‘collect’.