2
$\begingroup$

I wish to plot the solution of the following ODE:

T = 1;
Y = ParametricNDSolveValue[{X'[t] == Boole[X[t]<= 0]  - Boole[X[t] > 0], X[0] == x}, X, {t, 0, T}, {x}];
Show[
 Table[
  ParametricPlot[{Y[x][t], t}, {t, 0, T}],
  {x, -1,1,0.1}
  ],
 PlotRange -> All,
 AxesLabel -> {"x", "t"}
 ]

But the code does not compute: I'm guessing because the characteristic accumulate at zero.

$\endgroup$
2
$\begingroup$
Simplify[Boole[X[t]<= 0]  - Boole[X[t] > 0]]

Piecewise[{{-1, X[t] > 0}}, 1]

So we can simplify ODE and get the plottable solution:

T = 1;
Y = ParametricNDSolveValue[{X'[t] == Piecewise[{{-1, X[t] > 0}}, 1], 
   X[0] == x}, X, {t, 0, T}, {x}]

Plot[Evaluate[Table[Y[x][t], {x, -1, 1, 0.1}]], {t, 0, T}, Frame -> True]

enter image description here

$\endgroup$
1
  • $\begingroup$ That's very nice. Thank you. $\endgroup$ – Riku Dec 20 '19 at 16:15

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.