Module contents
Lesson 3 of 27Core 100 min

Nonlinear dynamical systems: chaos and predictability

Quantify the loss of trajectory predictability in chaotic systems with Lyapunov exponents, and examine strange attractors, Poincaré sections, shadowing and ensemble prediction.

After this lesson you can

  • Simulate Lorenz-63 and Lorenz-96 and characterize their attractors.
  • Calculate the Lyapunov spectrum using Benettin's algorithm and QR reorthogonalization.
  • Estimate the predictability horizon from the largest exponent and initial error.
  • Construct Poincaré sections and return maps to reduce a flow to a discrete map.
  • Explain shadowing and the conditions under which statistics of chaotic simulations are useful.

Before you start

The limit of a trajectory

A weather simulation starts from imperfect observations. Even if the model and integrator were exact, two nearby initial states can separate until they are indistinguishable from two typical states of the system. At that point, interpreting a trajectory as a point prediction is no longer useful. This does not imply that every statistical property is unpredictable: the state distribution and aggregate risks can remain informative after the phase of an individual trajectory is lost.

Linearization describes small perturbations. For x˙=f(x)\dot x=f(x) and a solution x(t)x(t), the tangent vector satisfies v˙=Df(x(t))v\dot v=Df(x(t))v. A finite perturbation follows this equation only while sufficiently small; once comparable to the size of the attractor, separation saturates and a line fitted to the entire interval does not estimate initial growth.

Two distinct limits are involved. Reducing the integration step usually brings the numerical solution closer to the exact one over a finite interval, provided the method converges and its assumptions hold. Reducing initial uncertainty brings the prediction closer to the evolution of the actual state. In a sensitive system either difference can be amplified: comparing two integrators at the end of a long interval does not by itself identify which failed. Compare short times first, then check long-term statistics and structural properties.

Lorenz and sensitivity

The 1963 Lorenz system is a reduced model of convection, not an operational forecast:

x˙=σ(y−x),y˙=x(ρ−z)−y,z˙=xy−βz.\dot x=\sigma(y-x),\qquad \dot y=x(\rho-z)-y,\qquad \dot z=xy-\beta z.

With σ=10\sigma=10, ρ=28\rho=28, β=8/3\beta=8/3 it shows two lobes and sensitivity to initial conditions. A strange attractor is an invariant set that attracts orbits from a region and has nontrivial geometric structure; “strange” and “chaotic” describe related, not identical, properties. The figure integrates two orbits instead of drawing idealized exponential separation.

InteractiveTwo butterflies separating
  • Initial trajectory
  • Perturbed trajectory

Orbits are calculated using RK4 with step 0.01; the scene uses coordinates (x/12, y/12, (z−25)/12). Growth varies locally and eventually saturates; the largest exponent is an asymptotic average, not the slope of every segment.

8
25
Current separation0.003281
RK4 step0.01
Change the initial perturbation and time. The panel uses the base-10 logarithm of the actual distance between the numerical solutions; rotate the 3D view to recognize both lobes.

If δ(t)≈δ0eλ1t\delta(t)\approx\delta_0 e^{\lambda_1 t} while the perturbation is small and λ1>0\lambda_1>0, the predictability horizon for threshold Δ\Delta is approximately T≈log⁡(Δ/δ0)/λ1T\approx\log(\Delta/\delta_0)/\lambda_1. Reducing δ0\delta_0 by a factor of one thousand adds log⁡(1000)/λ1\log(1000)/\lambda_1 rather than multiplying the horizon by one thousand. The finite-time rate fluctuates and the chosen threshold matters. A real atmosphere also has model and observation errors and unresolved variables; no universal number of days follows from this formula.

For example, with λ1=0.9\lambda_1=0.9, Δ=1\Delta=1 and δ0=10−6\delta_0=10^{-6}, the formula gives approximately 15.3515.35 time units. If initial error is 10−910^{-9}, it gives approximately 23.0323.03. Both figures are exponential-model calculations, not measurements from the figure. On the separation curve, first find a region where distance remains small and compare several initial conditions: local oscillations can be as important as the mean trend in a single segment.

Exponents and reorthogonalization

Lyapunov exponents describe asymptotic exponential rates along different tangent directions. Under the integrability and invariance assumptions of Oseledets’ multiplicative ergodic theorem, they exist almost everywhere for the invariant measure considered. The largest measures typical growth of infinitesimal perturbations, not an instantaneous value or a guarantee that every finite perturbation grows monotonically.

