Use ModelingToolkit.jl to solve a maximization problem

Sure, both Symbolics and SymPy allow for vectors of equations. Symbolics only has linear equations for now.

An example that would work for either is:

julia> using SymPy

julia> @syms a[1:2,1:2] b[1:2] x y
(Sym[a₁_₁ a₁_₂; a₂_₁ a₂_₂], Sym[b₁, b₂], x, y)

julia> eqs = [Eq(sum(a[i,:] .* (x,y)), b[i]) for i ∈ 1:2]
2-element Vector{Sym}:
 a₁_₁⋅x + a₁_₂⋅y = b₁
 a₂_₁⋅x + a₂_₂⋅y = b₂

julia> solve(eqs, [x,y])
Dict{Any, Any} with 2 entries:
  y => (a₁_₁*b₂ - a₂_₁*b₁)/(a₁_₁*a₂_₂ - a₁_₂*a₂_₁)
  x => (-a₁_₂*b₂ + a₂_₂*b₁)/(a₁_₁*a₂_₂ - a₁_₂*a₂_₁)

Or

julia> using Symbolics

julia> @variables a[1:2,1:2] b[1:2] x y
4-element Vector{Any}:
  Num[a₁ˏ₁ a₁ˏ₂; a₂ˏ₁ a₂ˏ₂]
  Num[b₁, b₂]
 x
 y

julia> eqs = [sum(a[i,:] .* (x,y)) ~ b[i] for i ∈ 1:2]
2-element Vector{Equation}:
 a₁ˏ₁*x + a₁ˏ₂*y ~ b₁
 a₂ˏ₁*x + a₂ˏ₂*y ~ b₂

julia> Symbolics.solve_for(eqs, [x,y])
2-element Vector{Num}:
 -*(a₁ˏ₁^-1)*(a₁ˏ₂*(a₂ˏ₁*b₁*(a₁ˏ₁^-1) - b₂)*((a₁ˏ₂*a₂ˏ₁*(a₁ˏ₁^-1) - a₂ˏ₂)^-1) - b₁)
                         (a₂ˏ₁*b₁*(a₁ˏ₁^-1) - b₂)*((a₁ˏ₂*a₂ˏ₁*(a₁ˏ₁^-1) - a₂ˏ₂)^-1)
3 Likes