4
$\begingroup$

This ode is first order with unique solution. DSolve can't obtain the solution $y=-x$. Could someone come with workaround to make it give this solution?

$$ y'(x)=\frac{-x^2-2 x y(x)+y(x)^2}{-x^2+2 x y(x)+y(x)^2} $$

With initial conditions $y(1)=-1$

Code

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

enter image description here

{}

The solution can be seen as $y=-x$ from steam plot

f = (y^2 - x^2 - 2*x*y)/(y^2 + 2*x*y - x^2)
StreamPlot[{1, f}, {x, 0, 2}, {y, -2, 2}, 
 StreamPoints -> {{{{1, -1}, Thickness[.01]}, Automatic}}, 
 ImagePadding -> 20, 
 Epilog -> {Red, PointSize[.05], Point[{{1, -1}}]}, PlotRange -> All]

Mathematica graphics

Also NDSolve

sol = NDSolve[{ode, ic}, y, {x, -1, 2}];
Plot[y[x] /. sol, {x, -1, 2}]

Mathematica graphics

The following verifies that $y=-x$ satisfies the ode and the IC

mysol = y -> Function[{x}, -x]
ode /. mysol
(*True*)

And

ic/.mysol
(*True*)

V 13.3.1 on windows 10

Update

Thanks for all the answers. I solved this by hand long time ago, it is one ode in my collection database of odes's (over 12,000 ode's) and was just going over the ones that Mathematica could not solve and found this).

Here is my hand solution. So I was surprised that Mathematica could not solve it. Will check again when V 14 is out.

\begin{align*} \frac{dy}{dx} & =\frac{y^{2}-x^{2}-2xy}{y^{2}-x^{2}+2xy}\\ y\left( 1\right) & =-1 \end{align*} This ode is of type homogeneous. At $x=1,y=-1$ then $f\left( x,y\right) =\frac{y^{2}-x^{2}-2xy}{y^{2}-x^{2}+2xy}$ is defined. And $f_{y}$ is also defined at $x=1,y=-1$. Hence a unique solution exist.

Let $y=ux$ or $u=\frac{y}{x}$, hence $\frac{dy}{dx}=x\frac{du}{dx}+u$ and the above ode becomes \begin{align*} x\frac{du}{dx}+u & =\frac{u^{2}x^{2}-x^{2}-2ux^{2}}{u^{2}x^{2}-x^{2}+2ux^{2}% }\\ x\frac{du}{dx}+u & =\frac{u^{2}-1-2u}{u^{2}-1+2u}\\ x\frac{du}{dx} & =\frac{u^{2}-1-2u}{u^{2}-1+2u}-u\\ & =\frac{u^{2}-1-2u-u\left( u^{2}-1+2u\right) }{u^{2}-1+2u}\\ & =-\frac{u^{3}+u^{2}+u+1}{u^{2}-1+2u} \end{align*} This is separable (homogeneous ode always becomes separable using the substitution$\ y=ux$, if not, then we made mistake). $$ \frac{du}{dx}\left( \frac{u^{2}+2u-1}{u^{3}+u^{2}+u+1}\right) =\frac{-1}{x} $$ Integrating gives \begin{align*} \int\frac{u^{2}+2u-1}{u^{3}+u^{2}+u+1}du & =-\int\frac{1}{x}dx\\ -\ln\left( 1+u\right) +\ln\left( 1+u^{2}\right) & =-\ln x+c_{1} \end{align*} Replacing $u=\frac{y}{x}$ gives $$ -\ln\left( 1+\frac{y}{x}\right) +\ln\left( 1+\frac{y^{2}}{x^{2}}\right) =-\ln x+c $$ Applying exponential to each side gives \begin{align} \left( 1+\frac{y}{x}\right) ^{-1}\left( 1+\frac{y^{2}}{x^{2}}\right) & =c_{1}\frac{1}{x}\nonumber\\ \left( \frac{x}{x+y}\right) \left( \frac{x^{2}+y^{2}}{x^{2}}\right) & =c_{1}\frac{1}{x}\nonumber\\ \left( \frac{x^{2}}{x+y}\right) \left( \frac{x^{2}+y^{2}}{x^{2}}\right) & =c_{1}\nonumber\\ x^{2}+y^{2} & =c_{1}\left( x+y\right) \nonumber\\ \frac{1}{c_{1}}\left( x^{2}+y^{2}\right) & =x+y\nonumber\\ c_{2}\left( x^{2}+y^{2}\right) & =x+y\tag{1} \end{align}