To obtain the spectrum, Benettin’s algorithm integrates the state and a matrix of tangent vectors QQ with Q˙=Df(x)Q\dot Q=Df(x)Q. Periodically it factors Q=Q~RQ=\widetilde Q R, adds log⁡∣Rii∣\log|R_{ii}| and restarts the vectors with Q~\widetilde Q. Dividing the sums by time gives finite-time estimates. Without QR, all generic vectors align with the dominant direction and the rest of the spectrum is lost. State and tangent evolution must use the same integrator stages.

InteractiveBenettin's algorithm step by step
  • Exponent 1
  • Exponent 2
  • Exponent 3

The scene centers z at 25 and divides positions by 12. Arrows and edges share a visual scale. The sum is compared with constant divergence; individual components take time to stabilize.

100
Phase
Accumulated time10.0
Finite exponents0.740, −0.016, −14.390
Sum−13.6666
Exact divergence−13.6667
Observe tangent vectors before and after each QR. Curves show accumulated rates from an actual integration; their sum is compared with Lorenz's constant divergence.

Liouville’s formula for the fundamental matrix Φ\Phi gives  ⁣d ⁣dtlog⁡∣det⁡Φ∣=tr⁡Df(x(t))\frac{\dd}{\dd t}\log|\det\Phi|=\operatorname{tr}Df(x(t)). If the corresponding limits exist, the time average of divergence is the sum of exponents. For Lorenz-63 it is −σ−1−β=−41/3-\sigma-1-\beta=-41/3. In an autonomous flow, the field’s own direction is tangent to a time shift; along a bounded regular nonstationary orbit, under the usual assumptions, it gives a zero exponent. An equilibrium does not automatically satisfy that statement.

Checking the sum detects sign, stage or accumulation errors; it does not identify which individual exponent is wrong. The factorization also has a sign convention: RiiR_{ii} can be negative depending on implementation, so its absolute value is accumulated. The interval between QR steps should avoid both collapse from poor conditioning and unnecessary cost from excessive frequency. Try several intervals and durations, and first test a linear system with known exponents.

Period doubling and return

The logistic map xn+1=rxn(1−xn)x_{n+1}=rx_n(1-x_n) provides a discrete laboratory. As rr varies, fixed points, cycles and chaotic regions appear, interrupted by periodic windows. Its finite-time exponent is the average of log⁡∣r(1−2xn)∣\log|r(1-2x_n)|. A positive value indicates average expansion for the observed orbit; transient and duration matter.

For a nonzero fixed point, x∗=1−1/rx^*=1-1/r and the map derivative is 2−r2-r. Local stability requires ∣2−r∣<1|2-r|<1, that is, 1<r<31<r<3. Crossing r=3r=3 loses this stability and produces a period-two cycle; further doublings appear later. For a periodic orbit of period pp, the exponent is p−1log⁡∣(fp)′(x)∣p^{-1}\log|(f^p)'(x)|: it is negative if the derivative product has magnitude less than one. Near a bifurcation, an exponent near zero can make a fixed transient insufficient.

InteractiveLogistic map bifurcation and exponent

Each column discards 700 iterations and shows 60 of the next 180. Convergence is slow near bifurcations; zoom and exponents have finite resolution.

3.500000
0
3.8300
Visible interval2.600000 to 4.000000
Selected finite exponent−0.3729
Pan and zoom the interval. The figure shows calculated iterates and the finite exponent; periodic windows have negative exponents in their interior.

Ratios of distances between successive bifurcations approach the Feigenbaum constant for the appropriate family and limit. A finite-resolution image is insufficient for an accurate measurement: bifurcations must be located, cycle order verified and numerical error controlled.

In this family, each point can be found by solving frp(x)=xf_r^p(x)=x and (frp)′(x)=−1(f_r^p)'(x)=-1 for periods p=1,2,4,8,16p=1,2,4,8,16. The next cell obtains an initial approximation by iterating slightly before each bifurcation; initial values of rr select the branch, and the residual is checked. Ratios of successive distances are a reproducible numerical measurement, not values read from pixels.

[ ]Measure doubling ratiosBrowser
import numpy as np
from scipy.optimize import root
def cycle(x,r,n):
    product=1.
    for _ in range(n):
        product*=r*(1-2*x)
        x=r*x*(1-x)
    return x,product
def bifurcation(n,guess):
    r=guess-.0001;x=.37
    for _ in range(200000): x=r*x*(1-x)
    result=root(lambda z:[cycle(z[0],z[1],n)[0]-z[0],cycle(z[0],z[1],n)[1]+1],[x,guess],tol=1e-12)
    if np.linalg.norm(result.fun)>1e-8 or abs(result.x[1]-guess)>1e-4: raise RuntimeError('no se localizó la rama')
    return result.x[1]
