First-Order Linear Differential Equations

A complete interactive guide — from theory to practice

What You'll Learn

By the end of this lesson, you will be able to:

  1. Identify and write first-order linear ODEs in standard form
  2. Compute the integrating factor for any first-order linear ODE
  3. Solve initial value problems step by step
  4. Visualize solution families through slope fields
  5. Understand how parameters affect solution behavior

What is a First-Order Linear ODE?

A first-order linear ordinary differential equation is an equation that relates an unknown function \(y(x)\) to its first derivative \(y'(x)\). It has the general form:

$$\frac{dy}{dx} + P(x)\,y = Q(x)$$

Here, \(P(x)\) and \(Q(x)\) are known functions of \(x\), and we want to find \(y(x)\). The equation is called linear because \(y\) and \(y'\) appear only to the first power — there are no terms like \(y^2\), \(\sin(y)\), or \(y \cdot y'\).

Common Pitfall

Make sure the coefficient of \(y'\) is exactly \(1\) before applying the method. If you have something like \(3y' + 6y = 9x\), first divide everything by 3 to get \(y' + 2y = 3x\).

Why Does This Matter?

First-order linear ODEs model countless real-world phenomena: radioactive decay, RC electrical circuits, Newton's law of cooling, mixing problems, population dynamics with harvesting, and more. Mastering this equation type gives you a powerful tool that appears throughout engineering and science.

Leonhard Euler systematized the integrating factor method in the 1730s, transforming the solution of linear differential equations from an art into a science. His work laid the foundation for all of modern engineering mathematics.

— Leonhard Euler (1707–1783), who solved more equations than anyone in history

The Integrating Factor Method

The key idea is beautifully simple: we multiply both sides of the equation by a cleverly chosen function — the integrating factor — that transforms the left side into an exact derivative.

Theorem — Integrating Factor

Given the standard form \(\displaystyle \frac{dy}{dx} + P(x)\,y = Q(x)\), define the integrating factor:

$$\mu(x) = e^{\int P(x)\,dx}$$

Then the general solution is:

$$y(x) = \frac{1}{\mu(x)}\left[\int \mu(x)\,Q(x)\,dx + C\right]$$

Why Does It Work?

Let's see why this magic works. Start with:

$$y' + P(x)\,y = Q(x)$$

Multiply both sides by \(\mu(x) = e^{\int P(x)\,dx}\):

$$\mu(x)\,y' + \mu(x)\,P(x)\,y = \mu(x)\,Q(x)$$

Now notice that \(\mu'(x) = P(x)\,\mu(x)\) by the chain rule. So the left side is:

$$\mu(x)\,y' + \mu'(x)\,y = \frac{d}{dx}\big[\mu(x)\,y\big]$$

This is exactly the product rule in reverse! The equation becomes:

$$\frac{d}{dx}\big[\mu(x)\,y\big] = \mu(x)\,Q(x)$$

Now just integrate both sides:

$$\mu(x)\,y = \int \mu(x)\,Q(x)\,dx + C$$

And divide by \(\mu(x)\) to isolate \(y\). That's it!

Key Insight

The integrating factor is designed so that \(\mu' = P \cdot \mu\). This is what makes the left side collapse into a single derivative via the product rule. This is the heart of the entire method.

Step-by-Step Method

Here is the streamlined procedure to solve any first-order linear ODE:

  1. Standard form. Write your equation as \(y' + P(x)\,y = Q(x)\). If there's a coefficient in front of \(y'\), divide through first. Identify \(P(x)\) and \(Q(x)\).
  2. Compute integrating factor. Calculate \(\mu(x) = e^{\int P(x)\,dx}\). Any antiderivative works (no \(+C\) needed).
  3. Apply the direct formula. Use the general solution: $$y = \frac{1}{\mu(x)}\left[\int \mu(x)\,Q(x)\,dx + C\right]$$ Evaluate the integral and simplify.
  4. Apply initial condition (if given). Substitute \(x = x_0\), \(y = y_0\) to find the constant \(C\).
Why the Formula Works

The derivation above (in the Theory section) shows that multiplying by \(\mu(x)\) makes the left side collapse into a product rule derivative: \(\dfrac{d}{dx}[\mu(x)\,y]\). But in practice, you can skip straight to the formula once you know \(\mu(x)\) and \(Q(x)\). The formula encodes all those steps — just plug in and integrate!

Worked Examples

Click each example to reveal the full step-by-step solution.

Step 1: Standard form. Already in standard form: \(P(x) = 2\), \(Q(x) = 6\).

Step 2: Integrating factor.

$$\mu(x) = e^{\int 2\,dx} = e^{2x}$$

Step 3: Apply formula. Use \(y = \dfrac{1}{\mu}\left[\int \mu \cdot Q\,dx + C\right]\):

$$y = \frac{1}{e^{2x}}\left[\int e^{2x} \cdot 6\,dx + C\right] = \frac{1}{e^{2x}}\left[\int 6e^{2x}\,dx + C\right]$$
$$y = \frac{1}{e^{2x}}\left[3e^{2x} + C\right] = 3 + Ce^{-2x}$$

Step 4: Initial condition. Apply \(y(0)=1\):   \(1 = 3 + C\), so \(C = -2\).

$$\boxed{y(x) = 3 - 2e^{-2x}}$$
Interpretation

As \(x \to \infty\), the exponential term dies out and \(y \to 3\). The value \(y=3\) is the equilibrium solution. No matter the initial condition, all solutions converge to 3. Try it in the Explorer below!

Step 1: Standard form. \(P(x) = -3\), \(Q(x) = e^{2x}\).

Step 2: Integrating factor.

$$\mu(x) = e^{\int -3\,dx} = e^{-3x}$$

Step 3: Apply formula.

$$y = \frac{1}{e^{-3x}}\left[\int e^{-3x} \cdot e^{2x}\,dx + C\right] = e^{3x}\left[\int e^{-x}\,dx + C\right]$$
$$y = e^{3x}\left[-e^{-x} + C\right] = -e^{2x} + Ce^{3x}$$
$$\boxed{y(x) = Ce^{3x} - e^{2x}}$$
Note

When \(P(x)\) is negative, solutions grow exponentially rather than decay. The behavior is fundamentally different from Example 1 — explore this in the visualizer!

Step 1: Standard form. Divide by \(x\):

$$y' + \frac{1}{x}\,y = x$$

So \(P(x) = \dfrac{1}{x}\) and \(Q(x) = x\) (for \(x > 0\)).

Step 2: Integrating factor.

$$\mu(x) = e^{\int \frac{1}{x}\,dx} = e^{\ln|x|} = x$$

Step 3: Apply formula.

$$y = \frac{1}{x}\left[\int x \cdot x\,dx + C\right] = \frac{1}{x}\left[\int x^2\,dx + C\right]$$
$$y = \frac{1}{x}\left[\frac{x^3}{3} + C\right] = \frac{x^2}{3} + \frac{C}{x}$$

Step 4: Initial condition. Apply \(y(1) = 2\):   \(2 = \frac{1}{3} + C\), so \(C = \frac{5}{3}\).

$$\boxed{y(x) = \frac{x^2}{3} + \frac{5}{3x}}$$
Variable Coefficients

This example shows that \(P(x)\) doesn't have to be constant. The integrating factor method works just as well for variable-coefficient equations — the integrating factor simply becomes a more interesting function (here, just \(x\)).

Step 1: Standard form. \(P(x) = \tan(x)\), \(Q(x) = \cos(x)\).

Step 2: Integrating factor.

$$\mu(x) = e^{\int \tan(x)\,dx} = e^{-\ln|\cos(x)|} = \sec(x)$$

Step 3: Apply formula.

$$y = \frac{1}{\sec(x)}\left[\int \sec(x)\cdot\cos(x)\,dx + C\right] = \cos(x)\left[\int 1\,dx + C\right]$$
$$y = \cos(x)\left[x + C\right] = (x + C)\cos(x)$$

Step 4: Initial condition. Apply \(y(0) = 0\):   \(0 = (0 + C)\cdot 1\), so \(C = 0\).

$$\boxed{y(x) = x\cos(x)}$$
Elegant Result

Sometimes the integrating factor and \(Q(x)\) simplify beautifully when multiplied together. Here \(\sec(x)\cdot\cos(x) = 1\), making the integration trivial. Always simplify before integrating!

Problem Setup: A 500-liter tank initially contains pure water. A brine solution with concentration 0.05 kg/L flows in at 10 L/min, and the well-mixed solution flows out at the same rate. Find the amount of salt \(A(t)\) in the tank at time \(t\).

Step 1: Set up the equation. Rate of change = (rate in) − (rate out):

$$\frac{dA}{dt} = (0.05)(10) - \frac{A}{500}(10) = 0.5 - \frac{A}{50}$$

Standard form: \(P(t) = \dfrac{1}{50}\), \(Q(t) = 0.5\):

$$\frac{dA}{dt} + \frac{1}{50}\,A = 0.5$$

Step 2: Integrating factor.

$$\mu(t) = e^{\int \frac{1}{50}\,dt} = e^{t/50}$$

Step 3: Apply formula.

$$A = \frac{1}{e^{t/50}}\left[\int e^{t/50}\cdot 0.5\,dt + C\right] = e^{-t/50}\left[0.5 \cdot 50 \cdot e^{t/50} + C\right]$$
$$A = e^{-t/50}\left[25e^{t/50} + C\right] = 25 + Ce^{-t/50}$$

Step 4: Initial condition. Apply \(A(0) = 0\) (pure water):

$$0 = 25 + C \quad \Rightarrow \quad C = -25$$
$$\boxed{A(t) = 25\big(1 - e^{-t/50}\big) \text{ kg}}$$
Physical Interpretation

Equilibrium concentration: As \(t \to \infty\), the tank reaches equilibrium at \(A = 25\) kg, which means the concentration equals the inflow concentration: \(25/500 = 0.05\) kg/L. Time constant: The characteristic time scale \(\tau = 50\) minutes tells us how quickly the tank's composition changes. After time \(\tau\), the tank reaches \((1-e^{-1}) \approx 63\%\) of equilibrium. This mixing problem is fundamental in chemical engineering, used to design reactors, wastewater treatment systems, and pharmaceutical manufacturing processes.

Step 1: Standard form. Divide by $x$:

$$\frac{dy}{dx} + \frac{1}{x}y = 2e^x$$

Thus $P(x) = \dfrac{1}{x}$ and $Q(x) = 2e^x$.

Step 2: Integrating factor.

$$\mu(x) = e^{\int \frac{1}{x}\,dx} = e^{\ln|x|} = x \quad \text{(for } x > 0\text{)}$$

Step 3: Apply formula.

$$y = \frac{1}{x}\left[\int x \cdot 2e^x\,dx + C\right]$$

Integrate by parts with $u = 2x$, $dv = e^x\,dx$:

$$\int 2xe^x\,dx = 2xe^x - \int 2e^x\,dx = 2xe^x - 2e^x = 2e^x(x - 1) + C$$
$$y = \frac{1}{x}\left[2e^x(x-1) + C\right] = 2e^x\left(1 - \frac{1}{x}\right) + \frac{C}{x}$$
$$\boxed{y = 2e^x\left(1 - \frac{1}{x}\right) + \frac{C}{x}}$$
Integration by Parts in Linear ODEs

Key insight: After the integrating factor is applied, the integral $\int \mu(x) \cdot Q(x)\,dx$ must be evaluated. For products like $xe^x$ or $x\sin(x)$, integration by parts is typically required. The formula $\int u\,dv = uv - \int v\,du$ is your most powerful tool when faced with such products. Practice this technique — it appears frequently in applied linear DEs!

Step 1: Standard form. $P(x) = \dfrac{2}{x}$ and $Q(x) = x^2$ (already in standard form).

Step 2: Integrating factor.

$$\mu(x) = e^{\int \frac{2}{x}\,dx} = e^{2\ln|x|} = x^2 \quad \text{(for } x > 0\text{)}$$

Step 3: Apply formula.

$$y = \frac{1}{x^2}\left[\int x^2 \cdot x^2\,dx + C\right] = \frac{1}{x^2}\left[\int x^4\,dx + C\right]$$
$$y = \frac{1}{x^2}\left[\frac{x^5}{5} + C\right] = \frac{x^3}{5} + \frac{C}{x^2}$$
$$\boxed{y = \frac{x^3}{5} + \frac{C}{x^2}}$$
Pattern Recognition: Rational Coefficients

General rule: If $P(x) = \dfrac{n}{x}$ (a constant divided by $x$), then:

$$\mu(x) = e^{\int \frac{n}{x}\,dx} = e^{n\ln|x|} = x^n$$

This gives an integrating factor that is a power of $x$, which is excellent for simplifying products and powers. This pattern appears constantly in applications ranging from heat diffusion to population dynamics. Watch for it!

Step 1: Standard form. $P(x) = \sin(x)$ and $Q(x) = \cos(x)$ (already in standard form).

Step 2: Integrating factor. We have $\int \sin(x)\,dx = -\cos(x) + C_0$, so:

$$\mu(x) = e^{\int \sin(x)\,dx} = e^{-\cos(x)}$$

Step 3: Apply formula.

$$y = \frac{1}{e^{-\cos(x)}}\left[\int e^{-\cos(x)}\cdot\cos(x)\,dx + C\right] = e^{\cos(x)}\left[\int e^{-\cos(x)}\cos(x)\,dx + C\right]$$

Step 4: General (Implicit) Solution.

$$\boxed{y = e^{\cos(x)}\left[\int e^{-\cos(x)}\cos(x)\,dx + C\right]}$$
No Closed Form

Critical insight: The integral $\displaystyle\int e^{-\cos(x)}\cos(x)\,dx$ has no elementary antiderivative. Even though the integrating factor method always works theoretically, it does not always yield a closed-form answer.

In practice: When faced with such integrals, we use numerical methods such as Euler's method, Runge-Kutta algorithms, or specialized ODE solvers (like those in SciPy or MATLAB). These approximate the solution to arbitrary precision without needing a formula.

Lesson: The integrating factor method is a powerful analytical tool, but nature does not always reward us with pretty answers. A working mathematician must be comfortable switching between analytical, numerical, and graphical approaches — and this example is a perfect reminder of that reality!

📝 Exam-Style Practice Problems

These problems are similar in style and difficulty to past exam questions. Click each problem to reveal the step-by-step solution.

Step 1: Write in standard form. Divide by $(1+x^2)$:

$$\frac{dy}{dx} + \frac{2x}{1+x^2}y = \frac{3}{(1+x^2)^2}$$

So $P(x) = \dfrac{2x}{1+x^2}$ and $Q(x) = \dfrac{3}{(1+x^2)^2}$.

Step 2: Find the integrating factor.

$$\mu(x) = e^{\int \frac{2x}{1+x^2}\,dx}$$

Let $u = 1 + x^2$, so $du = 2x\,dx$:

$$\int \frac{2x}{1+x^2}\,dx = \int \frac{du}{u} = \ln|u| = \ln(1+x^2)$$
$$\mu(x) = e^{\ln(1+x^2)} = 1+x^2$$

Step 3: Multiply through by $\mu(x) = 1+x^2$.

$$\frac{d}{dx}[(1+x^2)y] = \frac{3}{(1+x^2)^2} \cdot (1+x^2) = \frac{3}{1+x^2}$$

Step 4: Integrate both sides.

$$(1+x^2)y = \int \frac{3}{1+x^2}\,dx = 3\arctan(x) + C$$

Step 5: Solve for $y$.

$$\boxed{y = \frac{3\arctan(x) + C}{1+x^2}}$$
Pattern Recognition

Notice that $P(x) = \dfrac{2x}{1+x^2}$ is the derivative of $\ln(1+x^2)$. This is a common pattern: whenever you see a derivative-like structure in $P(x)$, the integrating factor simplifies dramatically. Watch for rational functions of the form $\dfrac{f'(x)}{f(x)}$!

Step 1: Write in standard form. Divide by $x$:

$$\frac{dy}{dx} - \frac{3}{x}y = x^3\cos(x)$$

So $P(x) = -\dfrac{3}{x}$ and $Q(x) = x^3\cos(x)$ (for $x > 0$).

Step 2: Find the integrating factor.

$$\mu(x) = e^{\int -\frac{3}{x}\,dx} = e^{-3\ln|x|} = e^{\ln|x|^{-3}} = \frac{1}{x^3}$$

Step 3: Multiply through by $\mu(x) = \dfrac{1}{x^3}$.

$$\frac{d}{dx}\left[\frac{y}{x^3}\right] = \frac{1}{x^3} \cdot x^3\cos(x) = \cos(x)$$

Step 4: Integrate both sides.

$$\frac{y}{x^3} = \int \cos(x)\,dx = \sin(x) + C$$
$$y = x^3(\sin(x) + C)$$

Step 5: Apply initial condition $y(\pi) = 0$.

$$0 = \pi^3(\sin(\pi) + C) = \pi^3(0 + C)$$

Thus $C = 0$.

Particular solution:

$$\boxed{y(x) = x^3\sin(x)}$$
Verification

Check: If $y = x^3\sin(x)$, then $y' = 3x^2\sin(x) + x^3\cos(x)$, so:

$xy' - 3y = x(3x^2\sin(x) + x^3\cos(x)) - 3x^3\sin(x) = 3x^3\sin(x) + x^4\cos(x) - 3x^3\sin(x) = x^4\cos(x)$ ✓

Interactive Slope Field Visualizer

A slope field (or direction field) draws small line segments showing the slope \(y' = Q(x) - P(x)\,y\) at many points. Solution curves must be tangent to these segments everywhere. Type your own equation or use a preset!

Click on the plot to trace a solution curve through that point!

Parameter Explorer

Explore how the solution to \(y' + ay = b\) with \(y(0) = y_0\) changes as you adjust the parameters. The exact solution is:

$$y(x) = \frac{b}{a} + \left(y_0 - \frac{b}{a}\right)e^{-ax}$$
a = 2.0
b = 6.0
y₀ = 1.0
Solution Analysis

Euler's Method vs Exact Solution

See how Euler's method (a simple numerical approximation) compares to the exact solution. Adjust the step size to see how accuracy improves with smaller steps.

h = 0.20
Observe

As you decrease the step size \(h\), Euler's method gets closer to the true solution. The error at each step is approximately \(O(h^2)\), so halving \(h\) roughly halves the local error — but doubles the number of steps needed. This trade-off between accuracy and computation is central to numerical methods.

إِنَّ مَعَ الْعُسْرِ يُسْرًا
"Indeed, with hardship comes ease."
— Quran 94:6

Just as the integrating factor transforms a difficult equation into one that can be solved, perseverance transforms difficulty into mastery. If a problem seems hard, keep working — the clarity will come.

Practice Problems

Test your understanding! Try each problem, then check your answer.

Progress: 0 / 6 completed

Problem 1 — Identify Standard Form

Which of the following is in standard form \(y' + P(x)y = Q(x)\)?

Problem 2 — Integrating Factor

What is the integrating factor for \(y' + 5y = 10\)?

Problem 3 — Solve It

Find the general solution of \(y' + y = e^{-x}\).

Problem 4 — Initial Value Problem

Solve \(y' - y = 2\), \(y(0) = 5\). What is \(y(x)\)?

Problem 5 — Integrating Factor (Variable)

For the equation \(y' + \frac{2}{x}y = x^3\), what is \(\mu(x)\)?

Problem 6 — Long-Term Behavior

For \(y' + 4y = 20\) with any initial condition, what is \(\displaystyle\lim_{x\to\infty} y(x)\)?

Quick Reference Card

Formula Summary

Standard form: \(\quad y' + P(x)\,y = Q(x)\)

Integrating factor: \(\quad \mu(x) = e^{\int P(x)\,dx}\)

General solution: \(\quad \displaystyle y = \frac{1}{\mu}\left[\int \mu \cdot Q\,dx + C\right]\)

For constant coefficients \(y' + ay = b\):

$$y = \frac{b}{a} + \left(y_0 - \frac{b}{a}\right)e^{-ax}$$

Equilibrium: \(\quad y_{eq} = b/a\) (when \(a > 0\), all solutions converge here)