# Solving the linear first order differential equation?

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!

• Why don't you separate the variables like $$\frac{dy}{y}=-xdx?$$ Also the final conclusion is definitely wrong. – Fakemistake Feb 24 '19 at 9:20

Hint:

This is a variable separable differential equation that is we can separate the differential equation such that for some functions $$f(x)$$ and $$g(y)$$: $$f(x)\mathrm dx =g(y)\mathrm dy$$. $$\dfrac{\mathrm dy}{\mathrm dx}=-xy \implies \int \dfrac{1}{y}\mathrm dy =-\int x \mathrm dx$$

Now all that is left is to compute the integral and use the inital condition to figure out the value of constant. Can you proceed?

Note that you cannot simply integrate $$-xy$$ wrt $$x$$. Your computation assumes that $$y$$ is a constant which it most certainly is not.

• That helped a lot! Thank you! – A.Smith Feb 24 '19 at 15:25

(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.)

After writing

$$\int\frac{\mathrm{d}y}{y}=\int -x\,\mathrm{d}x,$$

you get $$\ln|y|=-\frac{x^2}{2}+c_1$$, which implies

$$y(x)=c\exp(-x^2/2)\quad\text{for}\quad c=\pm\exp(c_1).$$

After plugging in $$y(0)=1$$, you get $$c=1$$, so

$$y(x)=\exp(-x^2/2).$$

• Thank you so so much! I super appreciate it! – A.Smith Feb 24 '19 at 15:53
• You're welcome :) – st.math Feb 24 '19 at 16:32

Here is another method that does not use separation of variables and uses integrating factors. Write $$y'+xy=0$$ and multiply both sides by $$e^{\int x\, dx}=e^{x^2/2}$$ to get that $$0=y'e^{x^2/2}+xye^{x^2/2}=\frac{d}{dx}(ye^{x^2/2}).$$ So $$ye^{x^2/2}=c\implies y=ce^{-x^2/2}$$ for some $$c$$. Since $$y(0)=1$$, we deduce that $$y=\exp(-x^2/2).$$