I'm trying to solve the following differential equation, involving a nonlinear ff2 (discrete) function ; however, something goes wrong, as NDSolve tries to compute ff2 symbolically.
tab = {-1, 0, 1};
ff2[x_] := Module[{pts, normal, dist, modFn},
pts = Nearest[tab, x][[1]];
normal = Sign[x - pts];
dist = Abs[x - pts];
modFn = (1/(2 0.1) Exp[-(dist/0.1)]);
modFn normal]
c = 0.1; k = 1;
sol = NDSolve[{vx'[t] + c vx[t] + k x[t] == ff2[x[t]],
vx[t] == x'[t], x[0] == 0.1, vx[0] == 0.}, {x, vx}, {t, 0, 10}]
Any hint on how to proceed with this?
ClearAll[ff2]; ff2[x_?NumericQ] :=.... See https://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/26037#26037 (probably a duplicate). – Michael E2 Jun 30 '23 at 13:53