Differential Equations • Systems of Differential Equations

Compartment Models

Track how substances flow between connected containers using systems of differential equations.

A changing curve with sigma and variable symbols for differential equations
Inside this lesson 10 sections 5 questions 8 figures

SECTION 1

Historical Context & Motivation

For centuries, scientists and engineers have needed to understand how substances move through connected systems. Whether it's salt dissolving in a series of water tanks, medicine distributing through the human body, or pollutants cycling through lakes and rivers, the core question is always the same: how much of a substance is in each part of the system at any given time? Compartment models were developed precisely to answer this question by treating each part of a system as a separate "compartment" and tracking the flow of material between them using differential equations.

1700s • Early Mixing Problems

Mathematicians like Euler studied how fluids mix in connected vessels, laying the groundwork for flow-based differential equations.

1920s • Pharmacokinetics Emerges

Researchers began modeling how drugs distribute through the bloodstream, organs, and tissues using multi-compartment systems, giving rise to the field of pharmacokinetics.

1927 • SIR Epidemic Model

Kermack and McKendrick published the SIR model, dividing a population into Susceptible, Infected, and Recovered compartments to predict disease spread — a breakthrough in epidemiology.

1960s–Today • Environmental & Engineering Applications

Compartment models expanded to ecology, chemical engineering, and climate science. Today, computer simulations let scientists model hundreds of interconnected compartments.

The central challenge that compartment models address is this: when you have multiple interconnected containers and material is constantly flowing in and out, how do you predict the amount in each container over time? A single differential equation can describe one tank, but the moment you connect tanks together, you need a system of differential equations — and that's exactly what this lesson is about.

SECTION 2

Core Principles & Definitions

Before diving into the math, you need to understand the building blocks of every compartment model. The basic idea is surprisingly simple: divide your system into boxes, track what goes in and what goes out of each box, and write a rate equation for each one. These rate equations form a system that you can solve to find how each compartment changes over time.

1

Compartment

A well-mixed region or container holding a measurable quantity (e.g., grams of salt, number of infected people). The substance is assumed to be uniformly distributed within each compartment.
2

Flow Rate

The speed at which fluid or material moves between compartments or enters/exits the system. Typically measured in liters per minute, people per day, etc. Flow rates can be constant or variable.
3

Concentration

The amount of substance per unit volume in a compartment: concentration = amount ÷ volume. For mixing problems, the outflow concentration equals the compartment's current concentration (well-mixed assumption).
4

Balance Law

The fundamental rule: Rate of change = Rate in − Rate out. This conservation principle is the backbone of every compartment equation.
5

System Coupling

When outflow from one compartment becomes inflow for another, their equations become coupled — you can't solve one without knowing the other. This coupling is what makes compartment models a system of differential equations.
✦

KEY TAKEAWAY

Think of a compartment model like a network of bathtubs connected by pipes. Each bathtub has faucets pouring water in and drains letting water out. The water level in each tub depends on all the pipes connected to it. If you know every flow rate, you can write one equation per tub — and the set of all those equations is your system of differential equations.

SECTION 3

Visual Explanation

A Two-Tank Mixing System

The diagram below shows the classic two-compartment mixing problem. An external source pumps a salt solution into Tank 1, and fluid flows between the two tanks and out of the system. Each arrow is labeled with its flow rate, and the concentration of the outflow depends on the current amount of salt divided by the volume in that tank.

Two-Tank Compartment ModelTank 1Volume V₁x₁(t) gramsTank 2Volume V₂x₂(t) gramsf₀ L/minconc. c₀ g/LInflowf₁₂ L/minconc. x₁/V₁f₂₁ L/minconc. x₂/V₂f_out L/minconc. x₂/V₂OutflowBalance Equationsdx₁/dt = f₀·c₀ − f₁₂·(x₁/V₁) + f₂₁·(x₂/V₂)dx₂/dt = f₁₂·(x₁/V₁) − f₂₁·(x₂/V₂) − f_out·(x₂/V₂)
The diagram shows external inflow (cyan arrow) entering Tank 1, inter-tank flows (pink and amber arrows) connecting the two compartments, and outflow (violet arrow) leaving Tank 2. The equations at the bottom express the rate of change of salt in each tank using the balance law: Rate in − Rate out.

Notice how the equation for Tank 1 includes a term involving x₂ (the amount in Tank 2), and the equation for Tank 2 includes a term involving x₁. This is the coupling that makes this a system rather than two independent equations. You must solve both equations together because the rate of change in each tank depends on what's happening in the other.

SECTION 4

Mathematical Framework

Let's formalize the mathematics behind compartment models. The key step is translating the physical setup — tanks, pipes, flow rates — into a precise system of differential equations. We'll start with the general balance law and then see how it applies to a standard two-tank problem.

GENERAL BALANCE LAW

dx/dt=(RateIn)−(RateOut)dx/dt = (Rate In) − (Rate Out)

Here x is the amount of substance in the compartment (grams, moles, people, etc.) and t is time. 'Rate In' includes every source — both external inputs and transfers from other compartments. 'Rate Out' includes every drain.

OUTFLOW RATE FROM A WELL-MIXED TANK

RateOut=f×(x/V)Rate Out = f × (x / V)

f = volumetric flow rate (L/min), x = amount of substance in the tank (grams), V = volume of fluid in the tank (liters). The ratio x/V is the concentration of the substance leaving the tank.

TWO-TANK SYSTEM

dx1/dt=f0c0−(f12/V1)x1+(f21/V2)x2dx2/dt=(f12/V1)x1−(f21/V2)x2−(fout/V2)x2dx₁/dt = f₀c₀ − (f₁₂/V₁)x₁ + (f₂₁/V₂)x₂ dx₂/dt = (f₁₂/V₁)x₁ − (f₂₁/V₂)x₂ − (f_out/V₂)x₂

x₁(t) and x₂(t) = grams of salt in Tank 1 and Tank 2. f₁₂ = flow from Tank 1 to Tank 2, f₂₁ = flow from Tank 2 to Tank 1, c₀ = concentration of the external inflow.

MATRIX FORM

d/dt[x1;x2]=A⋅[x1;x2]+[f0c0;0]d/dt [x₁; x₂] = A · [x₁; x₂] + [f₀c₀; 0]

The system can be written in matrix form where A is a 2×2 coefficient matrix containing the flow-rate-over-volume terms. This matrix notation becomes especially powerful for systems with three or more compartments, and it connects compartment models to linear algebra.

The key insight is that each equation has a negative term proportional to its own variable (substance leaving that tank) and a positive term proportional to the other tank's variable (substance arriving from the other tank). This cross-dependency is what couples the equations together and makes the system interesting to solve.

SECTION 5

Types of Compartment Models

Compartment models come in several varieties depending on the structure of the system and the nature of the flows. Understanding these types helps you recognize which model to use for a given real-world problem.

Types of Compartment ModelsA. Series (Cascade)C₁C₂→ outOne-way flow: 1 → 2 → outB. ParallelC₁C₂in →Independent tanks from same sourceC. Closed LoopC₁C₂Bidirectional: substance recirculatesD. SIR (Epidemic)SIRβSIγISusceptible → Infected → RecoveredComparison TableTypeFlow DirectionCouplingExampleSeriesOne-wayForward onlyDrug absorptionParallelFrom sourceIndependentIrrigation channelsClosed LoopBidirectionalFull couplingSalt-water tanks
Four common types of compartment model: series (cascade), parallel, closed loop, and the classic SIR epidemic model. Each differs in how compartments are connected and whether flow is one-way or bidirectional.

In a series model, substance flows in one direction — like food moving through stages of digestion. A parallel model has compartments that receive input from the same source but don't interact with each other. The closed-loop model is the most fully coupled: substance circulates back and forth, as in the two-tank mixing problem we saw earlier. Finally, the SIR model tracks people rather than chemicals, modeling how individuals transition from susceptible to infected to recovered — the flow rate depends nonlinearly on the product of S and I.

💡

Open vs. Closed Systems

A system is open if material can enter from outside or leave permanently (e.g., an inflow pipe and a drain). It is closed if the total amount of substance stays constant — it just redistributes among compartments. In a closed system, the sum x₁ + x₂ + … never changes.

SECTION 6

Worked Example: Two-Tank Salt Problem

Let's work through a classic problem step by step. Tank 1 holds 100 liters of pure water and Tank 2 holds 100 liters of pure water. A brine solution with a concentration of 2 g/L flows into Tank 1 at 5 L/min. Fluid flows from Tank 1 to Tank 2 at 5 L/min, and fluid flows from Tank 2 out of the system at 5 L/min. The volumes stay constant since every inflow rate equals every outflow rate. Find the system of differential equations and the amount of salt in each tank as t → ∞.

💡

Prerequisite: Integrating Factor Method

Steps 5 and 6 use the integrating factor method to solve first-order linear ODEs of the form dy/dt + P(t)·y = Q(t). The key idea: multiply both sides by a special function μ(t) = e^(∫P dt) called the integrating factor. This turns the left side into an exact derivative, (μy)′ = μQ, which you can integrate directly. If this technique is new to you, review a lesson on first-order linear ODEs before continuing — the balance-law setup in Steps 1–4 stands on its own and is the most important part for understanding compartment models.

Two-Tank Mixing Problem

  1. 1

    Step 1 — Identify the Variables and Given Values

    Let x₁(t) = grams of salt in Tank 1 at time t, and x₂(t) = grams of salt in Tank 2 at time t. Given: V₁ = V₂ = 100 L, inflow rate f₀ = 5 L/min with concentration c₀ = 2 g/L, flow from Tank 1 to Tank 2: f₁₂ = 5 L/min, outflow from Tank 2: f_out = 5 L/min. Initial conditions: x₁(0) = 0, x₂(0) = 0.
    Two unknowns: x₁(t) and x₂(t), both starting at 0.
  2. 2

    Step 2 — Write the Balance Equation for Tank 1

    Rate in: the external inflow brings salt at a rate of f₀ × c₀ = 5 × 2 = 10 g/min. Rate out: fluid leaves Tank 1 at 5 L/min carrying concentration x₁/100, so the outflow rate is 5 × (x₁/100) = x₁/20 g/min.
    dx₁/dt = 10 − x₁/20
  3. 3

    Step 3 — Write the Balance Equation for Tank 2

    Rate in: fluid arrives from Tank 1 at 5 L/min with concentration x₁/100, giving an inflow rate of 5 × (x₁/100) = x₁/20 g/min. Rate out: fluid leaves Tank 2 at 5 L/min with concentration x₂/100, giving an outflow rate of 5 × (x₂/100) = x₂/20 g/min.
    dx₂/dt = x₁/20 − x₂/20
  4. 4

    Step 4 — Write the System

    Combining the two equations, we have a system of first-order linear ODEs: dx₁/dt = 10 − x₁/20 and dx₂/dt = x₁/20 − x₂/20. Notice that the first equation depends only on x₁ (this is because there's no flow from Tank 2 back to Tank 1), so we can solve it independently and then substitute into the second equation.
    This is a series (cascade) compartment model — the first equation decouples.
  5. 5

    Step 5 — Solve the First Equation

    Rewrite dx₁/dt = 10 − x₁/20 in standard linear form: dx₁/dt + x₁/20 = 10. Here P = 1/20, so the integrating factor is μ = e^(∫(1/20)dt) = et/20e^{t/20}. Multiply both sides by et/20e^{t/20}: et/20e^{t/20}·dx₁/dt + (1/20)et/20e^{t/20}·x₁ = 10et/2010e^{t/20}. The left side is the derivative of the product et/20e^{t/20}·x₁, so: d/dt[et/20e^{t/20}·x₁] = 10et/2010e^{t/20}. Integrate both sides: et/20e^{t/20}·x₁ = 200et/20200e^{t/20} + C. Divide by et/20e^{t/20}: x₁ = 200 + Ce−t/20Ce^{−t/20}. Apply x₁(0) = 0: 0 = 200 + C, so C = −200.
    x₁(t) = 200(1 − e−t/20e^{−t/20})
  6. 6

    Step 6 — Solve the Second Equation

    Substitute x₁(t) into dx₂/dt + x₂/20 = x₁/20 = (200/20)(1 − e−t/20e^{−t/20}) = 10(1 − e−t/20e^{−t/20}). The integrating factor is again et/20e^{t/20}. Multiply both sides: d/dt[et/20e^{t/20}·x₂] = 10et/2010e^{t/20}(1 − e−t/20e^{−t/20}) = 10et/2010e^{t/20} − 10. Integrate both sides: et/20e^{t/20}·x₂ = 200et/20200e^{t/20} − 10t + C. Divide by et/20e^{t/20}: x₂ = 200 − 10t·e−t/20e^{−t/20} + Ce−t/20Ce^{−t/20}. Apply x₂(0) = 0: 0 = 200 + C, so C = −200. Therefore x₂(t) = 200 − 200e−t/20200e^{−t/20} − 10t·e−t/20e^{−t/20}, which can be written as x₂(t) = 200 − (200 + 10t)e−t/20e^{−t/20}. As t → ∞, both e−t/20e^{−t/20} → 0 and t·e−t/20e^{−t/20} → 0, so x₂ → 200.
    x₂(t) = 200 − (200 + 10t)e−t/20e^{−t/20}
  7. 7

    Step 7 — Find the Long-Term (Steady-State) Values

    As t → ∞, e−t/20e^{−t/20} → 0 and t·e−t/20e^{−t/20} → 0. Therefore x₁ → 200 g and x₂ → 200 g. This makes sense: at steady state, each tank has concentration 200/100 = 2 g/L, matching the incoming brine concentration. No further change occurs because the inflow and outflow concentrations are equal.
    Steady state: x₁ = x₂ = 200 g (concentration = 2 g/L in each tank)

SECTION 7

Strengths & Limitations

Compartment models are one of the most widely used tools in applied mathematics, but they have both powerful advantages and important limitations. Understanding these will help you decide when a compartment model is the right tool — and when you might need something more sophisticated.

AspectStrengthsLimitations
SimplicityEasy to set up: just apply the balance law to each compartment. The physical intuition is very clear — you can draw the system as boxes and arrows.Oversimplifies reality: real systems (oceans, human bodies) aren't perfectly mixed. Spatial variation within a compartment is ignored.
ScalabilityAdding more compartments is straightforward: just add another equation to the system. Works for 2 tanks or 200 tanks.Large systems become hard to solve by hand. Computer methods (numerical ODE solvers) are needed for more than 3–4 compartments.
VersatilityApplicable across fields: chemistry, biology, medicine, ecology, epidemiology, economics, and engineering.Not suitable for problems where diffusion, spatial gradients, or wave-like behavior matter — those require partial differential equations.
Constant volumesWhen inflow rate equals outflow rate, tank volumes remain constant, keeping the equations linear and solvable.If volumes change over time (e.g., a tank filling up), the equations become nonlinear and much harder to solve analytically.

Strengths vs. Limitations of Compartment Models

✦

KEY TAKEAWAY

A compartment model is like using a road map instead of satellite imagery. The map tells you how cities (compartments) are connected by highways (flow rates) and how traffic (substance) moves between them, but it doesn't capture every back road or neighborhood detail. For most routing decisions, the map is perfectly sufficient — and that's exactly why compartment models are so useful for modeling transfer and mixing problems across science and engineering.

SECTION 8

Connection to Advanced Theory

Compartment models sit at the crossroads of several advanced mathematical topics. If you continue studying math and science in college, you'll see these ideas expanded in exciting ways. Here's a preview of how compartment models connect to the bigger picture.

Compartment Models (This Lesson)Advanced Extension
Two or three tanks with constant flow rates → linear system of ODEsEigenvalue methods: the matrix A from the system x' = Ax + b has eigenvalues that determine how fast the system approaches steady state.
Well-mixed assumption: concentration is uniform within each compartmentPartial differential equations (PDEs): when mixing isn't perfect, you need PDEs that track concentration as a function of both position and time.
SIR model with constant infection/recovery ratesNonlinear dynamics and chaos: real epidemic models (SEIR, SIS) have variable rates and can exhibit complex behaviors like periodic outbreaks.
Exact analytical solutions for small systemsNumerical methods: Euler's method, Runge-Kutta, and other algorithms approximate solutions for large or nonlinear systems on computers.

From Compartment Models to Advanced Mathematics

The beauty of compartment models is that they give you a concrete, visual entry point into systems of differential equations. The skills you're building now — setting up balance laws, recognizing coupling between equations, and interpreting steady-state behavior — are exactly the skills you'll use in college-level courses on linear algebra, dynamical systems, and mathematical modeling. If you master the two-tank problem today, you're well on your way to modeling everything from ocean currents to financial markets.

SECTION 9

Practice Problems

Question 1: CONCEPTUAL

Explain in your own words what it means for two differential equations to be "coupled" in a compartment model. Why can't you solve one equation without knowing the solution to the other?
Show answer
Two equations are coupled when each equation contains the variable from the other equation. For example, in a two-tank closed-loop model, dx₁/dt depends on x₂ and dx₂/dt depends on x₁. You can't solve for x₁(t) alone because the rate of change of x₁ depends on x₂, which is itself changing over time. You must solve both equations simultaneously. In the special case of a series model, the first equation may not depend on the second variable, which allows you to solve it independently — but the second equation still depends on the first.

Question 2: BASIC CALCULATION

A single 50-liter tank contains 10 grams of salt dissolved in water. Pure water flows in at 3 L/min and well-mixed solution drains out at 3 L/min. Write the differential equation for x(t), the grams of salt at time t, and find the general solution.
Show answer
Since pure water enters, Rate in = 0 g/min. The outflow carries concentration x/50 at 3 L/min, so Rate out = 3x/50. The balance law gives dx/dt = 0 − 3x/50 = −3x/50. This is a separable equation whose solution is x(t) = x(0) × e−3t/50e^{−3t/50}. Using x(0) = 10, we get x(t) = 10e−3t/5010e^{−3t/50}. The salt decays exponentially toward 0 because pure water continuously dilutes the tank. After about 50/3 ≈ 16.7 minutes, the salt has dropped to about 10/e ≈ 3.68 grams.

Question 3: INTERMEDIATE

Tank A (80 L) initially has 20 g of salt. Tank B (60 L) initially has 0 g. Fluid flows from A to B at 4 L/min, and fluid flows out of B at 4 L/min. A brine solution with concentration 1 g/L enters Tank A at 4 L/min. Write the system of differential equations. Then determine the steady-state amount of salt in each tank.
Show answer
For Tank A: inflow = 4 × 1 = 4 g/min, outflow = 4 × (x₁/80) = x₁/20 g/min. So dx₁/dt = 4 − x₁/20. For Tank B: inflow from A = 4 × (x₁/80) = x₁/20 g/min, outflow = 4 × (x₂/60) = x₂/15 g/min. So dx₂/dt = x₁/20 − x₂/15. At steady state, dx₁/dt = 0 gives x₁ = 80 g (concentration 80/80 = 1 g/L, matching the inflow). Substituting into dx₂/dt = 0: 80/20 = x₂/15, so x₂ = 60 g (concentration 60/60 = 1 g/L). Both tanks reach a concentration of 1 g/L, equal to the input concentration, which makes physical sense.

Question 4: APPLIED

In a simplified SIR model, a school has 500 students. Initially 5 are infected and 495 are susceptible. The infection rate is β = 0.002 per person per day and the recovery rate is γ = 0.5 per day. Write the system of differential equations. Calculate dS/dt and dI/dt at time t = 0. Is the number of infected students initially increasing or decreasing?
Show answer
The SIR equations are: dS/dt = −βSI, dI/dt = βSI − γI, dR/dt = γI. At t = 0: S = 495, I = 5, R = 0. Compute dS/dt = −0.002 × 495 × 5 = −4.95 people/day. Compute dI/dt = 0.002 × 495 × 5 − 0.5 × 5 = 4.95 − 2.5 = 2.45 people/day. Since dI/dt > 0, the number of infected students is initially increasing at about 2.45 people per day. The infection is spreading because the rate of new infections (4.95/day) exceeds the recovery rate (2.5/day). The epidemic will grow until βSI = γI, i.e., until S drops to γ/β = 0.5/0.002 = 250 students.

Question 5: CRITICAL THINKING

Consider a closed two-tank system with no external inflow or outflow. Tank 1 (100 L) starts with 300 g of salt and Tank 2 (100 L) starts with 0 g. Fluid recirculates: 5 L/min flows from Tank 1 to Tank 2 and 5 L/min flows back from Tank 2 to Tank 1. Write the system of equations, determine the steady-state values, and explain why the total amount of salt is conserved. What does this model predict about how fast equilibrium is reached?
Show answer
The equations are: dx₁/dt = −(5/100)x₁ + (5/100)x₂ = −x₁/20 + x₂/20, and dx₂/dt = (5/100)x₁ − (5/100)x₂ = x₁/20 − x₂/20. Adding the two equations: d(x₁ + x₂)/dt = 0, confirming that total salt x₁ + x₂ = 300 g is conserved — no salt enters or leaves the closed system. At steady state, dx₁/dt = 0 gives x₁ = x₂. Combined with x₁ + x₂ = 300, we get x₁ = x₂ = 150 g (both tanks reach 1.5 g/L). To find the speed, let u = x₁ − x₂. Then du/dt = dx₁/dt − dx₂/dt = −u/10. So u(t) = 300e−t/10300e^{−t/10}. The time constant is 10 minutes, meaning the difference between the tanks halves roughly every 6.9 minutes. After about 30 minutes (3 time constants), the system is within 5% of equilibrium.

SUMMARY

Summary

Summary

Compartment models divide a system into well-mixed regions and use the balance law (Rate of change = Rate in − Rate out) to write a differential equation for each region. When compartments are connected by flows, their equations become coupled, forming a system of differential equations that must be solved together. The outflow rate from each compartment depends on the concentration (amount divided by volume) in that compartment, which changes over time.

Common types include series (cascade) models with one-way flow, closed-loop models with recirculation, and the SIR epidemic model for disease spread. At steady state, all derivatives equal zero and the system reaches equilibrium. The skills you've built here — setting up balance laws, recognizing coupling, and interpreting long-term behavior — form the foundation for advanced work in linear algebra, dynamical systems, and mathematical modeling.

Varsity Tutors • Differential Equations • Compartment Models