I am looking to solve the following nonlinear differential equation:
$$y'(t) = |y(t)| + \cos(t),$$ for all $t$ in $[0,4]$ with $y(0) = -1.5$.
I am really confused on how to approach it because of the absolute value.
I am looking to solve the following nonlinear differential equation:
$$y'(t) = |y(t)| + \cos(t),$$ for all $t$ in $[0,4]$ with $y(0) = -1.5$.
I am really confused on how to approach it because of the absolute value.
On
At initial point, $y<0$ thus $|y|=-y$ and the equation is: $$y'(t)=-y(t)+\cos(t)\quad\text{with}\quad y(0)=-\frac32$$ You will find : $$y(t)=-2e^{-t}+\frac12(\sin(t)+\cos(t)) \tag 1$$ which is valid insofar $y<0$ , that is $-2e^{-t}+\frac12(\sin(t)+\cos(t))<0$.
The first root is $t_1\simeq 1.0854188...$ (from numerical calculus).
After, $y$ is positive, $|y|=y$ and the equation becomes : $$y'(t)=y(t)+\cos(t)\quad\text{with}\quad y(t_1)=0$$ You solve it and find : $$y(t)=\frac12 e^{t-t_1}\left(\cos(t_1)-\sin(t_1) \right)+\frac12(\sin(t)-\cos(t)) \tag 2$$ which is valid insofar $y>0$ , that is $\frac12 e^{t-t_1}\left(\cos(t_1)-\sin(t_1) \right)+\frac12(\sin(t)-\cos(t))>0$.
The first root for $t>t_1$ is $t_2\simeq 2.302952...$ (again from numerical calculus).
After, $y$ is negative again and the equation becomes : $$y'(t)=-y(t)+\cos(t)\quad\text{with}\quad y(t_2)=0$$ You solve it and find : $$y(t)=-\frac12 e^{t_2-t}\left(\cos(t_2)+\sin(t_2)\right)+\frac12(\sin(t)+\cos(t)) \tag 3$$ which is valid insofar $y<0$. The next root $t_3\simeq 5.49996...$ is larger than $4$, outside the specified range of study. So we don't go further.
In summary, the solution for all $t$ in [0,4] is :
$$\begin{cases}
\text{Eq.}1\quad\text{ in }\quad 0\leq t\leq t_1 \\
\text{Eq.}2\quad\text{ in }\quad t_1\leq t\leq t_2 \\
\text{Eq.}3\quad\text{ in }\quad t_2\leq t\leq 4
\end{cases}$$

Since $y(0)=-1.5$ and $y$ is continuous the $y(t)$ have to be negative in some interval $[0, m]$ for some $m>0,$ thus in this interval the function $y$ must satisfy the equation $$y' =-y +\cos t$$