This is an example in Mathematica's help document.
NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0,
WhenEvent[y[t] == 0, y'[t] -> -0.95 y'[t]]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]
I do a modification like this:
NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0, a = y[t]; b=y'[t];
WhenEvent[a == 0, b -> -0.95 b]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]
It doesn't work.
If I want to keep a new symbol just as here a
to represent the y[t]
or some expression about y[t]
in the WhenEvent
, what can I do to achieve this goal?
(The error may be caused by the HoldAll
attribute of WhenEvent
.
Why I want to replace the y[t]
by a
?
It is important to me. Bucause I will use a dynamic a
in the WhenEvent )
a
why not use aParametricNDSolve
? It might be good, if could show what you want to do. $\endgroup$