Interactive Two-Tank System

See how coupled differential equations emerge from interconnected physical systems

The Physical System

Two tanks are connected by pipes. Liquid flows into Tank 1 from an external source, from Tank 1 to Tank 2 through a connecting pipe, and out of Tank 2 through a drain. The flow rates depend on the liquid levels, creating a coupled system of differential equations.

Governing Equations

Let $h_1(t)$ and $h_2(t)$ be the liquid levels (in meters) in Tank 1 and Tank 2 respectively:

$$A_1 \frac{dh_1}{dt} = Q_{\text{in}} - k_1\,h_1$$
$$A_2 \frac{dh_2}{dt} = k_1\,h_1 - k_2\,h_2$$

where:

  • $A_1, A_2$ = cross-sectional areas of the tanks (m²)
  • $k_1$ = valve coefficient from Tank 1 → Tank 2 (m²/s)
  • $k_2$ = valve coefficient from Tank 2 → drain (m²/s)
  • $Q_{\text{in}}$ = external inflow rate into Tank 1 (m³/s)

The key insight: The term $k_1 h_1$ appears in both equations — it is the outflow of Tank 1 and the inflow of Tank 2. This shared term is what couples the two equations. You cannot solve for $h_2(t)$ without knowing $h_1(t)$ first, because Tank 2's inflow depends on Tank 1's level.

Matrix Form — A System of First-Order ODEs

Dividing both equations by their respective areas and writing in matrix form:

$$\frac{d}{dt}\begin{pmatrix} h_1 \\ h_2 \end{pmatrix} = \underbrace{\begin{pmatrix} -k_1/A_1 & 0 \\ k_1/A_2 & -k_2/A_2 \end{pmatrix}}_{\mathbf{A}} \begin{pmatrix} h_1 \\ h_2 \end{pmatrix} + \begin{pmatrix} Q_{\text{in}}/A_1 \\ 0 \end{pmatrix}$$

This is exactly the form $\mathbf{x}' = \mathbf{A}\mathbf{x} + \mathbf{b}$ studied in Chapter 4. The eigenvalues of $\mathbf{A}$ determine the system's behavior.

Eigenvalue Analysis

Since $\mathbf{A}$ is lower-triangular, the eigenvalues are the diagonal entries:

$$\lambda_1 = -\frac{k_1}{A_1}, \qquad \lambda_2 = -\frac{k_2}{A_2}$$

Both eigenvalues are always negative (since $k_1, k_2, A_1, A_2 > 0$), so the system is always stable — both tank levels eventually reach steady state.

Steady-State Solution

Setting $dh_1/dt = 0$ and $dh_2/dt = 0$:

$$h_1^* = \frac{Q_{\text{in}}}{k_1}, \qquad h_2^* = \frac{Q_{\text{in}}}{k_2}$$

Notice: the steady-state levels depend only on the inflow rate and the respective valve coefficients — not on the tank areas (areas only affect how fast steady state is reached).

Live Two-Tank Animation

Watch both tanks fill and drain in real time. Adjust parameters, then press Play to see the coupled dynamics unfold — notice how Tank 2 responds to Tank 1's level.

2.0
2.0
0.50
0.50
1.00
0.0 m
0.0 m
1.0x
λ₁ = -0.25   λ₂ = -0.25
Physical System
t = 0.00 s
Tank Levels vs Time
Inflow → Tank 1
1.00
m³/s
Tank 1 → Tank 2
0.00
m³/s = k₁·h₁
Tank 2 → Drain
0.00
m³/s = k₂·h₂
Tank 1 Level
Steady state: h₁* = 2.00 m
0.00 m
Tank 2 Level
Steady state: h₂* = 2.00 m
0.00 m

Understanding the Coupling

The beauty of this system is that the two tanks are not independent. Let's trace the chain of cause and effect:

