Linear Nonhomogeneous First Order Equations

The general form for linear nonhomogenous differential equations of the first order is, $$ \begin{equation*} \tag{1} y^\prime + p(x)y = f(x) \end{equation*} $$
This function is:
We cannot solve such equations by simply separating the $x$ and $y$ terms and then integrating.
To solve, we can consider a simpler equation that is called the complementary equation,
$$ \begin{equation*} \tag{2} y_1^\prime + p(x)y_1 = 0 \end{equation*} $$
And then we make an assumption, that the answer to the nonhomogenious equation is some parameter $u$ multiplied by the solution of the complementary equation.
$$ \begin{equation*} \tag{3} y = u y_1 \end{equation*} $$
This method, solving a difficult equation by first solving a simpler one and multiplying by a parameter, is called variation of parameters.
We start by taking the derivitive of $y$ using the chain rule on equation (3)
$$ y^\prime = u^\prime y_1 + u y_1^\prime $$
Then we substitute this and (3) into the original equation (1)
$$ u^\prime y_1 + u y_1^\prime + p(x)u y_1 = f(x) $$
$$ \underbrace{u^\prime y_1 + u y_1^\prime}_{y^\prime} + p(x)\underbrace{u y_1}_y = f(x) $$
Next factor out $u$ in the second and third terms to get,
$$ u^\prime y_1 + \left(y_1^\prime + p(x) y_1 \right) u= f(x) $$
$$ u^\prime y_1 + \cancelto{0}{\left(y_1^\prime + p(x) y_1 \right)}u= f(x) $$ If we solve (2) correctly, then $y_1^\prime + p(x) y_1 = 0$.
So now we are left with, $$ \begin{equation*} \tag{4} u^\prime y_1 = f(x) \end{equation*} $$
$y_1$ is a function of $x$, so (4) is easily separted and solved by integration.
$$u^\prime = \frac{f(x)}{y_1(x)}$$
$$ \int du =\int \frac{f(x)}{y_1(x)} \, dx$$
$$ u =\int \frac{f(x)}{y_1(x)} \, dx$$
Finally from (3) the solution to $y$ is just $u y_1$

Steps to solve linear nonhomogeneous first order equations using the method of variation of parameters

Given $$y^\prime + p(x)y = f(x),$$
  1. State your intention to use variation of parameters by writing out $y$ in terms of the parameter $u$ and the solution to the complementary equation $y_1$ $$ y = u y_1.$$
  2. Write the complementary equation $$ y^\prime + p(x) y_1 = 0. $$
  3. Solve the complementary equation for $y_1$, ANY non-trivial solution will do.
  4. Write the equation we derived for $f(x)$ $$u^\prime y_1 = f(x)$$
  5. Solve for $u$
  6. Finally substute the values for $y_1$ and $u$ back into the equation from step 1.
Example 1 Find the general solution of $$ \begin{equation*} \tag{1.1} y^\prime + 2y = x^3e^{-2x}. \end{equation*} $$
Answer State your intention to use variation of parameters to solve. $$ \begin{equation*} \tag{1.2} y = u y_1 \end{equation*} $$
Note that the problem as stated is in the proper form,
$$y^\prime + 2y = x^3e^{-2x}.$$
$$\underbrace{y^\prime}_{\text{only } y^\prime} + \underbrace{2}_{p(x)}y = \underbrace{x^3e^{-2x}}_{f(x)}.$$
Often the problems must be rearranged to be in the correct form.
The complementary equation is then, $$ \begin{equation*} \tag{1.4} y_1^\prime + 2y_1 = 0. \end{equation*} $$
Rearrange the complementary equation so that we can integrate to solve. $$y_1^\prime = - 2y_1$$
$$\frac{y_1^\prime}{y_1} = - 2$$
$$\int \frac{dy_1}{y_1} = - \int 2\, dx$$
Solve the integrals $$ \begin{equation*} \tag{1.5} \ln \left| y_1 \right| = - 2x + k \end{equation*} $$
Solve for $y_1$ $$\left| y_1 \right| = e^{- 2x + k}$$
$$\left| y_1 \right| = e^k e^{- 2x}$$
$$ y_1 = \pm e^k e^{- 2x}$$
We can pick a better constant of integration, $$ y_1 = c e^{- 2x}$$
$$ c = \begin{cases} \phantom{-}e^k, & y_1> 0 \\ -e^k, & y_1< 0 \\ \end{cases} $$
At this point any non-trivial solution will do for our purposes, so we can pick the most convient one. $$ \text{choose } c = 1 $$
$$ \begin{equation*} \tag{1.6} y_1 = e^{- 2x} \end{equation*} $$
Skipping the steps between (1.5) and (1.6) is often convenient for finding a solution to the complementary equation but one should always remember these steps exist.
Checking your work so far
It is often a good practice to check your work when possible.
We can use the answer for $y_1$ to check our work.
Take the derivative of (1.6) $$ \frac{dy_1}{dx} = \frac{d}{dx} e^{- 2x} $$
$$ y^\prime = -2 e^{- 2x} $$
Then substitute back into the complementary equation (1.4). $$ y^\prime + 2y = 0 $$
$$ \left(-2 e^{- 2x}\right) + 2 \left(e^{- 2x}\right) = 0 $$
$$ 0 = 0 \, \checkmark $$
A simple check can save a lot of wasted effort.
Next we remember that, $$ u^\prime y_1 = f(x) $$
Substitute in the values for $y_1$ and $f(x)$, $$ u^\prime e^{- 2x} = x^3e^{-2x} $$
Divide both sides of the equation by $e^{- 2x}$ $$ u^\prime = x^3 $$
Then do the integration, $$ \int du = \int x^3 \, dx $$
Then do the integration, $$ u = \frac{x^4}{4} + c$$
At this step we are looking for a general solution so be sure to keep the constant of integration!
Finally we use (1.2) $$ y = u y_1 $$
To get the general solution, $$ \boxed{y = e^{- 2x} \left( \frac{x^4}{4} + c \right) }$$