I want to check the residual of the solution of an initializationproblem as done in this example: Initialization of ODESystems · ModelingToolkit.jl
However, my model is quite a bit more complex than the one in the example. So I would like to be able to index the residuals:
using ModelingToolkit, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D
@parameters g
@variables x(t) y(t) [state_priority = 10] λ(t)
eqs = [D(D(x)) ~ λ * x
D(D(y)) ~ λ * y - g
x^2 + y^2 ~ 1]
@mtkbuild pend = ODESystem(eqs, t)
iprob = ModelingToolkit.InitializationProblem(pend, 0.0,
[x => 1, y => 0.0, D(y) => 2.0, λ => 1], [g => 1], guesses = [λ => 1])
using NonlinearSolve
sol = solve(iprob)
sol.resid[x] # indexing the residual
But sol.resid[x]
doesn’t work. Is this possible in any other way?