1
External inflow $Q_{\text{in}}$ enters Tank 1 — this drives the entire system. If $Q_{\text{in}}$ changes, both tank levels eventually change.
2
Tank 1's level $h_1$ rises, increasing the outflow $k_1 h_1$ through the connecting valve. The higher the level, the greater the pressure driving fluid out.
3
This outflow becomes Tank 2's inflow — the coupling term $k_1 h_1$ appears in Tank 2's equation. Tank 2 cannot "know" its future without knowing Tank 1's state.
4
Tank 2 drains at rate $k_2 h_2$. Eventually, both tanks reach steady state when inflow = outflow for each tank simultaneously.
Why You Need Systems of DEs

If you tried to solve Tank 2's equation $A_2 h_2' = k_1 h_1 - k_2 h_2$ by itself, you'd be stuck: the right side contains $h_1(t)$, which is unknown. You must solve the system simultaneously — this is exactly the problem Chapter 4 addresses using matrix methods, eigenvalues, and eigenvectors.

One-Way vs Two-Way Coupling

This two-tank system has one-way (cascade) coupling: Tank 1 affects Tank 2, but Tank 2 does not affect Tank 1. Mathematically, the matrix $\mathbf{A}$ is lower-triangular, meaning Tank 1's equation is independent. In more complex systems (e.g., tanks connected by bidirectional pipes), you get two-way coupling where every equation depends on every variable.

Worked Examples

Example 1: Fill from empty — $A_1 = A_2 = 2$, $k_1 = k_2 = 0.5$, $Q_{\text{in}} = 1$

Setting up the system

$$\frac{dh_1}{dt} = \frac{1 - 0.5\,h_1}{2} = 0.5 - 0.25\,h_1$$
$$\frac{dh_2}{dt} = \frac{0.5\,h_1 - 0.5\,h_2}{2} = 0.25\,h_1 - 0.25\,h_2$$

Solving Tank 1 (independent equation)

Tank 1's equation is a first-order linear ODE with constant coefficients:

$$h_1' + 0.25\,h_1 = 0.5$$

With $h_1(0) = 0$, the solution is:

$$h_1(t) = 2(1 - e^{-0.25t})$$

Solving Tank 2 (uses $h_1$)

Substituting $h_1(t)$ into Tank 2's equation:

$$h_2' + 0.25\,h_2 = 0.25 \cdot 2(1 - e^{-0.25t}) = 0.5 - 0.5\,e^{-0.25t}$$

This has a repeated eigenvalue $\lambda = -0.25$. Using integrating factors or the matrix exponential with $h_2(0) = 0$:

$$h_2(t) = 2 - 2e^{-0.25t} - 0.5\,t\,e^{-0.25t}$$

Steady state

As $t \to \infty$: $h_1^* = Q_{\text{in}}/k_1 = 1/0.5 = 2$ m and $h_2^* = Q_{\text{in}}/k_2 = 1/0.5 = 2$ m.

Key observation: Tank 1 reaches steady state before Tank 2 — try it in the simulator above!

Example 2: Drain from full — $Q_{\text{in}} = 0$, $h_1(0) = 4$, $h_2(0) = 3$

The homogeneous system

With $Q_{\text{in}} = 0$, the system becomes $\mathbf{x}' = \mathbf{A}\mathbf{x}$ (no forcing term):

$$\frac{d}{dt}\begin{pmatrix} h_1 \\ h_2 \end{pmatrix} = \begin{pmatrix} -0.25 & 0 \\ 0.25 & -0.25 \end{pmatrix} \begin{pmatrix} h_1 \\ h_2 \end{pmatrix}$$

Eigenvalues and eigenvectors

Repeated eigenvalue $\lambda = -0.25$. Eigenvector for $\lambda$: $\mathbf{v}_1 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}$. Generalized eigenvector: $\mathbf{v}_2 = \begin{pmatrix} 4 \\ 0 \end{pmatrix}$.

General solution

$$\begin{pmatrix} h_1 \\ h_2 \end{pmatrix} = c_1 e^{-0.25t}\begin{pmatrix} 0 \\ 1 \end{pmatrix} + c_2 e^{-0.25t}\left[\begin{pmatrix} 4 \\ 0 \end{pmatrix} + t\begin{pmatrix} 0 \\ 1 \end{pmatrix}\right]$$

Applying $h_1(0) = 4, h_2(0) = 3$: $c_2 = 1$ and $c_1 = 3$.

