AI Wiki中文/EN

Differential equations and dynamics

微分方程与动力系统

Separate continuous dynamics, discretization error and numerical stability.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A decay model can grow on your computer

A state loses a fixed fraction of its current amount per unit time. The continuous model decays smoothly. A careless time step can make its numerical approximation alternate signs or grow without bound. The simulated behavior may belong to the method rather than the modeled system.

Differential equations specify how a state changes, while an initial condition selects a trajectory. Solving one means finding a function over time, not just a number that makes an algebraic expression zero. In AI, such models appear in control, continuous-time state models and differential-equation-based generative methods.

This chapter studies an ordinary differential equation (ODE). A partial differential equation also involves derivatives with respect to multiple independent variables, such as space and time. Begin with derivatives and finite differences.

Specify both the dynamics and the initial state

An initial-value problem has the form y′(t)=f(t,y(t)), with y(t₀)=y₀. Existence and uniqueness require suitable assumptions; a written initial condition alone does not prove that a unique solution exists. OpenStax §4.1 introduces solutions and initial-value problems.

For a positive decay rate k, the exactly solvable case is:

y′(t)=−ky(t),y(0)=y0,y(t)=y0e−kt.y'(t)=-ky(t),\qquad y(0)=y_0,\qquad y(t)=y_0e^{-kt}.

Differentiation verifies the equation, and substituting zero verifies the initial value. If time is measured in seconds, k has units of inverse seconds, so kh is dimensionless. For positive y₀, the exact trajectory remains positive and tends to zero.

Explicit Euler follows the current slope

On a grid with step h>0, explicit Euler predicts the next state using the current slope. Backward, or implicit, Euler evaluates the slope at the next time and unknown next state:

yn+1exp=yn+hf(tn,yn),yn+1imp=yn+hf(tn+1,yn+1).y_{n+1}^{\mathrm{exp}}=y_n+h f(t_n,y_n),\qquad y_{n+1}^{\mathrm{imp}}=y_n+h f(t_{n+1},y_{n+1}).

The OpenStax numerical-methods section develops the explicit slope-stepping idea. Implicit Euler generally requires solving an equation at each step; our linear example lets us rearrange that equation directly.

For the decay equation, the two update factors are:

yn+1exp=(1−kh)yn,yn+1imp=yn1+kh.y_{n+1}^{\mathrm{exp}}=(1-kh)y_n,\qquad y_{n+1}^{\mathrm{imp}}=\frac{y_n}{1+kh}.

Explicit Euler decays in magnitude only when |1−kh| is less than one, meaning 0<kh<2. For 1<kh<2 it alternates signs while shrinking, so stability does not guarantee positivity. At kh=2 it oscillates without decaying; above two its magnitude grows. Implicit Euler’s factor lies between zero and one for every positive k and h. This proves stability for this decay test, not accuracy for arbitrarily large steps or stability for every differential equation.

Error and stability answer different questions

Euler’s one-step local error is O(h²) for a sufficiently smooth solution; under the usual regularity assumptions its global error over a fixed finite time interval is O(h). “Global” here means accumulated over the interval, not a statement about every possible model. Halving h at a fixed endpoint uses twice as many steps. Comparing different methods after the same number of steps but different h compares different times.

For stiff systems, fast decaying modes can force explicit methods to take tiny stable steps even when the behavior of interest changes slowly. Implicit methods can ease a stability restriction, but resolving important transients still requires adequate accuracy.

Inspect a known solution before trusting a solver

Run the complete Python 3.12 standard-library program. Its helper uses exact fractions for both methods and accepts a nonnegative rational rate, positive rational h, rational initial value and 0–128 steps. The printed exponential reference is a separate floating-point evaluation. This is a solver for the stated linear decay model, not a general ODE package.

from fractions import Fraction as F
import math


def decay(rate,h,steps,method='explicit',initial=1):
    if any(type(v) not in (int,F) for v in (rate,h,initial)):
        raise ValueError('rational rate, step and initial value required')
    if rate < 0 or h <= 0 or type(steps) is not int or not 0 <= steps <= 128:
        raise ValueError('nonnegative rate, positive step, 0 to 128 steps required')
    if method not in ('explicit','implicit'):
        raise ValueError('unknown method')
    rate,h,y=F(rate),F(h),F(initial)
    factor=1-rate*h if method=='explicit' else 1/(1+rate*h)
    values=[y]
    for _ in range(steps):
        y*=factor;values.append(y)
    return values


