6
$\begingroup$

The documentation says

WhenEvent expressions can be used in NDSolve, NDSolveValue, ParametricNDSolve, ParametricNDSolveValue, DSolve, and DSolveValue.

But when I try this toy case

DSolve[{f[0]==0,f'[t]==2,WhenEvent[f[t]==5,f[t]->10]},f,t]

It complains that

Equation or list of equations expected instead of WhenEvent[f[t]==5,f[t]->10] in the first argument {f[0]==0,f'[t]==2,WhenEvent[f[t]==5,f[t]->10]}

But when I use this same eqn in NDSolve it works fine. So how do I get WhenEvent working with DSolve?

$\endgroup$
7
$\begingroup$

From the documentation of DSolve, this is classified as a hybrid-differential equation.

You need to specify the range of t something like {0, 10}

DSolve[{f[0] == 0, f'[t] == 2, WhenEvent[f[t] == 5, f[t] -> 10]}, f[t], {t, 0, 10}]

enter image description here

$\endgroup$
  • $\begingroup$ Well now when I look at the DSolve page that's obvious, I swear I checked that already... Thanks. They really should have a better error for that though. $\endgroup$ – TrashGirl Feb 8 '18 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.