# How to improve the following code to get rid of the warning messages?

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]


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

• 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. Feb 18 at 0:23

\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]]


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


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


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


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


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]


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]);


Here is the implicit one

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


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]


Or even

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


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.

X = Values@