% mandelbrot set 

% complex numbers c, for which z -> z^2+c stays bounded
% (starting with z = 0)

% grid in the complex plane
[a,b]=meshgrid(linspace(-2.5, 1), ... 
               linspace(-1.5, 1.5));
c = a + i*b; 

% compute escape times n of z-iteration
z = 0;
n = ones(size(c));
for k=1:100; 
   z = z.*z + c; 
   n = n + (abs(z) < 3);
end;

% small n corresponds to exterior  
surf(a,b,0*n,n); 
shading interp; 
axis off; axis square;

