April 15, 2014

A-Z Challenge 13: Mandelbrot set

Here’s some cool stuff for the math nerds, and a question to the art nerds. It’s about the Mandelbrot set. This is a mathematical object which was discovered more or less by chance, by the Polish mathematician Benoit Mandelbrot. What is cool about the Mandelbrot set, is that it makes some incredible pictures, using a very simple formula.

This is how you compute the Mandelbrot set: Take a number, square it, and add a constant. Repeat the procedure several times. This is the formula:

z(n+1) = z(n)*z(n) + c.

Depending on the choice of the constant c, the iterated number z(n) may stay finite, or it may grow to infinity.
There’s one more thing: Both z(n) and c have to be complex numbers, with a real part (x) and an imaginary part (y). It can be shown that if z(n+1) stays finite, it don’t get larger than 2 in magnitude. This makes the Mandelbrot set easy to compute. Just iterate the formula above (say) 50 times for all values of c (start with z(1)=c), and count how many iterations (n) are needed to make z(n+1) larger than 2. Then make a plot of the number of iterations n. Very simple. I computed the pictures below in 10-15 seconds with Matlab on my lap-top.

If you zoom on the Mandelbrot set, you will discover incredible patterns, and sometimes small Mandelbrot-set look-alikes hidden inside the full set. (To do the actual zoom, you need to re-compute inside a smaller subset of the image, to get higher resolution). The cool parts are along the rim of the Mandelbrot set.

And then comes my question to the art nerds: Is the Mandelbrot set art? It looks like art, but is it art, being created by a simple mathematical formula? What do you think?

There are fancy ways to compute the Mandelbrot set fast, and with high resolution. The code that I wrote in Matlab is not the fastest, but very simple. Here it is (lines starting with % are comments):

%-------------------------------------- 
% Plot the Mandelbrot set 
%-------------------------------------- 

%--- Set max iterations and grid size: 
nmax = 50; 
nx = 601; ny = 481; 

%--- Select a subset of the complex plane: 
xRange = [-2, 1]; yRange = [-1.2,1.2]; 
%xRange = [-1.20,-1.0]; yRange = [-0.38,-0.22]; 
%xRange = [-1.043,-1.033]; yRange = [-0.292,-0.284]; 

%--- Gridding: 
dx = diff(xRange)/(nx-1); 
dy = diff(yRange)/(ny-1); 
x = xRange(1):dx:xRange(2); 
y = yRange(1):dy:yRange(2); 

%--- Mandelbrot loop: 
for j=1:ny 
    for i=1:nx 
       c = complex(x(i),y(j)); 
       z1 = c; 
       r2 = c*conj(c); 
       n = 1; 
       while (r2<4 && n<nmax) 
          z2 = z1*z1+c; 
          r2 = z2*conj(z2);
          z1 = z2; 
          n = n+1; 
       end 
       narr(i,j) = n; 
    end 
end 

%--- Plot result: 
figure; imagesc(x,y,narr'); 
colorbar; caxis([1, nmax]); 
axis xy; axis equal;

%-----------------------------------------
% THE END
%-----------------------------------------




(The pictures where computed with the Matlab code above. the codes runs in Octave too, if you don't want to pay for a Matlab license. The white frame in the 1st picture shows the area zoomed in the 2nd picture and so on. I'm just an amateur in this branch of mathematics, known as fractals. Check out this link for a real-time zoomable Mandelbrot viewer made by the pros. )

4 comments:

  1. Math is just part of the palate. I'd say it's art.

    ReplyDelete
    Replies
    1. To simple to make to call it art, isn't it? I could make hundreds of other cool pictures just by zooming on different parts of the Mandelbrot set

      Delete
  2. Oh this is absolutely gorgeous!
    I would agree with Alex - this is definitely art. Maths porn (to shamelessly use your clever post above) is used in heaps of art, from Kafkas mathematical spirals in "The Burrow" through to so much modern art that works through mathematical concepts, Da Vinci's geometry etc. It's really beautiful. Lovely post.

    ReplyDelete
  3. Math porn is a good name for it.

    My favorite when it comes to mathematical art is Escher (he made the eye with the scull that I use as my profile picture). I should probably write a post about Escher sometime >:)

    ReplyDelete

Related Posts with Thumbnails