Hi, I would like to convert a numeric differential-algebraic equation to a symbolic model using modelingtoolkitize
. However, when then trying to convert it back to an ODEProblem, I get an overdetermined warning and when trying to solve it an InitialFailue
. The overdetermined warning is expected since I have 2 initial conditions + 1 algebraic equation but only 2 unknowns. I would like to get rid of the initial condition on u[2]
but am not sure how to do this.
Here’s and MWE with some comments explaining where it goes wrong.
# Minimum working example of an overdetermined DAE when using modelingtoolkitize.
using ModelingToolkit
using DifferentialEquations
using Plots
using LinearAlgebra
# Making the ODEFunction representing a DAE.
function dae!(du, u, p, t)
du[1] = u[2]
du[2] = u[1] + u[2]
end
mass_matrix = Diagonal([1, 0])
fun! = ODEFunction(dae!; mass_matrix)
# Making the ODEProblem where we start with in inconsistent initial condition. (We specify 2
# initial conditions and have 1 algebraic equation but only 2 unknowns.)
u0 = [1.0, 0.0]
tspan = (0.0, 10.0)
prob1 = ODEProblem(fun!, u0, tspan)
# When solving, DifferentialEquations finds a suitable initial condition by changing u0[2].
sol1 = solve(prob1)
display(plot(sol1))
println(sol1[1]) # [1.0, -1.0], different from our initial condition as expected.
# Converting it to a ModelingToolkit model.
u_names = [:u1, :u2]
@mtkcompile sys = modelingtoolkitize(prob1; u_names)
prob2 = ODEProblem(sys, [], tspan) # Gives a warning that the system is overdetermined.
sol2 = solve(prob2) # InitialFailure.
I would like to remove the initial condition for u[2]
to make the system fully determined but I’m not sure how to do this.
Thanks in advance.