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]
{}
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]
Also NDSolve
sol = NDSolve[{ode, ic}, y, {x, -1, 2}];
Plot[y[x] /. sol, {x, -1, 2}]
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*}