Differential Equations: First Order ODEs

Linear Equations & Method of Integrating Factors


A first order ordinary differential equation, or first order ODE, is an equation of the form

$$\dfrac{dy}{dx} = f(x, y).$$

Here, $f(x,y)$ is an arbitrary equation made up of the independent variable $x$ and the dependent variable $y$. The key factor that makes the equation a first order ODE is the fact that only the first derivative, $\dfrac{dy}{dx}$ is present.

When $f$ is linearly dependent on the dependent variable, $y$, then the equation is said to be a first order linear ODE. A first order linear ODE takes the following form:

$$\dfrac{dy}{dx} + p(x)y = g(x).$$

where $p$ and $g$ are each some function of $x$. This form clearly expresses how $y$ is only present linearly, or "by itself" - it is not raised to a power or inside something like a sine or cosine function. The following is an example of a first order linear ODE:

$$\dfrac{dy}{dx} - 2y = 2x.$$

When $p$ and $g$ are constants, i.e. they don't even use the $x$ variable, then the equation can be solved using standard calculus techniques. However, once this severe constraint is loosened to the general case, ordinary calculus tricks come up short. Thankfully, our old pal Leibniz cooked up the method of integrating factors (MIF) to solve these equations.

At first blush, MIF looks like it adds complexity when it should be trying to reduce it. However, think about how many standard methods of integration are derived - many just "undo" some known rule of differentiation. In this instance, MIF undoes the product rule. Keep this in mind as you read how it's done.

The first step is to make sure the equation is in its standard form. From there, multiply each side by a new term $\mu(x)$, known as the (you guessed it) integrating factor:

$$\mu(x)\dfrac{dy}{dx} + \mu(x)p(x)y = \mu(x)g(x).$$

Look at the left side of the equation. It looks somewhat similar to the result differentiation by the product rule. In fact, if we let the following equation hold

$$\dfrac{d\mu(x)}{dx} = \mu(x)p(x),$$

then we can see that

$$\dfrac{d}{dx} \mu(x)y = \dfrac{dy}{dx}\mu(x) + \mu(x)p(x)y.$$

We can then rewrite the initial equation as

$$\dfrac{d}{dx}\left(\mu(x)y\right) = \mu(x)g(x).$$

Integrating both sides with respect to $x$ gives us

$$\mu(x)y + c= \int \mu(x) g(x) \, dx,$$

which we can rearrange as

$$y = \dfrac{1}{\mu(x)} \left( \int \mu(x) g(x) \, dx + c\right).$$

However, since the integral inside the parentheses itself will produce an arbitrary constant of integration, we can drop the one originally produced by the left-hand side of the equation and simplify the equation like so:

$$y = \dfrac{1}{\mu(x)} \int \mu(x) g(x) \, dx.$$

However, this seems to only have swapped one difficult question for another, as we still don't know what the magical $\mu(x)$ term is. However, given our prior assumption about its derivative, we can solve for it. First, let's simply write it out again for reference:

$$\dfrac{d\mu(x)}{dx} = \mu(x)p(x).$$

If we assume $\mu(x)$ is positive, we can divide both sides by $\mu(x)$ to get the following equation

$$\dfrac{d\mu(x)/dx}{\mu(x)} = p(x).$$

From here we can integrate both sides, using the logarithmic rule to evaluate the lefthand side:

$$\ln|\mu(x)| = \int p(x) \, dx + c$$

Since the constant of integration is arbitrary, we can let it equal $0$ for simplicity:

$$\ln|\mu(x)| = \int p(x) \, dx.$$

Finally, we can exponentiate both sides to get rid of that gnarly logarithm:

$$\mu(x) = \text{exp}\left[\int p(x) \, dx\right]$$

Here, we use the alternate $\text{exp}[\ldots]$ notation instead of the traditional $e^x$ notation because the exponent is so large. Note also that $\mu(x)$ is indeed positive, as initially assumed. How amazingly convenient. Leibniz was a smaht cookies, he was. You might be wondering what to do with the constant of integration. The integrating factor need not be of a general form - any kind will do - so the constant can be chosen to make the equation as simple as possible. In fact, as we'll see later, the constants end up canceling themselves out anyway.

