I have to found the solution of this differential equation: y'=-2-y^2, it look simple but I didn't think so. After solving the differential eqaution I have to plot the solution.
What I do:
function DY=solution(t,y)
DY=$-2-y^2$;
end
$[t,y]=ode45(@solution, [0, 4], 0)$; %% I have this message
Warning: Failure at $t=1.110695e+00$. Unable to meet integration tolerances without reducing the step size below the smallest value allowed $(3.552714e-15)$ at time $t$.
In $ode45$ at $309$
%% $[t,y]=ode45(@solution, [0, 4], 0)$ I get an array of numerical solution
%% in both cases the solution plotted give something not good
plot$(t,y)$[solution figure]1
Notice, we have $$y'=-2-y^2$$ $$\frac{dy}{dt}=-(2+y^2)$$ $$\frac{dy}{2+y^2}=-dt$$ integrating both the sides, we get $$\int \frac{dy}{2+y^2}=-\int dt$$ $$\int \frac{dy}{(\sqrt2)^2+y^2}=-\int dt$$ $$\frac{1}{\sqrt 2}\tan^{-1}\left(\frac{y}{\sqrt 2}\right)=-t+c$$
Can you simplify further?