Differential equations: error on founding solution

236 Views Asked by At

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

3

There are 3 best solutions below

6
On BEST ANSWER

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?

0
On

Using Matlab? Before attempting numerical solution, first attempt a symbolic closed form solution.

Try the $t$ interval [0,1.1] because of vertical asymptote for $ \tan$ function.

3
On

It work good, so now how solve this problem whene I wnat to plot the solution on a bigger interval conataining O for example [-5,5]?