values=np.array([bifurcation(n,g) for n,g in [(1,3.),(2,3.449489743),(4,3.544090359),(8,3.564407266),(16,3.56875942)]])
print('bifurcaciones:',values)
print('razones sucesivas:',np.diff(values)[:-1]/np.diff(values)[1:])

A Poincaré section records where a flow crosses a transverse surface in a chosen direction. It reduces a continuous trajectory to a sequence of points; changing direction mixes different crossings. The map of successive maxima of zz is another reduction, related to but not identical to an arbitrary horizontal section.

InteractiveSlicing the attractor

RK4 uses step 0.01 and discards 20 time units as a transient. The scene centers z at 25 and divides positions by 12. Crossings are linearly interpolated; the 3D view shows one in four crossings and the 2D section shows all. Maxima come from the temporal grid and have sampling error.

27
Upward crossings132
Maxima found132
The plane moves in height; points are interpolated upward crossings. Below are the section and the return of successive maxima of z.

Shadowing and statistics

Shadowing states, in versions with hyperbolicity assumptions and sufficiently small local errors, that a pseudoorbit stays close to some exact orbit over the interval considered. That orbit may start from a different initial state: the result does not recover the actual observed trajectory or automatically guarantee validity for every system or integrator.

Ergodic statistics connect time averages and expectations with respect to an invariant measure when the ergodic theorem’s assumptions hold. Discarding a transient does not prove stationarity or ergodicity. To quantify uncertainty of a correlated average, divide a long trajectory into sufficiently long blocks or estimate autocorrelation; comparing replicates and integration steps helps detect bias. An ensemble of initial conditions can estimate distributions and probabilities, provided it reflects initial and model uncertainty.

If the average of NN correlated values is treated as if they were independent, the estimated standard deviation can be too small. In a stationary process with summable autocorrelations ρk\rho_k, the variance of the average behaves approximately as σ2τint/N\sigma^2\tau_{\mathrm{int}}/N, where τint=1+2∑k≥1ρk\tau_{\mathrm{int}}=1+2\sum_{k\ge1}\rho_k. In practice the sum must be truncated and sensitivity to truncation checked. Blocks offer an alternative: calculate each block mean, increase block length until estimated uncertainty changes negligibly and check that enough blocks remain. Neither procedure eliminates discretization bias or an incorrect invariant measure.

Lab: Lorenz-96 and the full spectrum

On a ring of d≥4d\ge4 variables, x˙i=(xi+1−xi−2)xi−1−xi+F\dot x_i=(x_{i+1}-x_{i-2})x_{i-1}-x_i+F, with periodic indices. Its divergence is −d-d. The code integrates state and tangents using RK4 and reorthogonalizes by QR. Finite-time estimates are not exact values; repeat with longer times, smaller steps and different transients.

[ ]Lorenz-96 and Benettin's algorithmBrowser
import numpy as np
def lorenz96(x, forcing=8.0):
    x=np.asarray(x,dtype=float)
    if x.ndim!=1 or len(x)<4: raise ValueError('se requieren al menos cuatro variables')
    return (np.roll(x,-1)-np.roll(x,2))*np.roll(x,1)-x+forcing
def jacobian96(x, forcing=8.0):
    x=np.asarray(x,dtype=float); n=len(x)
    if x.ndim!=1 or n<4: raise ValueError('se requieren al menos cuatro variables')
    i=np.arange(n); J=-np.eye(n)
    J[i,(i+1)%n]+=x[(i-1)%n]
    J[i,(i-2)%n]-=x[(i-1)%n]
    J[i,(i-1)%n]+=x[(i+1)%n]-x[(i-2)%n]
    return J
def rk4_tangent(f,jac,x,Q,dt):
    def rhs(y,V): return f(y),jac(y)@V
    a,A=rhs(x,Q); b,B=rhs(x+dt*a/2,Q+dt*A/2)
    c,C=rhs(x+dt*b/2,Q+dt*B/2); d,D=rhs(x+dt*c,Q+dt*C)
    return x+dt*(a+2*b+2*c+d)/6, Q+dt*(A+2*B+2*C+D)/6
