The following MATLAB program uses matrix arithmetic to carry out
the Mandelbrot iteration simultaneously for a whole matrix of
c-points. With the indicated 667 by 520 resolution, each matrix
involved in the computation has over a third of a million elements
and occupies about 2.8 megabytes of memory. Hence, you probably will
need a computer with 32 megabytes of RAM to run the program as
written. If your computer runs out of memory, try decreasing the
resolution (as indicated "for rough drafts").
function w = mandel(wind, count)
% Constructs Mandelbrot set
% C. Henry Edwards August 1996
% Before running mandel define wind = [a b c d]
% and the number count of iterations desired. Thus
%
% >> wind = [-2.25 1.75 -1.5 1.5];
% >> count = 100;
% >> w = mandel(wind, count);
%
% should generate the standard picture.
a = wind(1); b = wind(2); % viewing window
c = wind(3); d = wind(4); % in the complex plane
p = 667; q = 520; % p x q grid of points
% p = 100; q = 78; % for rough drafts
x = a : (b-a)/(p-1) : b;
y = c : (d-c)/(q-1) : d;
[x,y] = meshgrid(x,y); % grid of complex points
c = x + i*y;
clear x y
z = zeros(q,p);
for k = 1:count
k
z = z.*z + c;
end
w = ones(q,p);
w = w + ( abs(z) < 2 ); % black or white?
w = flipud(w);
bwmap = [ 1 1 1; 0 0 0 ];
image(w), colormap(bwmap), axis off