Solving overdetermined systems in ModelingToolkit.jl

Writing Equation(x + y, 2) is not quite right. Users should use ~.

Also, for NonlinearSystem to work, you need to have the same number equations and states. So, it should be

julia> using ModelingToolkit

julia> @variables x, y
(x, y)

julia> sys = NonlinearSystem([x + y ~ 2, x ~ y], [x, y], [])
Equations (2):
 x + y ~ 2
 x ~ y
States (2):
  x
  y
Parameters (0):

julia> equations(alias_elimination(sys))
1-element Vector{Equation}:
 0 ~ 2 - (2y)

julia> observed(alias_elimination(sys))
1-element Vector{Equation}:
 x ~ y

Or to use solve_for

julia> ModelingToolkit.solve_for([x + y ~ 2, x ~ y], [x, y])
2-element Vector{Float64}:
 1.0
 1.0
1 Like