def lyapunov_spectrum(f,jac,x0,dt,n_steps,qr_every=5,burn_steps=0):
    x=np.asarray(x0,dtype=float).copy()
    if x.ndim!=1 or not np.all(np.isfinite(x)) or dt<=0 or n_steps<=0 or qr_every<1 or burn_steps<0: raise ValueError('parámetros inválidos')
    Q=np.eye(len(x))
    for _ in range(burn_steps):
        x,Q=rk4_tangent(f,jac,x,Q,dt); Q,_=np.linalg.qr(Q)
    Q=np.eye(len(x)); sums=np.zeros(len(x))
    for i in range(n_steps):
        x,Q=rk4_tangent(f,jac,x,Q,dt)
        if (i+1)%qr_every==0 or i+1==n_steps:
            Q,R=np.linalg.qr(Q); diagonal=np.abs(np.diag(R))
            if np.any(diagonal==0): raise FloatingPointError('base tangente singular')
            sums+=np.log(diagonal)
    return sums/(n_steps*dt)
def kaplan_yorke(exponents):
    lam=np.sort(np.asarray(exponents,dtype=float))[::-1]
    if not len(lam) or not np.all(np.isfinite(lam)): raise ValueError('espectro inválido')
    sums=np.cumsum(lam); positive=np.flatnonzero(sums>=0)
    if not len(positive): return 0.0
    j=int(positive[-1])+1
    return float(j if j==len(lam) else j+sums[j-1]/abs(lam[j]))
[ ]Finite spectrum and Kaplan-Yorke dimensionBrowser
x0=np.full(8,8.); x0[0]+=.01
exponents=lyapunov_spectrum(lorenz96,jacobian96,x0,.02,1000,5,400)
print('espectro finito:',exponents)
print('suma y divergencia:',sum(exponents),-len(x0))
print('dimensión Kaplan-Yorke estimada:',kaplan_yorke(exponents))

The Kaplan-Yorke dimension interpolates between partial sums of ordered exponents. It is an estimate associated with the spectrum, not an exact measurement of geometric dimension for every system. A sum close to −8-8 checks the volume balance, but does not establish convergence of every exponent.

[ ]Ensemble of initial conditionsBrowser
rng=np.random.default_rng(42)
base=np.full(8,8.);base[0]+=.01
ensemble=base+rng.normal(size=(20,8))*1e-6
initial_rms=np.sqrt(np.mean(np.sum((ensemble-base)**2,axis=1)))
def field_batch(x): return (np.roll(x,-1,axis=1)-np.roll(x,2,axis=1))*np.roll(x,1,axis=1)-x+8
def advance(x,h):
    a=field_batch(x);b=field_batch(x+h*a/2);c=field_batch(x+h*b/2);d=field_batch(x+h*c)
    return x+h*(a+2*b+2*c+d)/6
reference=base[None,:]
first=None; threshold=1.
for step in range(1000):
    ensemble=advance(ensemble,.02);reference=advance(reference,.02)
    rms=np.sqrt(np.mean(np.sum((ensemble-reference)**2,axis=1)))
    if first is None and rms>=threshold: first=(step+1)*.02
print('primer tiempo RMS >= 1:',first,'error RMS final:',rms)
[ ]Compare horizonsBrowser
predicted=np.log(1/initial_rms)/exponents[0]
print('RMS inicial:',initial_rms,'predicción exponencial:',predicted,'primer cruce medido:',first)

The horizon here is defined by a specific norm threshold and a synthetic ensemble with a fixed seed. The reference starts near the unstable uniform equilibrium, while the spectrum discards a transient: initial local rates and perturbation orientations prevent expecting exact agreement. None would mean that the threshold was not reached in the simulated interval. The result tests the procedure in this model, not atmospheric predictability.

Exercises

NumericTime to threshold
With λ₁=0.9 and initial error 10⁻⁶, estimate the time to reach threshold 1 under the exponential model.
NumericAn initial improvement
With λ₁=0.9 and initial error 10⁻⁶, how much time is gained by reducing it to 10⁻⁹ while keeping the same threshold?
ProofSum of exponents
Prove: Derive the sum of exponents from the tangent fundamental matrix.
0
Φ'=Df(x(t))Φ and Φ(0)=I; assume the required time limits exist.

Step 1 of 3. What does Liouville's formula state?

CodeSpectrum with QR
Implement lyapunov_spectrum(f, jac, x0, dt, n_steps): jointly integrate state and tangent matrix with RK4, reorthogonalize at each step and return accumulated rates.
import numpy as np
def lyapunov_spectrum(f, jac, x0, dt, n_steps):
  pass
Shift+Enter to run
QuizNeutral direction
Why does a zero exponent often appear in an autonomous flow along a bounded nonstationary orbit?
QuizBeyond the horizon
A long chaotic numerical trajectory separates from the physical trajectory. What can be concluded?
Key idea
Chaos limits point prediction through perturbation growth, but distributions can be studied if the model, regime and errors are validated for that question.