Differential equation of form: $y^{\prime} + a(x)y = f(x,y)$

I have been working on the solution to the following differential equation:

$$y' + y = \frac{2x}{e^x(1+ye^x)}$$

I am not sure how to solve this type of problem because of the y on the right side... I tried to multiply both sides by the bottom. From there I tried to find the solution as though it were:

$$(1+ye^x)y' + y(1+ye^x) = 0$$

However, I thought that this method of solution required the $$y'$$ to be isolated. If that is not the case, then I am solving it fine. If that is the case, then what am I meant to be doing?

• The solution is of the form $y = -e^{-x} - \sqrt{x^2 + C}$. Plug and verify. – Ahmad Bazzi Aug 25 at 22:00
• Can you explain how you got that? – dminzi Aug 25 at 22:06
• Your homogeneous equation can be factored and as such can be easily solved. – Allawonder Aug 25 at 22:10
• @AhmadBazzi You're sure that's the general solution? No other functions satisfy the equation? – Allawonder Aug 25 at 22:12
• @dminzi I mean that the second equation in OP is trivial since it implies $y'=-y$ or $y=-e^{-x}.$ So well, you'd be right to cancel since the latter doesn't satisfy the original equation in any case. – Allawonder Aug 25 at 23:08

Let $$y=ue^{-x}$$

$$y'=u'e^{-x}-ue^{-x}$$

Your differential equation transforms into

$$u'=\frac {2x}{1+u}$$ Which is separable.

$$\int (1+u)du = \int 2x dx$$

Solve for $$u$$ and substitute in $$y=ue^{-x}$$ to find $$y$$

$$y' + y = \frac{2x}{e^x(1+ye^x)}$$ $$\implies \{ye^x(1+ye^x)-2x\}dx+e^x(1+ye^x)dy=0$$ which is of the form $$M(x,y)dx+N(x,y)dy=0$$ where $$M(x,y)=ye^x(1+ye^x)-2x\qquad \text{and}\qquad N(x,y)=e^x(1+ye^x)$$ Now $$\frac{\partial M}{\partial y}=e^x+2ye^{2x}\qquad \text{and}\qquad \frac{\partial N}{\partial x}=e^x+2ye^{2x}$$ Clearly, $$\frac{\partial M}{\partial y}=\frac{\partial N}{\partial x}$$ So the given differential equation is exact differential equation and its solution is $$\int_{\text{treating ~y~} as constant}M~dx~+~\int(\text{terms in ~N~not containing ~x~})~dy~=~c$$ $$\implies \int_{\text{treating ~y~} as constant}\{ye^x(1+ye^x)-2x\}~dx~+~\int0~dy~=~c$$ $$\implies ye^x~+~\frac{1}{2}y^2~e^{2x}-x^2~=~c$$ $$\implies y=\frac{-e^x\pm\sqrt{e^{2x}- 2~e^{2x}\cdot (-x^2-c)}}{e^{2x}}$$ $$\implies y=\frac{-1\pm\sqrt{1- 2(-x^2-c)}}{e^{x}}$$ where $$~c~$$is constant.