Skip to content

Indexing a residual of an InitializationProblem #3260

@1-Bart-1

Description

@1-Bart-1

As described here: https://discourse.julialang.org/t/indexing-a-residual-of-an-initializationproblem/123356?u=bart_van_de_lint
Symbolic indexing on the residual of a solution is not possible yet. This would be a good debugging tool. I would suggest this feature to work similarly to normal symbolic indexing. So instead of sol[symbol] it would work like sol.resid[symbol].

Example:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions