# Solve $(x+y)^2dx+(2xy+x^2-1)dy=0$

I have a problem trying solving this ODE: $$(x+y)^2dx+(2xy+x^2-1)dy=0$$

I tried the following s=teps: $$M=(x+y)^2dx, N=(2xy+x^2-1)dy$$ $$\frac{\partial M}{\partial y}=2(x+y)=2x+2y$$ $$\frac{\partial N}{\partial x}=2y+2x=\frac{\partial M}{\partial y}\rightarrow Exact$$ $$\varnothing_1=\int Mdx=\int (x+y)^2dx=\frac{(x+y)^3}{3}=\frac{x^3}{3}+\frac{y^3}{3}+xy^2+x^2y$$ $$\varnothing_2=\int Ndy=\int (2xy+x^2-1)dy=xy^2+x^2y-y$$ $$\varnothing=\varnothing_1+\varnothing_2=\frac{x^3}{3}+\frac{y^3}{3}+xy^2+x^2y-y=Constant$$

But if I expand the bracket $(x+y)^2$ before integrating I will get: $$\varnothing_1=\int Mdx=\int (x+y)^2dx=\int (x^2+2xy+y^2)dx=\frac{x^3}{3}+xy^2+x^2y$$ Wich will lead to the solution: $$\varnothing=\varnothing_1+\varnothing_2=\frac{x^3}{3}+xy^2+x^2y-y=Constant$$

What is the wrong step ?

## Help is appreciated.

Edit:

I solved both at y(1)=1 and plotted them on mathematica and got:

So, obviously one is wrong, but which one and why ?

• When you evaluated $\int{(x+y)^2}dx$, you took $y$ to be a constant. When you open the brackets and integrate, the only extra term is $\frac{y^3}{3}$, which was absorbed by the constant of integration. Commented Feb 4, 2016 at 9:33
• But the solution is greatly affected by expansion, so was the expansion is wrong ? Commented Feb 4, 2016 at 9:35

## 1 Answer

The expansion is not wrong. The solution after the expansion is correct.

Look at the steps without the expansion: $$\varnothing_1=\int Mdx=\int (x+y)^2dx=\frac{(x+y)^3}{3}=\frac{x^3}{3}+\frac{y^3}{3}+xy^2+x^2y+C_1(y)\\ \varnothing_2=\int Ndy=\int (2xy+x^2-1)dy=xy^2+x^2y-y+C_2(x)$$

I added $C_1(y)$ and $C_2(x)$ in them since they are multi-variable functions. In the integral with respect to $x$, $C_1(y)$ is the constant term, and similar for the $C_2(x)$.

Notice that $\phi_1$ and $\phi_2$ are both the $\phi$ you are looking for. So your equation $\phi=\phi_1+\phi_2$ is not correct. Instead, it should be $\phi=\phi_1=\phi_2$.

Now compare $\phi_1$ and $\phi_2$ to get $\phi$. You can find that the term $\frac{y^3}{3}$ in $\varnothing_1$ should be dropped (or absorbed in $C_1(y)$) since $\phi_2$ does not have that term, and $C_2(x)$ cannot have that term also. So $C_1(y)$ in this case is $-y-\frac{y^3}{3}+C$. Then the first solution also becomes $$\frac{x^3}{3}+xy^2+x^2y-y=C$$, which is the same as the second one.

• Edit: I solved both at y(1)=1 and plotted them on mathematica and got 2 different graphs. So, obviously one is wrong, but which one and why ? Commented Feb 4, 2016 at 12:13
• @MohamedMostafa: There should be only one solution. What I meant in the answer is in your first solution, $y^3/3$ should be removed. So both of the two solutions are the same, which is $\frac{x^3}{3}+xy^2+x^2y-y=C$. Commented Feb 4, 2016 at 14:13
• Why should it be removed while the integral $\int (x+y)^2dx=\frac{(x+y)^3}{3}$ is correct ? that's what I don't understand. Commented Feb 4, 2016 at 15:41
• @MohamedMostafa: See my edit. Hope it is clear this time. Commented Feb 4, 2016 at 16:20
• It's now clear, thank you :) Commented Feb 5, 2016 at 9:06