# [Edu-sig] Fractals

kirby urner kirby.urner at gmail.com
Fri Apr 28 02:59:23 CEST 2006

```So one of my high schoolers wants to use Python to understand
Fractals?  What should we do?

Per my opener for Mandelbrot that time (a PowerPoint, done on short
notice for Terry, when the originally scheduled talent bailed) I broke
it down into sequences and their characteristics.

Sequences may be reiterative, meaning they feed back into themselves
(Fibonaccis the classic example).

Sequences may be convergent, meaning they approach a value.  Or
divergent, meaning they go huge (more should be said).  Or oscillatory
(regular repeating sequence).  Or chaotic, which is the "irrational
number" like sequence:  not divergent, not oscillatory, never settles
down, never converges.

Interesting.

So then as an example of chaotic, we should import from cmath and
simply explore the feedback loop z = z**2 + c for convergence or
divergence.  Actually, we don't really need cmath

It's not that this loop is chaotic.  It's that the boundary in between
the convergent and divergent sequences it generates is chaotic.

Two complex numbers, arbitrarily close together, may diverge in
whether they converge or not, or on how fast they diverge (a source of
color differences).

>>> def seq(o=0j, z=1+1j):
while True:
yield o
o = o**2 + z

>>> g = seq()
>>> for i in range(10): print g.next()  # divergent!

0j
(1+1j)
(1+3j)
(-7+7j)
(1-97j)
(-9407-193j)
(88454401+3631103j)
(7.81099614727e+015+6.42374081669e+014j)
(6.05990163519e+031+1.0035162954e+031j)
(3.5715362873e+063+1.21624200789e+063j)

>>> g = seq(z=0.1+0.1j)
>>> for i in range(10): print g.next()  # convergent!

0j
(0.1+0.1j)
(0.1+0.12j)
(0.0956+0.124j)
(0.09376336+0.1237088j)
(0.093487700481+0.123198705499j)
(0.0935620291046+0.123035127359j)
(0.093616210726+0.123022832334j)
(0.0936293776353+0.123033862792j)
(0.0936291289629+0.123039168003j)

Kirby
```