The differential equation
\begin{equation*}
\frac{dx}{dt} + \frac{20}{ 400 - t} x = 5
\end{equation*}
is an example of a first-order linear differential equation. More specifically, a first-order linear differential equation is an equation that can be written in the form
\begin{equation*}
\frac{dx}{dt} + p(t) x = q(t).
\end{equation*}
Let us first show how to solve first-order linear equations when the coefficient functions are constant. If
\begin{align*}
\frac{dx}{dt} + px & = q,\\
x(t_0) & = x_0,
\end{align*}
then we first multiply both sides of the equation by \(e^{pt}\) to obtain
\begin{equation*}
e^{pt} \frac{dx}{dt} + e^{pt} px = q e^{pt}.
\end{equation*}
The left-hand side of the equation is exact. That is,
\begin{equation*}
e^{pt} \frac{dx}{dt} + e^{pt} px = \frac{d}{dt} \left( x(t) e^{pt} \right).
\end{equation*}
If we integrate both sides of
\begin{equation*}
\frac{d}{dt} \left( x(t) e^{pt} \right)= q e^{pt},
\end{equation*}
then
\begin{equation*}
x(t) e^{pt} = \frac{q}{p} e^{pt} + C.
\end{equation*}
If we apply the initial condition, we can determine \(C\text{,}\)
\begin{equation*}
C = \left( x_0 - \frac{q}{p} \right) e^{pt_0}.
\end{equation*}
Thus, the solution that we seek is
\begin{equation*}
x(t) = \frac{q}{p} + \left( x_0 - \frac{q}{p} \right) e^{p(t_0 - t)}.
\end{equation*}
Example 1.5.2.
Suppose we wish to solve the initial value problem
\begin{align}
\frac{dx}{dt} -2 x & = 3,\tag{1.5.4}\\
x(0) & = 1.\tag{1.5.5}
\end{align}
Multiplying both sides of equation
(1.5.4) by
\(e^{-2t}\text{,}\) we obtain
\begin{equation*}
\frac{d}{dt}\left( e^{-2t}x \right) = e^{-2t}\frac{dx}{dt} -2 e^{-2t}x = 3e^{-2t}.
\end{equation*}
Integrating both sides of this last equation, gives us the following
\begin{equation*}
e^{-2t}x = 3 \int e^{-2t} \, dt + C = -\frac{3}{2} e^{-2t} + C.
\end{equation*}
Applying the initial condition \(x(0) = 1\text{,}\) we can conclude that \(C = 5/2\text{,}\) and
\begin{equation*}
x(t) = \frac{5}{2} e^{2t} - \frac{3}{2}.
\end{equation*}
Example 1.5.3.
Now let us solve a first-order linear differential equation where the coefficients are not constant. Suppose that
\begin{equation*}
y' + 2xy = e^{-x^2},
\end{equation*}
where \(y(0) = 1\text{.}\) We will multiply both sides of the equation by \(e^{x^2}\) and use the product rule to obtain
\begin{equation*}
\frac{d}{dx} \left( e^{x^2} y \right) = e^{x^2} y' + 2xe^{x^2}y = e^{x^2} e^{-x^2} = 1.
\end{equation*}
Integrating both sides, we get
\begin{equation*}
e^{x^2} y = \int dx + C.
\end{equation*}
Thus, the general solution is
\begin{equation*}
y = (x + C) e^{-x^2}.
\end{equation*}
Using the initial condition to solve for \(C\text{,}\) we find that \(C = 1\) and
\begin{equation*}
y = (x + 1)e^{-x^2}.
\end{equation*}
We can use Sage to check our solution.
Surprisingly, the strategy in
Example 1.5.3 will always work. Suppose that
\begin{equation}
x' + p(t) x = q(t).\tag{1.5.6}
\end{equation}
If we choose \(P(t)\) such that \(P'(t) = p(t)\) and multiply both sides of the equation by \(e^{P(t)}\text{,}\) then
\begin{equation*}
\left( e^{P(t)} x \right)' = e^{P(t)} ( x'(t) + p(t) x(t) )= e^{P(t)} q(t).
\end{equation*}
Integrating both sides,
\begin{equation*}
e^{P(t)} x = \int e^{P(t)} q(t) \, dt + C
\end{equation*}
or
\begin{equation*}
x = \frac{1}{e^{P(t)} } \left( \int e^{P(t)} q(t) \, dt + C \right).
\end{equation*}
The Fundamental Theorem of Calculus tells us that \(P(t) = \int p(t) \, dt\text{.}\) We say that
\begin{equation*}
\mu(t) = e^{\int p(t) \, dt} = \exp\left( \int p(t) \, dt \right)
\end{equation*}
is an
integrating factor for the differential equation
(1.5.6).
Example 1.5.4.
Consider the initial value problem
\begin{gather*}
\frac{dy}{dx} - \frac{2}{x} y = 2x^2\\
y(-2) = 4.
\end{gather*}
Our integrating factor is
\begin{equation*}
\mu(x) = \exp\left( - \int \frac{2}{x} \, dx\right) = e^{-2 \ln x} = e^{\ln x^{-2}} = x^{-2}.
\end{equation*}
Multiplying both of our differential equation by \(\mu(x) = x^{-2}\text{,}\) we obtain
\begin{equation*}
x^{-2} \left(\frac{dy}{dx} - \frac{2}{x} y \right) = 2
\end{equation*}
or
\begin{equation*}
\frac{d}{dx}\left( x^{-2} y \right) = x^{-2} \frac{dy}{dx} - 2 x^{-3} y = 2.
\end{equation*}
We can now integrate this equation to get
\begin{equation*}
x^{-2} y = 2x + C.
\end{equation*}
The initial condition \(y(-2) = 4\) allows us to find \(C = 5\text{.}\) Therefore, the solution to our initial value problem is
\begin{equation*}
y = 2x^3 + 5x^2.
\end{equation*}