I am trying to solve a differential equation that changes its behaviour depending on the value of the dependent variable. I've tried as shown below, but the computer does not understand my If clause as an "equation or set of equations".
NDSolve[{If[x[t] > 0, x''[t] == -x[t], x''[t] == -2*x[t]], x[0] == 1,
x'[0] == 0}, x, {t, 0, 10}]
How can I make this work?
WhenEvent[]
as @anders describes, but otherwise, yourIf[]
is not properly structured:NDSolve[{x''[t] == If[x[t] > 0, -x[t], -2 x[t]], x[0] == 1, x'[0] == 0}, x, {t, 0, 10}]
$\endgroup$