At $y\left( 1\right) =-1$ the above gives $$ 2c_{2}=0 $$ Hence $$ c_{2}=0 $$ Therefore from (1) \begin{align*} x+y & =0\\ y & =-x \end{align*}

$\endgroup$
1
  • $\begingroup$ 'DSolve[{(y[x]^2 + 2*xy[x] - x^2) y'[x]== (y[x]^2 - x^2 - 2*xy[x]), y[1]==1}, ...]' gets you a little further. $\endgroup$ Commented Dec 29, 2023 at 8:45

4 Answers 4

3
$\begingroup$

The answer to the question has already been given. My aim below is only to add some analytical explanation.

The general solution of the PDE : $$y'(x)=\frac{-x^2-2 x y(x)+y(x)^2}{-x^2+2 x y(x)+y(x)^2}\tag 1$$ given on the form of implicit equation is : $$\boxed{y+x+c(y^2+x^2)=0}\tag 2$$ $c$ is an arbitrary constant.

Proof : $$y'+1+2c(y\:y'+x)=0$$ $$y'=-\frac{1+2c\,x}{1+2c\,y}=-\frac{1+2(-\frac{y+x}{y^2+x^2})\,x}{1+2(-\frac{y+x}{y^2+x^2})\,y}$$ After simplification :

$\quad y'=\frac{y^2-x^2-2xy}{y^2-x^2+2xy}\quad$ is exactly the original ODE which proves that Eq.(2) is solution of Eq.(1).

The analytic solution (2) is the equation of a family of circles if $c\neq 0$ and a straigth line $y+x=0$ id $c=0$.

Note : On the graphs the curves appear like ellipses instead of circles if the x-axis and y-axis are not graduated with the same unit length.

On explicit form the general solution is : $$\boxed{\begin{cases} y=-x\quad\text{if}\quad c=0\\ y= -\frac{1}{2c}\big(1\pm \sqrt{1-4c\,x-4c^2x^2} \big)\quad\text{if}\quad c\neq 0 \end{cases}}$$ These exact equations may be used to check the accuracy of the numerical step-by-step calculus for solving the ODE.

Particular solution satisfying the condition $y(1)=-1$ :

from the general solution with $x=1$ and $y=-1$ :

$1+(-1)+c(1^2+(-1)^2)=0\quad\implies\quad 2c=0\quad\implies\quad c=0$.

Thus the solution satisfying both the ODE and the condition is $y=-x$ as expected.

enter image description here

$\endgroup$
6
$\begingroup$

If you solve your ode without initial conditions

ode = y'[x] == (y[x]^2 - x^2 - 2*x*y[x])/(y[x]^2 + 2*x*y[x] - x^2)
ic = y[1] == -1
{y1, y2} = (Values@DSolve[{ode }, y, x ] // Flatten) /. C[1] -> c1

you get two solutions.

Only the first solution may fullfill y[1]==-1

Plot[{y1[1], y2[1]}, {c1, -5, 5}, PlotRange -> {-2, 2},PlotStyle -> {Blue, Red}]

enter image description here

Asymptotic[y1[x], c1 -> Infinity] 
(*ConditionalExpression[-x, x \[Element] Reals]*)
$\endgroup$
4
$\begingroup$

Look at:

sol = DSolve[{ode}, y[x], x];
Plot[y[x] /. sol /. C[1] -> {-1, 0, 1}, {x, -1, 4}]

enter image description here

Therefore, for finite C1, y=-x is only tangent to sol[1] for x==0. I am not sure if this already counts as a singular solution. Only for C1== Infinity y=-x is a solution.

$\endgroup$
3
$\begingroup$

I add that AsymptoticDSolveValue calculates well the solution that DSolve doesn't detect:

AsymptoticDSolveValue[{ode, ic}, y[x], x -> 1]

(*-x*)
$\endgroup$

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