TransWikia.com

`NDSolve & WhenEvent` return interpolation function with duplicate points ! How to avoid?

Mathematica Asked by Ulrich Neumann on February 10, 2021

In a simple example I switch the ode depending on two events.

V = NDSolveValue[{  v'[t] == (1 - flag[t]) 3.29 - flag[t] 10.8,v[0] == 10, flag[0] == 0
, WhenEvent[v[t] ==    25, flag[t] -> 1]
, WhenEvent[v[t] ==  0 , "StopIntegration"]
} , v, {t, 0, 10 }, DiscreteVariables -> flag[t] ]    ;

NDSolve seems to work quite good

Plot[V[t], {t, 0, V["Domain"][[1, 2]]}, GridLines -> {None, {10, 25}},PlotRange -> {0,30}]

enter image description here

and returns the plotted (Hermite-) interpolation.

Looking inside V[t] I get the interpolationdata

tv = Transpose[{V["Coordinates"][[1]], V["ValuesOnGrid"]}]

To my surprise there is a duplicate point inside the interpolation data tv

Cases[tv, {___, x_, x_, ___} :> x, All]
(*{{4.55927, 25.}}*)

which comes from the first event detection. That means NDSolve returns an interpolation object, working quite well, with duplicate interpolation points???

My questions:

  • V["InterpolationMethod"](*Hemite*) but Interpolation[tv, Method ->"Hermite"] fails. What kind of interpolation is used by NDSolve ?

  • How could I avoid duplicate points using ‘NDSolve& WhenEvent`?

Thanks!

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP