I am trying to solve a first order differential equation using NDSolve
. The differential equation is
g[x[t]] x’[t] + K1 x[t] + f[x[t]] = K2
with x’[0]==0
. Function f is a continuous linear piecewise function and g is df/dx, and it is not a continuous function. It is easy to obtain the exact solution for the different regions, and it is a periodic oscillation with a period of about 1.555 (with the data below). My problem is about the numerical solution because I can’t obtain it using NDSolve. I have tried different options, even using ListInterpolation
for the points in f and g, but the results I obtain is
NDSolve::smpf: Failure to project onto the discontinuity surface when computing Filippov continuation at time 2.031744647155892`.
The code is:
dataOrigIni = {a -> 100.2, b -> 0.99, x1 -> 1.99/100.2, x2 -> 1/0.99, K1 -> 13, K2 -> 2.5};
f[x_] := Piecewise[{{b x, x <= -x2}, {-(((a - b) x1 x2)/(x2 - x1)) + (b x2 - a x1)/(x2 - x1) x, -x2 <= x <= -x1}, {a x, -x1 <= x <= x1}, {((a - b) x1 x2)/(x2 - x1) + (b x2 - a x1)/(x2 - x1) x, x1 <= x <= x2}, {b x, x >= x2}}];
g[x_] := Piecewise[{{b , x <= -x2}, {(b x2 - a x1)/(x2 - x1), -x2 < x < -x1}, {a , -x1 <= x <= x1}, {(b x2 - a x1)/(x2 - x1), x1 < x < x2}, {b , x >= x2}}];
eqn0 = {g[x[t]] x'[t] + K1 x[t] + f[x[t]] == K2, x[0] == 0} /.dataOrigIni
sol0 = NDSolve[eqn0, x[t], {t, 0, 10}]
Any suggest?
Thank you
Images from the closed solution:
I have put together Alex' solution using NDSolve and the obtained by DSolve through theoretical considerations. The comparison is below
They are very similar, but jumping in x[t] is not observed and the periodicity is missing because an increasing drift can be observed. My experience with Mathematica is limited, so I don't know if this is a normal behaviour.
K1
areReal
, not exact. Therefore, your solution is not exact, but some kind of numerical solution. Even with exact parameters this kind of solution is not differentiable in some points, and therefore it can't be solved withNDSolve
directly. Probably we need to addWhenEvent
to this model. $\endgroup$