if __name__ == '__main__':
    for h in [F(1,4),F(3,4),F(1),F(5,4)]:
        explicit=decay(2,h,4)
        print('h='+str(h),'explicit='+str([str(v) for v in explicit]))
    for n in [4,8,16]:
        a=decay(2,F(1,n),n)[-1]
        b=decay(2,F(1,n),n,'implicit')[-1]
        print('T=1, n='+str(n),'explicit='+format(float(a),'.6f'),
              'implicit='+format(float(b),'.6f'))
    print('exact at T=1:',format(math.exp(-2),'.6f'))

Output:

h=1/4 explicit=['1', '1/2', '1/4', '1/8', '1/16']
h=3/4 explicit=['1', '-1/2', '1/4', '-1/8', '1/16']
h=1 explicit=['1', '-1', '1', '-1', '1']
h=5/4 explicit=['1', '-3/2', '9/4', '-27/8', '81/16']
T=1, n=4 explicit=0.062500 implicit=0.197531
T=1, n=8 explicit=0.100113 implicit=0.167772
T=1, n=16 explicit=0.118067 implicit=0.151901
exact at T=1: 0.135335

With k=2, steps 1/4 and 3/4 produce factors 1/2 and −1/2. Step 1 reaches the nondecaying boundary −1; step 5/4 produces unstable factor −3/2. The second table compares all approximations at T=1 and shows both methods approaching exp(−2) as the grid is refined.

Each step uses a constant number of rational operations and storing m steps takes O(m) values. Fraction bit cost grows with the trajectory. General implicit methods also pay for nonlinear or linear solves; comparing only the step count can hide their cost.

Separate the equation, the method and the implementation

A physically wrong equation can be solved accurately. A suitable equation can be approximated badly. A sound algorithm can be implemented with incorrect units or an off-by-one endpoint. These are different failure modes. Check conserved or monotone quantities when the model actually has them, and compare with exact solutions on small test cases.

Adaptive solvers estimate local error to choose steps, but discontinuities, events and stiffness require appropriate handling. Error tolerances are not automatically bounds on every quantity a downstream model will use. Neural ODE training also involves differentiating through or around a numerical solve; that adds questions beyond forward accuracy.

The implicit formula here is derived from a scalar linear equation. Reusing its denominator for a nonlinear or coupled system would change the method. Higher-order Runge–Kutta and multistep methods have different stability regions and assumptions.

Keep time and step count aligned

  1. With k=2 and h=3/4, is explicit Euler stable in magnitude? Does it preserve positive values?

Answer 1: Its factor is −1/2, so magnitudes decay but signs alternate. It does not preserve positivity.

  1. Why does h=1 fail to reproduce asymptotic decay for the same rate?

Answer 2: The factor is −1, exactly on the stability boundary. The numerical magnitude stays constant while the exact solution decays.

  1. To compare h=1/4 and h=1/8 at T=1, how many steps does each need?

Answer 3: Four and eight. Equal step counts would end at different times.

  1. Does implicit Euler’s stable decay factor make a huge step accurate?

Answer 4: No. Stability controls growth of the numerical recurrence; approximation error can still be large. The factor 1/(1+kh) can differ greatly from exp(−kh).

Start numerical dynamics with a solvable test equation

The OpenStax sections provide the ODE and explicit-Euler foundations. The implicit factor and stability boundaries here follow by direct algebra, with exact trajectories as implementation checks.

A useful extension is a two-component system with decay rates 1 and 1000. Compare the step needed to keep the fast mode stable with the step needed to describe the slow mode accurately. Then examine an adaptive solver with those two questions kept separate.

Make a prediction, then check

Does numerical stability alone guarantee an accurate trajectory?

Choose one answer

Learning objectives

  • Verify a decay solution and derive two Euler recurrences.
  • Distinguish stability, positivity and fixed-time accuracy.

Prerequisites & connections

Explore related knowledge →

References

  1. Calculus Volume 2 — 4.1 Basics of Differential Equations
    Gilbert Strang; Edwin Herman; OpenStax · 2016
  2. Calculus Volume 2 — 4.2 Direction Fields and Numerical Methods
    Gilbert Strang; Edwin Herman; OpenStax · 2016

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: primary-source locations, explicit assumptions, derivations, exact/literal and numerical checks, and bilingual review; not independent human or second-agent peer review.

  • Single-agent authored technical review: primary-source locations, explicit domains and assumptions, derivations, literal/exact probability or numerical reference cases, bilingual examples and exercises. Not independent human or second-agent review.
  • Four focused tests passed on CPython3.12.4; NumPy1.26.4 actually executed for the Fourier chapter. Exact rational probability/stencil checks are distinguished from floating-point calculations and observed Monte Carlo output. Both languages render three equations, six anchors and four answers; final repository checks recorded separately.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.