1618.dev

small tools, one committed a day

Newton Fractal Explorer

Newton's method hunts a root by repeatedly stepping z → z − p(z) / p′(z). On the real line it just works. On the complex plane, colour every starting point by which root it ends up at and the basins of attraction interlock in a fractal — the border between "falls to this root" and "that root" is infinitely crenellated. Drag to pan, scroll to zoom, and click any point to watch its path to a root.

p(z) = roots zoom

Each colour is one root's basin; brightness shows how fast Newton got there. Black points never settle (a cycle, or a knife-edge between basins). The ringed dots mark the actual roots.

What you are looking at

Pick a polynomial like p(z) = z³ − 1. It has three roots, evenly spaced around the unit circle. Drop a starting point anywhere and run Newton's iteration; it will almost always spiral into one of the three. Paint each starting point in that root's colour and you get three basins of attraction — but their shared border is not a tidy curve. Zoom into any boundary and you find all three colours meeting again, forever. That endlessly repeating three-way frontier is the Newton fractal.

The iteration

zn+1 = zn − a · p(zn) / p′(zn)

p′ is the derivative; the ratio p/p′ is Newton's correction, the jump that lands you near a root. The relaxation factor a (the slider above) scales that jump: a = 1 is ordinary Newton; below 1 it under-steps and the basins fatten and smooth; above 1 it over-steps and the boundaries grow lacy and wild. It is the most fun knob on the page — sweep it slowly.

Brightness = speed

Two points can fall to the same root but at very different speeds — one in three steps, one in thirty as it picks its way along a basin edge. We shade each pixel by its iteration count: bright where Newton converged fast, dark where it dithered near the boundary. That shading is what makes the fractal filigree pop out along every frontier.

When Newton gets stuck

Newton's method does not always converge. The polynomial z³ − 2z + 2 (the trap in the menu) has a notorious flaw: start at z = 0 and the iteration bounces 0 → 1 → 0 → 1 forever, an attracting cycle that never reaches any root. A whole region of starting points drains into that cycle; we paint them black. Those black islands are real mathematics, not a rendering gap — Newton genuinely fails there.

How this page is built

The math lives in logic.py — the Newton step, the polynomials and their roots, the nearest-root classification, and the cycle detection (a point that never settles within the iteration budget). The picture is drawn in JavaScript on a canvas for speed, but the same Python backs the point inspector, so the path and root under your cursor come straight from the source of truth.