$$h_1(t) = 4e^{-0.25t}, \qquad h_2(t) = (3 + t)e^{-0.25t}$$

Fascinating behavior: Tank 2's level initially rises (because fluid pours in from Tank 1) before eventually draining. The term $t \cdot e^{-0.25t}$ creates a transient "bump." Try this scenario in the simulator!

Example 3: Different valve sizes — $k_1 = 1$, $k_2 = 0.25$

Setup

With $A_1 = A_2 = 2$, $Q_{\text{in}} = 1$, filling from empty:

$$\mathbf{A} = \begin{pmatrix} -0.5 & 0 \\ 0.5 & -0.125 \end{pmatrix}, \qquad \lambda_1 = -0.5, \quad \lambda_2 = -0.125$$

Distinct eigenvalues — different timescales!

The eigenvalue ratio $|\lambda_1/\lambda_2| = 4$ tells us Tank 1 responds 4 times faster than Tank 2. This separation of timescales is common in coupled systems.

Steady state

$$h_1^* = \frac{Q_{\text{in}}}{k_1} = \frac{1}{1} = 1 \text{ m}, \qquad h_2^* = \frac{Q_{\text{in}}}{k_2} = \frac{1}{0.25} = 4 \text{ m}$$

The smaller drain valve ($k_2 = 0.25$) causes Tank 2 to fill much higher! This demonstrates how valve sizing directly determines the operating levels.

📝 Exam-Style Practice Problems

Click each problem to reveal the step-by-step solution.

Practice 1: Find eigenvalues for $A_1=1, A_2=3, k_1=2, k_2=1$

Solution

Step 1: Form the system matrix:

$$\mathbf{A} = \begin{pmatrix} -k_1/A_1 & 0 \\ k_1/A_2 & -k_2/A_2 \end{pmatrix} = \begin{pmatrix} -2 & 0 \\ 2/3 & -1/3 \end{pmatrix}$$

Step 2: Since $\mathbf{A}$ is lower-triangular, the eigenvalues are the diagonal entries:

$$\boxed{\lambda_1 = -2, \qquad \lambda_2 = -\frac{1}{3}}$$

Step 3: Interpret: Both negative → stable. Tank 1 responds 6× faster than Tank 2 ($|\lambda_1/\lambda_2| = 6$).

Practice 2: Solve the drain problem $h_1(0)=3, h_2(0)=0, Q_{\text{in}}=0$ with $A_1=A_2=1, k_1=k_2=1$

Solution

Step 1: The system matrix and repeated eigenvalue:

$$\mathbf{A} = \begin{pmatrix} -1 & 0 \\ 1 & -1 \end{pmatrix}, \qquad \lambda = -1 \text{ (repeated)}$$

Step 2: Tank 1 is independent: $h_1' = -h_1$, so $h_1(t) = 3e^{-t}$.

Step 3: Tank 2: $h_2' = h_1 - h_2 = 3e^{-t} - h_2$. This is a first-order linear ODE.

Step 4: Using an integrating factor $e^t$:

$$(e^t h_2)' = 3e^{-t} \cdot e^t = 3$$
$$e^t h_2 = 3t + C$$

With $h_2(0)=0$: $C=0$. Therefore:

$$\boxed{h_1(t) = 3e^{-t}, \qquad h_2(t) = 3t\,e^{-t}}$$

Step 5: Tank 2 peaks at $t=1$ where $h_2(1) = 3/e \approx 1.10$ m, then decays.

Connection to Chapter 4

How It All Fits Together

Section 4.1 (Matrices): The system matrix $\mathbf{A}$ encodes all the physics — tank areas, valve coefficients, and connectivity. Reading the matrix tells you the system's structure.

Section 4.2 (Homogeneous Systems): The drain scenario ($Q_{\text{in}}=0$) gives $\mathbf{x}' = \mathbf{A}\mathbf{x}$. Eigenvalues determine decay rates; eigenvectors determine the independent modes. Repeated eigenvalues (equal valve ratios) produce the $te^{\lambda t}$ terms.

This simulator: Lets you see the abstract mathematics come to life. The eigenvalues control how fast the levels change. The coupling term connects one equation to the other. The steady state is found by setting derivatives to zero.