How to solve a differential equation with sign function? I was modeling the motion of a spring oscillator with dry friction and thus I met with this equation 
$$kx+\operatorname{sgn} (x′)⋅|f|+mx''=0,$$
where $x$ stands for the position (positive for stretching the spring and negative for compressing it) and $k,|f|$ and $m$ are constants. 
I just want to solve the equation without involving more physics things like the law of energy conservation.
 A: Note that the homogeneous equation is unchanged, in both cases it is  $$mx''+kx=0$$
Whose solution is $x=A\cos(wt+\phi)$ and the speed is $v(t)=-A\sin(wt+\phi)$
At $t=0$ the speed is zero so $\phi=0$ and then it annuls again when $wt=\pi$.
This will be the same for the next interval, the period stays unchanged between the states maximum stretch and maximum compression because the speed annuls in both of these extreme points.
So the movement can be decomposed into intervals $[t_n,t_{n+1}]$ where the speed is of constant sign.
If we note $T=\frac {\pi}{w}$ the period then $t_n=nT$.
$mx''+kx=(-1)^nf\iff x(t)=A_n\cos(wt-n\pi)+(-1)^n\frac fk$
Now we have to find an explicit formula for the amplitude.
$x(0)=x_0=A_0+\frac fk$ so $A_0=x_0-\frac fk$
$x(T)=A_0\cos(\pi)+\frac fk=A_1\cos(0)-\frac fk$ so $A_1=3\frac fk-x_0$
$x(2T)=A_1\cos(\pi)-\frac fk=A_2\cos(0)+\frac fk$ so $A_2=x_0-5\frac fk$
By a simple induction $A_n=(-1)^n(x_0-(2n+1)\frac fk)$

$x(t)=(-1)^n\bigg[\big(x_0-(2n+1)\frac fk\big)\cos(wt-n\pi)+\frac fk\bigg]$

