$\DeclareMathOperator\sgn{sgn}$Trying an finite duration Ansatz to solve $y''=-kg\,\sgn(y')-\gamma y'$, Does it formally solve the problem?
The original Ansatz of \eqref{Eq. 2} ended to be wrong as noted by @Nicolas' answer, so I keep the same question now for the Ansatz of \eqref{Eq. 11}.
Intro
I am trying to understand differential equations of finite duration by making simple examples, on previous questions here MSE 1 and here MSE 2 I think I have found some, but in the last one I found something weird from the physics interpretation of their results so I made a question here PSE, but maybe the problem is not the math but instead I missed some missing term so I move forward and included the air resistance.
Main section
Following this Wikipedia for friction under Coulomb damping | Illustration I should formulate Newton's 2nd law for a brick moving on an horizontal plane as (for positive constants $\{k,\ g,\ m\}$): $$my'' = -F-\sgn(y')kmg \label{Eq. 1}\tag{Eq. 1}$$ Considering $F=by'$ the air resistance as Stoke's drag and calling $\gamma = \frac{b}{m}$ by simplifying the mass I will get: $$y''=-kg\,\sgn(y')-\gamma y' \label{Eq. 2}\tag{Eq. 2}$$
By looking at something I now I tried to use the solution to: $y'' = \pm kg-\gamma y'$ which Wolfram-Alpha found to be $y(t) = c_2+c_1\dfrac{e^{-\gamma t}}{\gamma}\pm\dfrac{kg}{\gamma}t$, so making something similar to what I done on the previous questions I tried an Ansatz $y(t)= A+\sgn(y'_0)\theta(T-t)\left[Be^{-\gamma t}+Ct\right]$ and I tried to match the constants $\{A,\ B,\ C,\ T\}$ assuming it is posible to find a finite extinction time $T>0$ since I don't know beforehand if it is posible, and $\theta(t)$ is the Heaviside step function and $\text{sgn}(t)$ is the Signum function.
Question
After a lot of mistakes I found the following solution:
$$y(t)= y_0+\frac{\sgn(y'_0)}{\gamma}\left(|y'_0|+\frac{kg}{\gamma}\right)-\sgn(y'_0)\left[\frac{1}{\gamma}\left(|y'_0|+\frac{kg}{\gamma}\right)e^{-\gamma t}+\frac{kg}{\gamma}t\right]\cdot\theta\!\left(\frac{1}{\gamma}\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)-t\right)-\sgn(y'_0)\frac{kg}{\gamma^2}\left(1+\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)\right)\cdot\theta\!\left(t-\frac{1}{\gamma}\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)\right) \label{Eq. 3}\tag{Eq. 3}$$
which I am looking to understand if it is indeed solving the equation formally. Here $y_0 := y(0)$ and $y'_0:=y'(0)$.
By calling the (supposedly) finite extinction time: $$T = \frac{1}{\gamma}\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)\label{Eq. 4}\tag{Eq. 4}$$ and the constant term for the time variable: $$g(\require{cancel}\cancel{t}) = \sgn(y'_0)\frac{kg}{\gamma^2}\left(1+\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)\right)\label{Eq. 5}\tag{Eq. 5}$$ I will have that \eqref{Eq. 3} takes a friendlier form: $$y(t)= y_0+\frac{\sgn(y'_0)}{\gamma}\left(|y'_0|+\frac{kg}{\gamma}\right)-\sgn(y'_0)\left[\frac{1}{\gamma}\left(|y'_0|+\frac{kg}{\gamma}\right)e^{-\gamma t}+\frac{kg}{\gamma}t\right]\cdot\theta\!\left(T-t\right)-g(\cancel{t})\cdot\theta\!\left(t-T\right) \label{Eq. 6}\tag{Eq. 6}$$
Here there is some issues that makes think maybe the solution is mistaken:
- I found first the solution without the term $g(\cancel{t})$, but after plotting the solution in Desmos I found the solution at time $t=T$ makes a huge jump, differently from the previous solutions I found on the mentioned questions, so maybe here I made a poor choose of some constants. I hope it could be improved since the term $g(\cancel{t})\cdot\theta\!\left(t-T\right)$ introduces a Dirac's Delta function on the derivative which shouldn't exists in principle, I mean, assuming $g(\cancel{t})\cdot\theta\!\left(t-T\right)\equiv 0$ do solves already the differential equation on $t\leq T$, and since the trivial zero functions also solves \eqref{Eq. 2} it should be possible to find a solutions keeps static after $T>t$ without having these discontinuities.
- I am not fully sure if I do found a solution of finite duration, or if instead, I just sliced a function at half way its trajectory. Assuming $g(\cancel{t})\cdot\theta\!\left(t-T\right)=0$ and looking at $t\to T^-$ what I did is taking $y'(t)$ such $\theta(T^- -t)=1$ but the argument of the function became zero such it stops moving, so I took $T$ by making $\left(|y'_0|+\frac{kg}{\gamma}\right)e^{-\gamma T}-\frac{kg}{\gamma}=0$.
If I didn't messed it up, the distance traveled before the brick stop moving by itself will be: $$\Delta y:=|y(T)-y(0)|=\left|\frac{|y'_0|}{\gamma}-\frac{kg}{\gamma^2}\ln\left(1+\frac{\gamma|y'_0|}{kg}\right)\right| \label{Eq. 7}\tag{Eq. 7}$$ Does it match with the classic ways of solving this problem? (would be a benchmark to see if the solution is right or not).
By the way, I left here the Desmos I used, at least in principle it looks the differential equation is fulfilled by positive and negative initial speeds.

Added later
After the amazing answer by @Nicolas I realized the answer of equation \eqref{Eq. 3} could be improved as he says, but it still has the issue of the jump, but then I tried the following: let match a constant $M$ such as: $$y(t)=y_0+\sgn(y'_0)M-\sgn(y'_0)\left[\frac{1}{\gamma}\left(|y'_0|+\frac{kg}{\gamma}\right)\left(e^{-\gamma t}-1\right)+\frac{kg}{\gamma}t+M\right]\theta(T-t) \label{Eq. 8}\tag{Eq. 8}$$ still using $T$ as defined in \eqref{Eq. 4} and that $\left(|y'_0|+\frac{kg}{\gamma}\right) = \frac{kg}{\gamma}e^{\gamma T}$ (I kept them like this since were easier for me to follow the initial conditions), and noticing that at $t<T$ both $M$ terms cancel each other I could use them to tune the discontinuity by letting it to match: $$ y(T^+):= y_0+\sgn(y'_0)\left(y(T)-y_0\right) \label{Eq. 9}\tag{Eq. 9}$$
implying that: $$ M = \frac{|y'_0|}{\gamma}-\frac{kg}{\gamma^2}\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)\label{Eq. 10}\tag{Eq. 10}$$
with this, keeping it as short as possible (as @Nicolas did) and using $T$ as defined in \eqref{Eq. 4} I can postulate the following solution to the diff. eqn. of \eqref{Eq. 2}:
$$y(t) = y_0+\sgn(y'_0)\left(\frac{|y'_0|}{\gamma}-\frac{kg}{\gamma^2}\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)\right)-\sgn(y'_0)\left[\frac{kg}{\gamma^2}e^{\gamma T}\left(e^{-\gamma t}-1\right)+\frac{kg}{\gamma}t+\frac{|y'_0|}{\gamma}-\frac{kg}{\gamma^2}\ln\left(1+\frac{\gamma |y'_0|}{kg}\right)\right] \cdot \theta\!\left(T-t\right)\label{Eq. 11}\tag{Eq. 11}$$
which should, by construction, fulfill as solution to \eqref{Eq. 2} for whole time (it is still tied to the same issues of the solutions on the previous question), but at least the constant terms, jumps, and the introduced Dirac's delta function of \eqref{Eq. 3} should have been solved, at least, is what could be seen on Desmos 2 (even it show to work for some $\gamma <0$ but looks there exist some $\gamma_{\text{min}}(y'_0,k,g) < 0$ where it stops working).
Last update
After an interesting discussion with @Nicolas belowe his answer, I believe $y(t)$ as depicted by \eqref{Eq. 11} is do solving \eqref{Eq. 2}. Differently from the previous questions, here it is not posible to use the argument $x^n\delta(x)=0$ to avoid the rise of Dirac's Delta functions on the derivatives of $\theta(T-t)$, but here, as a happy accident, what is attached to the delta functions becomes zero at $t=T$ so they get canceled.
Also, as a free gift @Nicolas noticed that $z(t)=y'(t)$ solves the differential equation $z'=-kg\sgn(z)-\gamma z$, making another example of a finite duration differential equation.
Unfortunately I don't have anymore the time to transcript the demostration since I come back to work, but I left a picture of my notebook.
