Looping constructs, construct equations, ModelingToolkit

Is it possible to define equations using looping constructs, or is there a “correct” way to implement the following systems of equations,

N=3;
@parameters μ ϵ η_ω η_a A β[1:N] ω[1:N] θ[1:N, 1:N] 
@variables z[1:N^2+3*N + 1](t) D_train(..) P(t) W[1:N, 1:N](t)
eqs1 = [Equation(D_train(t), 2 * cos(4 * t + pi/2) + 1.5 * cos(8*t + pi/5) + 1.8 * cos(12 * t + pi/12))    

for i in 1:N
    for j in 1:N
        if i!=j
            D(W[i,j]) ~ A * (exp(im * z[9 + 3*(i-1) + j]/ω[j] )) 
    end
    W[i,i] ~ 0
end
]

Any help is deeply appreciated.

It’s just an array. Just create and array of equations and fill it with a loop

1 Like