Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 47 ยท Ordinary Differential Equations

Ordinary Differential Equations: Overview

Preview chapter 3: how physics becomes ordinary differential equations, how to turn second-order equations into first-order systems, and how the methods in this chapter fit.

Newton's second law, F = m a, is an ordinary differential equation (ODE): it relates a quantity (position) to its own rate of change (velocity, acceleration). So do the equations for a circuit with a capacitor, radioactive decay, a pendulum, a planet orbiting a star, and a chemical reaction. If you can write down the forces, you can write down an ODE; if you can solve ODEs numerically, you can predict the motion even when no formula exists.

A direction field of short slope marks for dy/dt = cos t minus 0.4 y with one solution curve following the arrows
An ODE gives a slope at every point. A solution is a curve that follows the arrows from its starting point.

What you will learn

  • What an initial value problem is and why it can be solved step by step.
  • How to reduce any higher-order ODE to a first-order system.
  • Where each lesson in this chapter fits.
  • How to solve an ODE with scipy.integrate.solve_ivp as a reference.

Key terms

ODE: an equation with a function of one variable (usually time) and its derivatives.

Initial value problem (IVP): an ODE together with the state at a starting time.

State vector: the list of quantities that fully describe the system at one instant, such as (x, v).

Time step h or dt: the size of each jump forward in time.

Phase space: the space of all possible state vectors.

Why step by step?

Know the start Initial position, velocity
Know the rule Slope at each state
Take a small step Repeat until done
1 / 3

Initial value problems

A first-order IVP has the form

dy/dt = f(t, y), y(tโ‚€) = yโ‚€

The function f gives the slope of the solution at any point. If you know where you are and which way you are heading, a short step forward gets you to a nearby point; repeating the process traces out the curve. The figure above shows such arrows for dy/dt = cos t โˆ’ 0.4 y. Every numerical method in this chapter is a different way of choosing that short step.

Turning second-order equations into first-order systems

Newton's law for a mass on a spring is second order: m dยฒx/dtยฒ = โˆ’k x. The methods in this chapter handle only first-order systems, so introduce the velocity v = dx/dt as a new unknown:

dx/dt = v dv/dt = โˆ’(k/m) x

Now the state is the vector (x, v). Any ODE of order n becomes n first-order equations in the same way. This is a routine trick you will use in every lesson of this chapter.

Python A mass on a spring with solve_ivp

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.

Phase space

Instead of plotting x and v against time, plot them against each other. For the spring the points lie on an ellipse because the energy E = (m vยฒ + k xยฒ)/2 is constant. Closed curves in phase space mean periodic motion; a curve that spirals outward means energy is being created, which for a frictionless spring is a numerical error. Phase portraits are the best way to spot sick simulations.

Python The phase portrait of the spring

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.

What each lesson covers

Common misconceptions

"An ODE solver gives the exact solution." It gives a sequence of approximate values. Accuracy depends on the method, the step and the problem.

"A second-order equation needs a second-order method." The order of the ODE and the order of the method are unrelated. You first rewrite the equation as a first-order system, then choose any method.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What do you need to start solving dy/dt = f(t, y)?

    An initial value problem is the ODE together with the state at the starting time.
  2. 2. How is m x'' = -k x written as a first-order system?

    Introduce v = x' as a new unknown; the second-order equation becomes two first-order ones.
  3. 3. In phase space, a frictionless oscillator traces

    Energy is conserved, so the state stays on one contour of energy.
  4. 4. A simulated frictionless oscillator spirals outward in phase space. What does this suggest?

    Real frictionless oscillators do not gain energy; the drift is a numerical artifact.

Summary

  • An ODE gives the slope at every state; an IVP adds the starting state.
  • Higher-order equations become first-order systems by adding velocities as unknowns.
  • Phase portraits reveal energy behavior at a glance.
  • solve_ivp is a trustworthy reference to test your own solvers against.

Next: Euler's Method