This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

← Posts

demoAIDynamics and chaos

The double scroll of Chua's circuit

Two capacitors, an inductor, a resistor and one diode whose current is a three-piece straight line. The voltages never settle and never repeat: they wind around two centers, hopping between them at irregular times. Nearby starts separate like with , which is what a separate scipy calculation gives within the scatter expected of a run this long.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

The exponent is measured here by following two copies of the circuit started apart and pulling them back to that distance after every step (Benettin's method). The reference, in posts/refs/chuas-circuit-double-scroll.py, uses a different method and a different integrator: scipy's DOP853 at a tolerance of , carrying the linearized equations along the orbit, over 24000 time units. It gives . Split into 40 windows of 600 time units (the length of this post's run), the estimates scatter with a standard deviation of 0.0165, so the test allows three of those: 0.05.

The circuit

Chua's circuit is an electronic circuit designed by Leon Chua to be chaotic: its voltages follow a definite rule, with no randomness in it, yet never settle into a repeating pattern. It has two capacitors, an inductor, a resistor, and one nonlinear part, a Chua diode: a small circuit whose current is a function of the voltage across it made of three straight pieces. In the middle the slope is and outside it is , and both slopes are negative, so the part feeds energy into the circuit instead of absorbing it.

In scaled units, with and the two capacitor voltages and the inductor current, the equations are the three above. The program uses the standard double-scroll values , , and .

Printed

-0.571429
-1.85714
The Chua diode's current: three straight pieces
g(x)
−202−3−2−10123voltage xcurrent g(x)

Tests 1 of 1 pass

  • the diode is m0 x inside |x| < 1 and m1 x + (m0 - m1) outside (passes)

Inside the current is , so , and outside it is for , so . The negative slopes make the origin unstable: a small voltage grows instead of dying away. Far out, the circuit's other parts win and push it back. With nowhere stable to rest, the state keeps moving.

Stepping the equations

The program advances the state with the classical fourth-order Runge-Kutta method at a step of , then runs 20000 steps (100 time units) so the state reaches the set it keeps returning to, the attractor, before anything is measured.

Printed

settle_time: 100
sa: [1.9856, 0.336371, -1.75373]

Tests 1 of 1 pass

  • the settling run is 20000 steps of 0.005, 100 time units (passes)

The double scroll

Now follow the state for 210 time units (42000 steps). Record , and count how often it changes sign: the attractor has two lobes, one around and one around , and a sign change is a hop from one to the other. Before looking: if the motion were periodic, the hops would come at a fixed rhythm. Do they?

Printed

jumps: 41
The voltage x over 100 time units
x(t)
−20220406080timex
The double scroll, seen along z
(x, y) over 210 time units
−0.4−0.200.20.4−2−1012xy
the double scroll in (x, y, z): drag to rotate
drag to rotate · x [-2.24, 2.24] · y [-0.4, 0.4] · z [-3.18, 3.18]

Tests 1 of 1 pass

  • the orbit hops between the scrolls about 41 times in 210 time units, as scipy's long run does (passes)

In 210 time units the state changed lobes 41 times (jumps): a few turns around one center, then a few around the other, with the number of turns changing from visit to visit. That irregular count is the visible sign of chaos. A scipy run a hundred times longer (posts/refs/chuas-circuit-double-scroll.py) averages 40.9 hops per 210 time units, and single stretches of that length range from 34 to 50, with a standard deviation of 3.1; the test allows three of those.

How fast nearby starts separate

Chaos has a measurable rate. Start two copies of the circuit a distance apart. On average the distance grows like ; is the largest Lyapunov exponent, and a positive is what chaos means in numbers. The two copies cannot be left alone for long, since once their distance is as large as the attractor it stops growing. So after every step the program measures the new distance , adds to a running sum, and moves the second copy back along the same direction to distance . The exponent is the sum divided by the elapsed time.

The run is 120000 steps, 600 time units. The reference value from scipy is , and a run of this length scatters about the true value with a standard deviation of .

Printed

lyap: 0.326691
horizon: 56.3857
The running estimate of the largest Lyapunov exponent
ln(d / d0) summed, over elapsed timescipy's value, give or take one 600-unit run's spread
00.20.40.6100200300400500600timeλ estimate

Tests 2 of 2 pass

  • the largest Lyapunov exponent is scipy's 0.3277 within three standard deviations of a 600-time-unit estimate (passes)
  • a 1e-8 difference reaches order one in ln(1e8) / lambda = 56 time units, scipy's 56.2 within 15 percent (passes)

The estimate wanders early, while one or two passes near the center of a lobe can move it, and settles as the time grows. This run gives (lyap), against scipy's . At that rate a difference of in the starting voltage grows to order one, the size of the attractor, in time units (horizon). Past that time the equations are still exact, but a measurement of the starting voltage to eight digits no longer predicts which lobe the circuit is on.

Checked when the site was built: 5 of 5 tests passed, in 6.36 s. Download 2026-09-25-chuas-circuit-double-scroll.viv