Skip to content

D(x)-like guesses are not respected during initialization #3049

Closed
@hersle

Description

@hersle

$x\prime\prime(t) = 0$ with $x(0) = 0$ and ${x\prime(0)}^2 = 1$ should initialize with $x\prime(0) = \pm 1$ chosen by an initial guess, and solve to $x(t) = \pm t$:

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations
using Test

for sign in [-1.0, +1.0]
    @variables x(t)
    sys = ODESystem(
        [D(D(x)) ~ 0], t;
        initialization_eqs = [D(x)^2 ~ 1, x ~ 0], guesses = [D(x) => sign], name = :sys
    ) |> structural_simplify
    prob = ODEProblem(sys, [], (0.0, 1.0), [])
    sol = solve(prob, Tsit5())
    @test sol(1.0, idxs=sys.x)  sign # system with D(x(0)) = ±1 should solve to x(1) = ±1
end

But it always chooses the negative branch:

Test Failed at C:\Users\herma\.julia\dev\SymBoltz\bug.jl:14
  Expression: sol(1.0, idxs = sys.x) ≈ sign
   Evaluated: -0.9999999999999956 ≈ 1.0

So it looks like the guess for D(x) is not respected. Is there a missing dummy derivative substitution somewhere, similar to #3029?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions