DIFFERENTIAL EQUATIONS • SYSTEMS OF DIFFERENTIAL EQUATIONS

Compartment Models

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

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.

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.

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.

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.

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 = (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
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
dx₁/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 [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.

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.

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.

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
Step 1 — Identify the Variables and Given ValuesLet 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
Step 2 — Write the Balance Equation for Tank 1Rate 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
Step 3 — Write the Balance Equation for Tank 2Rate 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
Step 4 — Write the SystemCombining 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
Step 5 — Solve the First EquationRewrite 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) = e^(t/20). Multiply both sides by e^(t/20): e^(t/20)·dx₁/dt + (1/20)e^(t/20)·x₁ = 10e^(t/20). The left side is the derivative of the product e^(t/20)·x₁, so: d/dt[e^(t/20)·x₁] = 10e^(t/20). Integrate both sides: e^(t/20)·x₁ = 200e^(t/20) + C. Divide by e^(t/20): x₁ = 200 + Ce^(−t/20). Apply x₁(0) = 0: 0 = 200 + C, so C = −200.
x₁(t) = 200(1 − e^(−t/20))
6
Step 6 — Solve the Second EquationSubstitute x₁(t) into dx₂/dt + x₂/20 = x₁/20 = (200/20)(1 − e^(−t/20)) = 10(1 − e^(−t/20)). The integrating factor is again e^(t/20). Multiply both sides: d/dt[e^(t/20)·x₂] = 10e^(t/20)(1 − e^(−t/20)) = 10e^(t/20) − 10. Integrate both sides: e^(t/20)·x₂ = 200e^(t/20) − 10t + C. Divide by e^(t/20): x₂ = 200 − 10t·e^(−t/20) + Ce^(−t/20). Apply x₂(0) = 0: 0 = 200 + C, so C = −200. Therefore x₂(t) = 200 − 200e^(−t/20) − 10t·e^(−t/20), which can be written as x₂(t) = 200 − (200 + 10t)e^(−t/20). As t → ∞, both e^(−t/20) → 0 and t·e^(−t/20) → 0, so x₂ → 200.
x₂(t) = 200 − (200 + 10t)e^(−t/20)
7
Step 7 — Find the Long-Term (Steady-State) ValuesAs t → ∞, e^(−t/20) → 0 and t·e^(−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)

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.

Strengths vs. Limitations of Compartment Models
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.
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.

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.

From Compartment Models to Advanced Mathematics
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.

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.

Practice Problems

PROBLEM 1CONCEPTUAL
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?
PROBLEM 2BASIC 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.
PROBLEM 3INTERMEDIATE
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.
PROBLEM 4APPLIED
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?
PROBLEM 5CRITICAL 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?

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