# Solving $\frac{dy}{dx} = -xy$

I'm trying to solve the differential equation $\frac{dy}{dx} = -xy$.

So far I've got:

$\frac{dy}{dx} = -xy$

$-xy\;dx = dy$

$\frac{1}{y}\;dy = -x\;dx$

$\ln(|y|) = -\frac{1}{2}x^2 + c$ (I combined both integration constants into one)

$y = e^c e^{-\frac{1}{2}x^2}$ or $y = -e^c e^{-\frac{1}{2}x^2}$

It looks correct, but I'm missing one particular case: $y = 0$.

$e^c$ is always positive, and thus is $-e^c$ always negative. Using both, I've included all solutions except $y = 0$.

For $y = 0$, the differential equation does hold though: $\frac{dy}{dx} = 0$ for any $x$, and $-xy = 0$ for any $x$ as well.

What am I missing in my computation?

-
You lost the case $y = 0$ when you divided by $y$. –  Qiaochu Yuan Sep 9 '11 at 18:30
You divided by $y$, so of course that got rid of the case $y=0$, right? So in that stage, you could have written "either $y=0$ or ..." –  GEdgar Sep 9 '11 at 18:32
You've got all but 0.00000000000001 of the solution. –  Michael Hardy Sep 9 '11 at 18:36
BTW, using an asterisk for ordinary multiplication in $\TeX$ is like eating mashed potatoes by hand when silverware is available. You can write $a \times b$ or $a\cdot b$ or $ab$. –  Michael Hardy Sep 9 '11 at 18:37
@Michael Hardy: Thanks, I'm still trying to learn it. Learned quite a bit from your cleanup. –  pimvdb Sep 9 '11 at 18:39

A "general" solution of a differential equation often misses some particular cases, which might be obtained as limits where a parameter goes to $+\infty$ or $-\infty$. In this case you would take $c \to -\infty$ so $e^c e^{-x^2/2} \to 0$. Or you could identify $\pm e^c$ as a new parameter $A$, giving you the solution $y = A e^{-x^2/2}$ (and of course the case $A=0$ works, even though it isn't a value of $\pm e^c$).

-

The equation is $y'+xy=0$. Usually I don't like to divide by $y$, instead, try and make this the derivative of some function by multiplying with an exponential. In this case

$$e^{x^2/2}y'+xe^{x^2/2}y=0 \Leftrightarrow (e^{x^2/2}y)'=0$$

This means that there exists $c$ such that $e^{x^2/2}y=c$ and therefore $y=ce^{-x^2/2}$, and you didn't miss any of the cases.

Of course, the method doesn't work all the time, but this is a linear first order equation, and it is always solvable like this, and there even is a direct formula for solving $y'+p(x)y=q(x)$ when $p,q$ are continuous:

$$\int q(x)dx \cdot e^{-\int p(x)}$$

-
And how do you know what to multiply by in situations like this? The trick is to take your suspected solution -- which will involve a constant of integration $c$ -- solve for $c$, then differentiate both sides of this equation. In this case you differentiate (both sides of) the equation $c=e^{x^2/2}y$, which gives $0=e^{x^2/2}\left[\frac{dy}{dx}+xy\right]$. So multiplying across by $e^{x^2/2}$ is what works in this case. In other situations the function may not be defined at all points $x$, or might involve $y$ which may make things a little trickier. –  Shane O Rourke Sep 9 '11 at 20:57