I am afraid to have understood the nonsmoothness of your problem correctly, but since it looks like a typical equation of motion in mechanics, so it may be similar to friction and impacts. For these kind of ODEs exist two classes of numerical solution: event-driven and time-stepping, whereas standard methods assuming smoothness fail.
For the event-driven there is an example (bouncing ball) in the MatLab documentation, for time-stepping (aka event-collecting), I give a simple example (I am not aware of a built-in solver in MatLab)
% Implementation of a time−stepping scheme [Moreau1988]
% for a bouncing ball (1D), ground modeled by unilateral constraint
% y>=0 and coefficient of restitution dy/dt plus=−rc ∗ dydt minus
clear; clc; close all;
N=1000; h=0.01 ; T=N∗h ; t=0:h:T; % time discretization
rc=0.9; % coefficient of restitution
m=1; g=10;
% mass and gravitational acceleration
y=zeros(N+1, 1); v=zeros (N+1, 1) ; % position and velocity arrays
R=zeros(N, 1); % reaction impulse, value at t=0 depends on past
F=zeros(N, 1); % external impulse, value at t=0 does not enter
% i.c . and forcing for bouncing −−> rest "contact closing"
q0=0.5; v0=0; % initial conditions
f=@(t) −m∗g; % external force (continuous−time)
% a sum of a geometric series gets a physical meaning [Zeno's paradoxes]
zenotime=sqrt(8∗q0/g)/(1−rc)−sqrt(2∗q0/g); %assuming v0=0
% i.c. and forcing for resting −−> flight "contact opening"
%q0=0.0; v0=0; % initial conditions
%f=@(t) (−1.2∗sin(t∗2∗pi/T−1)∗m∗g; % external force (continuous−time)
y(1)=q0; v(1)=v0;
for n=1:N
% Euler−forward for y(n+1)=y(n)+v(n)∗h; position
% Euler−backward for velocity
F(n)=h∗f(t(n+1));% integrated force at t=t(n+1)
v(n+1)=v(n)+F(n)/m; % free flight, otherwise overwritten by LCP
% LCP for contact, manually resolved
if (y(n+1)<=0)
% prevent penetration
dv=−(1+rc)∗v(n); % (potential) velocity jump
if (m∗dv)>F(n) % ground can only push, but not pull
v(n+1)=v(n)+dv; % impact law
R(n)=m∗dv−F(n); % reaction force from equation of motion
end % else nothing to do
end % else nothing to do
end
figure;
yyaxis left; plot(t, y, [zenotime, zenotime], [−0.1, 0.6], 'k−−') ;
xlabel('time [s]'); ylabel('position [m]'); ylim([−0.1 0.6])
yyaxis right; plot(t(2:end), R); % R at t=0 is not determined
ylabel ('reaction impulse [Ns]'); ylim ([−1 6] );
For friction I may provide a similar example, too.