Tuesday, July 8, 2014

The Mandelbrot Set and Fractals

The Mandelbrot set and associated Julia set are examples of beautiful fractal graphics derived from mathematics. Here is Wolfram Mathworld's introduction to the Mandelbrot set. Some relevant books are:

[1] Amazon: The Fractal Geometry of Nature, by Benoit B. Mandelbrot, 1982.

This books, however, does not have good review as the writing is said to be not so good. A review on Amazon is: "It is not an easily readable book. 1. It is not well-organized 2. It does not cover necessary things in detail 3. Frustratingly long in some parts." Books on this topic that are said better by Amazon reviewers:

[2] Feder, Fractals; Turcotte, Fractals and Chaos in Geology and Geophysics.
[3] The Science of Fractal Images, edited by Peitgen and Saupe. The math is clear; the algorithms are plainly stated for the PC enthusiast with some simple programming skills; and the color plates are astounding.




The first Mandelbrot set image was created in 1978. The Python program below from [4] will draw such an image. Note to run the Python program you need Numpy, which stands for Numerical Python, and is a scientific computation module of Python. You can download the win32 installation package from [6], or amd64 version from [7]. On my system, I have Python 2.7.1 and use Numpy 1.8.1. 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2013, P. Lutus http://arachnoid.com
# Released under the GPL http://www.gnu.org/licenses/gpl.html

from numpy import arange

# dimensional parameters for the set

yl = -1.2
yh = 1.2
ys = .05

xl = -2.05
xh = 0.55
xs = 0.03

def mandelbrot(c):
  z = 0
  for n in range(10):
    z = z*z + c
    if(abs(z) > 2):
      return '.'
  return '*'
 
s = ''
for y in arange(yl,yh,ys):
  for x in arange(xl,xh,xs):
    s += mandelbrot(complex(x,y))
  s += '\n'
 
print(s)


[5] contains an example program to draw the Mandelbrot set image in iPhone.

[8] is about doing the drawing in JavaScript. It includes the formula of Linas Vepstas algorithm to draw a smoothed-color version of the image:

\mu = n + 1 - \frac{1}{\log 2}\log \log P_c^n(0)


References:

[4] Mandelbrot Set - An exploration in pure mathematics
[5] A Mandelbrot Set Visualization on the iPhone
[6] Sourceforge: Numerical Python
[7] Unofficial Windows Binaries for Python Extension Packages
[8] Visualizing the Mandelbrot set with JavaScript


No comments:

Blog Archive

Followers