differential equations25 min

Systems of ODEs

Coupled systems of first-order ODEs, phase portraits, and simulating multi-variable dynamics

0/9Not Started

Why This Matters

Real-world systems rarely involve just one changing quantity. A predator-prey ecosystem tracks both rabbit and fox populations simultaneously. A chemical reaction involves concentrations of multiple substances. A robot arm has position and velocity for each joint. These are all systems of ODEs -- multiple differential equations that are coupled together, meaning each equation can involve all the unknown functions.

The phase portrait is a powerful visualization tool for systems: instead of plotting each variable against time, you plot them against each other. A 2D system of dx/dt and dy/dt becomes a vector field in the xy-plane. Trajectories in this plane reveal stability, oscillation, and the long-term behavior of the system at a glance. This is the bridge between differential equations and linear algebra, because the behavior of linear systems is completely determined by the eigenvalues of the coefficient matrix.

Define Terms

Visual Model

System of ODEsdx/dt = f(x,y), dy/dt = g(x,y)
2D Euler MethodStep both variables
Matrix FormdX/dt = AX
EigenvaluesDetermine behavior
Trajectories(x(t), y(t)) paths
Phase PortraitVector field + trajectories
Stable NodeBoth eigenvalues negative
Unstable / SaddlePositive eigenvalue
Spiral / CenterComplex eigenvalues

The full process at a glance. Click Start tour to walk through each step.

Systems of ODEs couple multiple variables. Eigenvalues of the coefficient matrix determine whether solutions converge, diverge, or oscillate.

Code Example

Code
// System of ODEs: dx/dt = -x + 0.5y, dy/dt = 0.5x - y
// This models two quantities that decay but are coupled

function eulerSystem(fSystem, x0, y0, tEnd, steps) {
  const h = tEnd / steps;
  let x = x0, y = y0, t = 0;
  const trajectory = [{ t: 0, x, y }];

  for (let i = 0; i < steps; i++) {
    const [dxdt, dydt] = fSystem(x, y);
    // Update BOTH variables using OLD values
    const xNew = x + h * dxdt;
    const yNew = y + h * dydt;
    x = xNew;
    y = yNew;
    t += h;
    if (i % (steps / 10) === 0 || i === steps - 1) {
      trajectory.push({
        t: Math.round(t * 100) / 100,
        x: Math.round(x * 1000) / 1000,
        y: Math.round(y * 1000) / 1000
      });
    }
  }
  return trajectory;
}

// Coupled decay system
const system = (x, y) => [-x + 0.5 * y, 0.5 * x - y];

console.log("Coupled decay from (2, 1):");
const traj1 = eulerSystem(system, 2, 1, 5, 1000);
traj1.forEach(p => console.log(`  t=${p.t}: x=${p.x}, y=${p.y}`));

// Predator-prey (Lotka-Volterra)
// dx/dt = 0.4x - 0.01xy (prey grows, eaten by predators)
// dy/dt = -0.3y + 0.005xy (predators die, fed by prey)
const predPrey = (x, y) => [0.4*x - 0.01*x*y, -0.3*y + 0.005*x*y];

console.log("\nPredator-prey from (80 prey, 30 predators):");
const traj2 = eulerSystem(predPrey, 80, 30, 30, 3000);
traj2.forEach(p => console.log(`  t=${p.t}: prey=${p.x}, pred=${p.y}`));

Interactive Experiment

Try these exercises:

  • Run the coupled decay system from different starting points: (2, 1), (0, 3), (-1, 2). Do all trajectories approach the same final state?
  • Change the coupling strength in dx/dt = -x + ky: try k = 0 (uncoupled), k = 0.5, and k = 1.5. How does coupling affect the decay?
  • For the predator-prey system, try starting with (100, 10) and (50, 50). Do the populations oscillate? Do they ever reach a steady state?
  • Convert the second-order ODE y'' + y = 0 into a system: let u = y and v = y'. What is du/dt and dv/dt? Simulate it.
  • What happens to the predator-prey system if you double the prey growth rate?

Quick Quiz

Coding Challenge

2D System Simulator

Write a function called `simulate2D` that takes a system function f(x, y) returning [dxdt, dydt], initial conditions x0 and y0, a final time tEnd, and number of steps n. Return an array of objects with t, x, and y values at each step. Use the 2D Euler method: compute both derivatives with old values, then update both variables. Round x and y to 3 decimal places.

Loading editor...

Real-World Usage

Systems of ODEs model multi-variable dynamics across all fields:

  • Ecology: The Lotka-Volterra predator-prey model tracks interacting populations. Extensions model entire food webs with dozens of coupled species.
  • Epidemiology: The SIR model (Susceptible, Infected, Recovered) is a 3D system of ODEs used to predict disease spread. COVID-19 models are extensions of this framework.
  • Robotics: A robot joint has both position and velocity, forming a 2D system. A full robot arm with n joints has a 2n-dimensional system.
  • Economics: Coupled differential equations model interacting markets, where the price of one commodity affects demand for another.
  • Climate science: Atmospheric models couple temperature, pressure, humidity, and wind velocity across thousands of grid points, each governed by coupled ODEs.

Connections