4
$\begingroup$

I have to solve the following initial Value problem $$y'=\frac{2xy}{y^2-1}, \quad y(2)=1$$

so, I wrote the following code to solve it

sol = DSolve[{y'[x] == (2*x*y[x])/(y[x]^2 - 1), y[2] == 1}, y[x], x]

and I received the following answer enter image description here.

My question is, how could I improve my code, so I will not have these warning messages?

$\endgroup$
1
  • 2
    $\begingroup$ They are not errors, just warnings that Mathematica may not have found all solutions. It does give you an answer that satisfies the differential equation and boundary condition. You should plot the solution to determine if it makes sense to you. $\endgroup$
    – Bill Watts
    Feb 18 at 0:23

2 Answers 2

5
$\begingroup$

\begin{align*} y^{\prime} & =f\left( x,y\right) \\ & =\frac{2xy}{y^{2}-1}\\ y\left( 2\right) & =1 \end{align*}

We see at $y=1,x=2$ the $f\left( x,y\right) $ is not defined. Hence existence and uniqueness theorem does not apply. There is no guarantee that unique solution exists on an interval that includes $y\left( 2\right) =1$. There could be unique solution, no solution at all, or infinite number of solutions. Theory says nothing about this since it does not apply. Only way is to solve it and find out.

Integrating the ode gives

\begin{align} \int\frac{y^{2}-1}{y}dy & =\int2xdx\nonumber\\ \frac{y^{2}}{2}-\ln y & =x^{2}+c\tag{1}% \end{align}

Applying IC

\begin{align*} \frac{1}{2}-\ln1 & =4+c\\ c & =\frac{1}{2}-4\\ & =-\frac{7}{2}% \end{align*}

Hence solution (1) becomes

$$ \frac{y^{2}}{2}-\ln y=x^{2}-\frac{7}{2} $$

This is an implicit solution. You can leave the solution implicit. But DSolve always tries to find explicit solution and has no option to ask for implicit solution only.

To obtain explicit solution

sol = -7/2 + x^2 - 1/2*y[x]^2 + Log[y[x]] == 0
Solve[sol, y[x]]

Mathematica graphics

Lets checks if both solutions satisfy the ode and the IC. It turns out only one of these does. Which is why DSolve returns one of them and not both.

ode = y'[x] == (2*x*y[x])/(y[x]^2 - 1)
ic = y[2] == 1
ode /. y -> 
   Function[{x}, -I  Sqrt[ProductLog[-E^(7 - 2 x^2)]]] // FullSimplify

Mathematica graphics

ode /. y -> 
   Function[{x}, I  Sqrt[ProductLog[-E^(7 - 2 x^2)]]] // FullSimplify

Mathematica graphics

ic /. y -> 
   Function[{x}, -I  Sqrt[ProductLog[-E^(7 - 2 x^2)]]] // FullSimplify

Mathematica graphics

ic /. y -> 
   Function[{x}, I  Sqrt[ProductLog[-E^(7 - 2 x^2)]]] // FullSimplify

Mathematica graphics

So only the solution with the negative sign satisfy the ode and the IC and that is what DSolve returned.

Compare to output of DSolve

ode = y'[x] == (2*x*y[x])/(y[x]^2 - 1)
ic = y[2] == 1
sol = DSolve[{ode, ic}, y[x], x]

Mathematica graphics

In Maple, it has an option to return implicit solution if a user wants. I hope in future version of Mathematica this can be added. Here is maple's solution

ode:=diff(y(x),x)=(2*x*y(x))/(y(x)^2-1);
ic:=y(2)=1;
sol:=dsolve([ode,ic]);

enter image description here

Here is the implicit one

 sol:=dsolve([ode,ic],y(x),'implicit');

enter image description here

As to the warning message, this is produced by Solve due to having Log[y]. (which is a function of y) Here is a much simpler example

Solve[y^2 == Log[y], y]

Mathematica graphics

Or even

 Solve[y == Log[y], y]

Mathematica graphics

All produce same message. Not sure now if there is a way to add assumptions or other trick to avoid these warning messages. But as mentioned in comment, these are warning and not errors. But always good to look at them even if they are just warning just in case.

$\endgroup$
1
0
$\begingroup$

Try inverse problem

X = Values@
DSolve[{ (y ^2 - 1) == x'[y] (2*x[y]*y ) , x[1] == 2}, x , y][[1,1]]  

Plot[X[y], {y, 0, 5}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.