TITLE: How do I find the general solution of this ODE?
QUESTION [1 upvotes]: I'm brand new to differential equations, so when I was given the following equation and told to find the general solution I did this: 
$${dy\over dx}=e^x-y$$
$$\int {dy\over dx}dx = \int (e^x-y)dx$$
$$y(x) = e^x - yx + C$$
But I was given three options to choose from:
i. $y(x) = e^x + C$
ii. $y(x) = Ce^{-x}+{1\over 2}e^x$
iii. $y(x) = e^x - {1\over 2}y^2 + C$
My solution isn't there, so what is it that I'm missing?

REPLY [2 votes]: $y$ depends on $x$, so you can't just integrate it like that. What you actually do to solve this sort of equation (linear in $dy/dx$ and $y$, first-order) is to look for an integrating factor, to write the terms involving $y$ as a single derivative that can just be integrated. For an equation
$$ \frac{dy}{dx} + p(x)y = q(x), $$
the idea is to rewrite the left-hand side as $ \frac{1}{\mu} \frac{d}{dx}(\mu y) $ for some function $\mu(x)$ (because we know how to integrate $(\mu y)'$). Using the product rule implies that this is equal to $ y'+\frac{\mu'}{\mu}y$, so this will work if
$$ \frac{\mu'}{\mu} = p. $$
This is easy to integrate and we find $\mu(x) = e^{\int p(x) \, dx}$ (there's no need for an arbitrary constant since it cancels when we divide by $\mu$).

In this case, $p(x)=1$, so $\mu(x)=e^x$ and the equation becomes
$$ (e^x y)' = e^{2x}. $$
One then integrates once and divides by the integrating factor, which gives
$$ y(x) = Ae^{-x} + \frac{1}{2}e^{x}, $$
where $A$ is a constant arising from the integration. One can check that this satisfies the original equation.
{"set_name": "stack_exchange", "score": 1, "question_id": 2228654}