TITLE: Solving the linear first order differential equation?
QUESTION [5 upvotes]: I was given the equation
$y' = -xy$, where $y(0) = 1$.
My solution was as follows:
$$\frac{dy}{dx} = -xy $$
$$dy = -xy \ dx $$
$$\int {dy} = \int {-xy dx} $$
$$y = -\frac{x^2}{2}y + c $$
$$y + \frac{x^2}{2}y = c $$
$$y(1 + \frac{x^2}{2}) = c $$
$$y = \frac{c}{1 + \frac{x^2}{2}} $$
I tried plugging in $0$ and $1$ respectively to find $c$, and got $c = 0$.
I just know that what I did is wrong. Where did I go wrong, please? Thanks!

REPLY [4 votes]: (Too long for a comment.)
No one else has mentioned this, so I will...  
Remember:  $y$ is a function of $x$, not something that is constant with respect to variation of $x$.  (Forgetting this is a fairly common error when first performing implicit differentiation.)  It can help to write "$y(x)$" rather than just "$y$".
Your error is believing $\int -x y(x) \, \mathrm{d}x = \frac{-1}{2}x^2 y$.  But $y$ is not some constant in this integral; it is a function that depends on $x$.  Otherwise, what is written could be the absurdity (when, say $y(x) = \frac{1}{x^2}$), "$\int -x \cdot \frac{1}{x^2} \,\mathrm{d}x = \frac{-1}{2} x^2 \cdot \frac{1}{x^2} + C_1 = C$" rather than the correct 
$$ \int -x \cdot \frac{1}{x^2} \,\mathrm{d}x = \ln|x| + C  \text{.}  $$
Quick way to verify this:  Implicitly differentiate your antiderivative to see if you get the integrand and differential element back:\begin{align*}
\left( \frac{-1}{2}x^2 y(x) \right)' 
    &= \frac{-1}{2}x^2 (y(x))' + \left( \frac{-1}{2}x^2 \right)' y(x)  \\
    &= \frac{-1}{2}x^2 \,\mathrm{d}y(x) + \left( \frac{-1}{2} \cdot 2 x \,\mathrm{d}x \right) y(x) \\
    &= \frac{-1}{2}x^2 \,\mathrm{d}y(x) - x y(x) \,\mathrm{d}x  \text{,}
\end{align*}
which isn't quite "$- x y\,\mathrm{d}x$".
(However, we have shown \begin{align*}
\int \left( \frac{-1}{2}x^2 \frac{\mathrm{d}y(x)}{\mathrm{d}x} - x y(x) \right) \,\mathrm{d}x 
    &= \int \frac{\mathrm{d}}{\mathrm{d}x} \left( \frac{-1}{2}x^2 y(x) \right) \, \mathrm{d} x  \\
    &= \frac{-1}{2}x^2 y(x) + C  \text{.}
\end{align*}
Familiarity with this kind of manipulation could be useful in the future.)