2

0

In a simple example I try to calculate the time the solution `x[t]`

passes a second time `x[t]==1`

.

```
X = ParametricNDSolveValue[{x''[t] + 2 .3 x'[t] + x[t] == 1,
x[0] == x0, x'[0] == v0, flag[0] == 0
, WhenEvent[x[t] > 1 , {flag[t] -> 1}]
, WhenEvent [(x[t] < 1 ) && (flag[t] == 1) ,"StopIntegration" ]},
x, {t, 0, 10}, {x0, v0} ,DiscreteVariables -> {flag} ];
Plot[X[0, 1][t], {t, 0, X[0, 1]["Domain"][[1]][[-1]]},GridLines -> {{X[0, 1]["Domain"][[1]][[-1]]}, {1}}]
```

Depending on the initial conditions `x0,v0`

I now force the endtime to equal `4`

which can be visualized in

```
ContourPlot[4 == X[x0, v0]["Domain"][[1]][[-1]], {x0, -.7, .7}, {v0, 0, 2},FrameLabel -> {x0, v0}]
```

Works! But if I try to calculate the contour for a special point

```
FindRoot[4 == X[0, v0]["Domain"][[1]][[-1]], {v0, 1}]
(*FindRoot[4 == X[0, v0]["Domain"][[1]][[-1]], {v0, 1}]*)
```

Mathematica can't evaluate!!!

What is wrong here? Thanks!

I am a bit confused about

`["Domain"]`

- it is given as apropertyfor an`InterpolatingFunction`

when I use`PropertyList[ X[0,1]]`

for example. But Mathematica crashes (!) doing`PropertyList[ {X[0,1], All } ]`

which seems to be how`PropertyList`

should be used? – gwr – 2019-02-08T14:32:04.183Instead of

`["Domain"]`

you could also use`[[1]]`

:`X[0, 1][[1]] (*{{0., 4.27631}}*)`

– Ulrich Neumann – 2019-02-08T14:34:51.5931I am getting

`Part::partd`

errors for the`ContourPlot`

(which nontheless produces a plot) and also for the`FindRoot`

which also gives`FindRoot::nlnum`

error. – gwr – 2019-02-08T14:42:34.833With

`Quiet@FindRoot[ With[{v = v0}, 4 == X[0, v]["Domain"][[1, -1]]], {v0, 1}]`

I am getting`{v0 -> 1.49383}`

. – gwr – 2019-02-08T14:49:10.500@gwr: Thanks, after testing your code

`FindRoot[4 == X[0, v0]["Domain"][[1, -1]], {v0, 1}]`

works, mysterious! – Ulrich Neumann – 2019-02-08T14:53:24.060