Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 39 ยท Systems and Phase Planes

Systems of First-order ODEs

Learn how a system of first-order ODEs describes coupled quantities, how to turn any higher-order equation into a system, and how to solve one with SciPy.

Real problems rarely have a single unknown. Two tanks exchange salt water, a predator eats its prey, a mass hangs on a spring while a second mass hangs below it. Each quantity changes at a rate that depends on the others, so you need several equations solved together. That is a system of ordinary differential equations.

The good news is that you only need one idea to handle them all: write the system as a single equation for a vector. This lesson shows that vector form, explains why every higher-order equation can be turned into a first-order system, and solves a few systems numerically. The later lessons in this chapter study what the solutions look like.

What a system looks like

Coupled rates Each derivative depends on several unknowns.
One vector Stack the unknowns into u(t).
One rule u' = f(t, u) describes everything.

A single equation is just a system with one component.

1 / 2

The general form

A first-order system with two unknowns x(t) and y(t) looks like this:

TEXT
x' = f(t, x, y)
y' = g(t, x, y)

Stack the unknowns into a vector u = (x, y) and the right-hand sides into F(t, u) = (f, g). The whole system is now u' = F(t, u). An initial value problem adds a starting vector u(t0) = u0. Under mild smoothness conditions, exactly one solution passes through each starting point, the same existence and uniqueness story you met for single equations.

If F does not contain t explicitly, the system is autonomous. If every component of F is linear in the unknowns, it is linear, and you can write it as u' = A(t) u + b(t). Linear systems with a constant matrix A are the main subject of the next lesson.

Turning one high-order equation into a system

Take a second-order equation such as a damped spring:

TEXT
y'' + 0.5 y' + 4 y = 0

Introduce a new variable for the velocity: v = y'. Then y' = v and, from the equation, v' = -4y - 0.5v. Two first-order equations, two unknowns. The recipe works for any order n: let the unknowns be y, y', ..., y^(n-1); the first n-1 equations just say each is the derivative of the previous one, and the last is the original equation solved for the highest derivative.

This is why solvers only need to support the form u' = F(t, u). You never have to implement a separate method for second-order equations.

Python A damped spring as a first-order system

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The position y swings back and forth with shrinking amplitude, while the velocity v is the slope of the position curve.

A genuinely coupled example: two tanks

Tank A holds 100 liters and tank B holds 50 liters. Brine is pumped from A to B and from B back to A at 5 liters per minute, and tank B also drains through a small leak (replaced by fresh water). Let a(t) and b(t) be the kilograms of salt. Salt leaves A at 5 * a/100 = 0.05a and arrives from B at 5 * b/50 = 0.1b. Salt leaves B toward A at 0.1b, arrives from A at 0.05a, and drains away through the leak at 0.05b. Together:

TEXT
a' = -0.05 a + 0.10 b
b' =  0.05 a - 0.15 b

The matrix form is u' = A u with A = [[-0.05, 0.10], [0.05, -0.15]]. Every entry is a rate constant: the diagonal is "salt leaving this tank" and the off-diagonal is "salt arriving from the other tank".

Python Salt in two connected tanks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the total decays because of the leak. Without the leak term -0.05 b the total would stay constant, a conservation law that is a great sanity check for a model.

Direction fields become vector fields

For one equation, a direction field draws a slope at each (t, y). For an autonomous system in two unknowns, F(x, y) is a vector at each point of the phase plane, and solutions are curves that are tangent to these vectors everywhere. Time is no longer an axis; it is the speed at which you travel along the curve. Phase portraits build on this picture.

Common mistakes

  • Forgetting an initial condition. An n-component system needs n starting values. A second-order equation needs both y(0) and y'(0).
  • Mixing up the order of unknowns. If you pack u = [y, v], return [v, ...] in that same order.
  • Returning a scalar from the function. F must return one entry per unknown.
  • Checking only one component. A bug in one equation can hide while another looks fine, so compare all of them with a known solution or a conservation law.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How many first-order equations does the third-order equation y''' + y = 0 become?

    A third-order equation needs three unknowns: y, y' and y''. That gives three first-order equations.
  2. 2. A system is called autonomous when:

    Autonomous means u' = F(u) with no explicit time dependence. Linearity and the number of unknowns are separate properties.
  3. 3. For y'' = -9y with u = [y, v], v = y', which function returns the right-hand side?

    The first entry is y' = v and the second is v' = y'' = -9y. The order must match u = [y, v].
  4. 4. How many initial values does a system of 3 first-order equations need?

    One starting value per unknown, so three.

Summary

  • A system couples several unknowns; write it as u' = F(t, u) with a vector u.
  • Any n-th order equation becomes a first-order system by adding y', ..., y^(n-1) as unknowns.
  • Linear systems have the form u' = A u + b; autonomous ones have no explicit t.
  • Solve them numerically with solve_ivp and sanity-check with conserved quantities.
  • Solutions are curves in the phase plane, studied in the next lessons.

Next: Linear Systems and Eigenvalues