Plugging the equation for $\mu(x)$ and the solution to the overall equation together gives us the following monstrosity:

$$y = \dfrac{1}{\text{exp}\left[\int p(x) \, dx\right]} \int \text{exp}\left[\int p(x) \, dx \right] g(x) \, dx.$$

Of course all of this is a pain in the hindquarters to write out, so usually you'll just want to solve for $\mu(x)$ first, then substitute in as necessary.


Problems

  1. Solve the following first order linear ODE: $\dfrac{dy}{dx} - 2y = 2e^x$

    Step 1: Solve for $\mu(x)$:

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int -2 \, dx \\ \ln|\mu(x)| = -2x + c \\ \mu(x) = e^{-2x + c} \\$

    We can choose $c=0$ for simplicity:

    $ \mu(x) = e^{-2x} $

    Step 2: Substitute $\mu(x)$ into original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x) g(x) \, dx \\ y = \dfrac{1}{e^{-2x}} \displaystyle\int e^{-2x} 2e^{x} \, dx \\ y = 2e^{2x} \displaystyle\int e^{-x} \, dx \\ y = 2e^{2x} \left( -e^{-x} + c \right)\\ y = -2e^{x} - 2ce^{2x} \\ y = -2e^{x} + ce^{2x} \\ $

    Note that since the constant of integration, $c$, is arbitrary, we can get rid of the -2 term to simplify things.

    Show Answer
  2. Solve the following first order linear ODE: $\dfrac{dy}{dx} + y = 0$

    Step 1: Solve for $\mu(x)$

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int 1 \, dx \\ \ln|\mu(x)| = x + c \\ \mu(x) = e^{x + c} \\ $

    Let's choose $c=0$ for simplicity.

    $ \mu(x) = e^x \\ $

    Step 2: Substitute $\mu(x)$ into the original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x)g(x) \, dx \\ y = \dfrac{1}{e^x} \displaystyle\int e^x\cdot 0 \, dx \\ y = e^{-x} \displaystyle\int 0 \, dx \\ y = e^{-x} c \\ y = ce^{-x} \\ $

    Show Answer
  3. Solve the following linear first order ODE: $\dfrac{dy}{dx} + 3y = e^x$

    Step 1: Solve for $\mu(x)$:

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int 3 \, dx \\ \ln|\mu(x)| = 3x + c \\ \mu(x) = e^{3x + c} \\$

    We can choose $c=0$ for simplicity:

    $ \mu(x) = e^{3x} $

    Step 2: Substitute $\mu(x)$ into original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x) g(x) \, dx \\ y = \dfrac{1}{e^{3x}} \displaystyle\int e^{3x} e^{x} \, dx \\ y = e^{-3x} \displaystyle\int e^{4x} \, dx \\ y = e^{-3x} \left( \dfrac{1}{4}e^{4x} + c \right)\\ y = \dfrac{1}{4}e^{x} + ce^{-3x} $

    Show Answer
  4. Solve the following first order linear ODE: $\dfrac{dy}{dt} - 2y = t^2e^{2t}$.

    Step 1: Solve for $\mu(t)$

    $ \ln|\mu(t)| = \displaystyle\int p(t) \, dt \\ \ln|\mu(t)| = \displaystyle\int -2 \, dt \\ \ln|\mu(t)| = -2t + c \\ \mu(t) = e^{-2t+c} \\ $

    We can choose $c = 0$ for simplicity

    $ \mu(x) = e^{-2t} $

    Step 2: Substitute $\mu(x)$ into the original equation and solve:

    $ y = \dfrac{1}{\mu(t)} \displaystyle\int \mu(t)g(t) \, dt \\ y = \dfrac{1}{e^{-2t}} \displaystyle\int e^{-2t}t^2e^{2t} \, dt \\ y = e^{2t} \displaystyle\int t^2 \, dt \\ y = e^{2t} \left( \dfrac{1}{3}t^3 + c \right) \\ y = \dfrac{1}{3}t^3e^{2t}+ ce^{2t} \\ $

    Show Answer
  5. Solve the following first order linear ODE: $4\dfrac{dy}{dx} - 8xy = 12x$

    Step 1: Rearrange into standard form:

    $ 4\dfrac{dy}{dx} - 8xy = 12x \\ \dfrac{dy}{dx} - 2xy = 3x \\ $

    Step 2: Solve for $\mu(x)$:

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int -2x \, dx \\ \ln|\mu(x)| = -x^2 + c \\ \mu(x) = e^{-x^2 + c} \\$

    We can choose $c=0$ for simplicity:

    $ \mu(x) = e^{-x^2} $

    Step 3: Substitute $\mu(x)$ into original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x) g(x) \, dx \\ y = \dfrac{1}{e^{-x^2}} \displaystyle\int e^{-x^2} 3x \, dx \\ y = \dfrac{-3}{2}e^{x^2} \displaystyle\int -2xe^{-x^2} \, dx \\ $

    Use $u$-substitution to evaluate the integral by letting $u=-x^2$ such that $du = -2x \, dx$.

    $ y = \dfrac{3}{2}e^{x^2} \left( \displaystyle\int e^u \, du \right) \\ y = \dfrac{3}{2}e^{x^2} \left( e^u + c \right) \\ y = \dfrac{3}{2}e^{x^2} \left( e^{-x^2} + c \right) \\ y = \dfrac{3}{2} + \dfrac{3}{2}ce^{x^2} \\ y = \dfrac{3}{2} + ce^{x^2} \\ $

    Show Answer
  6. Solve the following first order linear ODE: $\dfrac{dy}{dx} + y = xe^{-x} + 1$

    Step 1: Solve for $\mu(x)$

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int 1 \, dx \\ \ln|\mu(x)| = x + c \\ \mu(x) = e^{x+c} \\ $

    We can choose $c = 0$ for simplicity

    $ \mu(x) = e^x $

    Step 2: Substitute $\mu(x)$ into the original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x)g(x) \, dx \\ y = e^{-x} \displaystyle\int e^x\left(xe^{-x} + 1\right) \, dx \\ y = e^{-x} \displaystyle\int x + e^x \, dx \\ y = e^{-x} \left( \dfrac{1}{2}x^2 + e^x + c \right) \\ y = \dfrac{1}{2}x^2e^{-x} + 1 + ce^{-x} \\ $

    Show Answer
  7. Solve the following first order linear ODE: $\dfrac{dy}{dx} - y = 2xe^{2x}$

    $\dfrac{dy}{dx} - y = 2xe^{2x}$

    Step 1: Solve for $\mu(x)$

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int -1 \, dx \\ \ln|\mu(x)| = -x + c \\ \mu(x) = e^{-x+c} \\ $

    We can choose $c = 0$ for simplicity

    $ \mu(x) = e^{-x} $

    Step 2: Substitute $\mu(x)$ into the original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x)g(x) \, dx \\ y = e^x \displaystyle\int e^{-x}\left(2xe^{2x}\right) \, dx \\ y = e^x \displaystyle\int 2xe^x \, dx \\ y = 2e^x \displaystyle\int xe^x \, dx \\ $

    The integral here is solved via integration by parts. This particular integral is already solved in the Integration By Parts problem set.

    $ y = 2e^x \left(xe^x - e^x + c\right) \\ y = 2xe^{2x} - 2e^{2x} + ce^x \\ $

    Show Answer
  8. Solve the following first order linear ODE: $\dfrac{dy}{dx} + y = a\sin(bx)$

    Step 1: Solve for $\mu(x)$

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int 1 \, dx \\ \ln|\mu(x)| = x + c \\ \mu(x) = e^{x+c} \\ $

    We can choose $c = 0$ for simplicity

    $ \mu(x) = e^x $

    Step 2: Substitute $\mu(x)$ into the original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x)g(x) \, dx \\ y = e^{-x} \displaystyle\int ae^x\sin(bx) \, dx \\ y = e^{-x} \displaystyle\int ae^x\sin(bx) \, dx \\ $

    Use integration by parts to solve the integral. The solution to this particular integral can be found in the Integration By Parts problem set.

    $ y = e^{-x} \left( \dfrac{ae^x\sin(bx) - abe^x\cos(bx)}{b^2+1} + c \right) \\ y = ce^{-x} + \dfrac{a\sin(bx)- ab\cos(bx)}{b^2+1} \\ $

    Show Answer
  9. Solve the following first order linear ODE: $(1+t^2)\dfrac{dy}{dt} +4ty = (1+t^2)^{-2}$

    Step 1: Rearrange into standard form:

    $ (1+t^2)\dfrac{dy}{dt} + 4ty = (1+t^2)^{-2} \\ \dfrac{dy}{dt} + \dfrac{4t}{1+t^2}y = (1+t^2)^{-3} \\ $

    Step 2: Solve for $\mu(t)$

    $ \ln|\mu(t)| = \displaystyle\int p(t) \, dt \\ \ln|\mu(t)| = \displaystyle\int \dfrac{4t}{1+t^2} \, dt \\ $

    Solve via $u$-substitution. Let $u = 1+t^2$ such that $\dfrac{du}{dt} = 2t$. Then $du = 2tdu$.

    $ \ln|\mu(t)| = \displaystyle\int \dfrac{2}{u} \, du \\ \ln|\mu(t)| = 2\displaystyle\int \dfrac{1}{u} \, du \\ \ln|\mu(t)| = 2\ln|u| + c \\ \ln|\mu(t)| = 2\ln|1+t^2| + c \\ $

    We can choose $c = 0$ for simplicity

    $ \ln|\mu(t)| = 2\ln|1+t^2| \\ \mu(t) = e^{2\ln|1+t^2|} \\ \mu(t) = \left(1+t^2\right)^2 \\ $

    Step 3: Substitute $\mu(t)$ into the original equation and solve:

    $ y = \dfrac{1}{\mu(t)} \displaystyle\int \mu(t)g(t) \, dt \\ y = \dfrac{1}{\left(1+t^2\right)^2} \displaystyle\int \left(1+t^2\right)^2(1+t^2)^{-3} \, dt \\ y = \dfrac{1}{\left(1+t^2\right)^2} \displaystyle\int (1+t^2)^{-1} \, dt \\ y = \dfrac{1}{\left(1+t^2\right)^2} \left( \tan^{-1}(t) + c \right) \\ y = \dfrac{\tan^{-1}(t)}{\left(1+t^2\right)^2} + \dfrac{c}{\left(1+t^2\right)^2} \\ $

    Show Answer
  10. Solve the following first order linear ODE: $2\dfrac{dy}{dx} + y = 3x^2$

    2\dfrac{dy}{dx} + y = 3x^2

    Step 1: Rearrange into standard form:

    $ 2\dfrac{dy}{dx} + y = 3x^2 \\ \dfrac{dy}{dx} + \dfrac{1}{2}y = \dfrac{3}{2}x^2 \\ $

    Step 2: Solve for $\mu(x)$

    $ \ln|\mu(x)| = \displaystyle\int p(x) \, dx \\ \ln|\mu(x)| = \displaystyle\int \dfrac{1}{2} \, dx \\ \ln|\mu(x)| = \dfrac{1}{2}x + c \\ \mu(x) = e^{(1/2)x + c} \\ $

    We can choose $c = 0$ for simplicity

    $ \mu(x) = e^{(1/2)x} \\ $

    Step 3: Substitute $\mu(x)$ into the original equation and solve:

    $ y = \dfrac{1}{\mu(x)} \displaystyle\int \mu(x)g(x) \, dx \\ y = \dfrac{1}{e^{(1/2)x}} \displaystyle\int e^{(1/2)x} \dfrac{3}{2}x^2 \, dx \\ y = \dfrac{1}{2e^{(1/2)x}} \displaystyle\int e^{(1/2)x} 3x^2 \, dx \\ $

    Use integration by parts to solve the integral. The solution to this particular integral can be found in the Integration By Parts problem set.

    $ y = \dfrac{1}{2e^{(1/2)x}} \left( 6x^2e^{(1/2)x} - 24xe^{(1/2)x} + 48e^{(1/2)x} + c \right) \\ y = 3x^2 - 12x + 24 + \dfrac{c}{e^{(1/2)x}} \\ $

    Show Answer