%MANDEL1 First Mandelbrot file.
clear
xmax=2;
steps=300;       % Points in each direction?
maxiter=64;      % How many steps per point?

% Initialization
Z=0;
X=[-xmax:2*xmax/(steps-1):xmax];
Y=[-xmax:2*xmax/(steps-1):xmax];

for m=1:steps
  c = i*(Y(m));  % What y value to use?
  for n=1:steps
    c = X(n) - .5 + i*imag(c);  % What x value?
    z = c;
    for r = 0:maxiter
      z = z*z + c;    % Fractal calculation
      if abs(z)>2     % Stop if outside circle.
        break
      end
    end
    Z(m,n) = sqrt(r/maxiter);  % Color = #iter.
  end
end

% Plotting commands.  Scale colormap to data.
imagesc(Z)
axis off, axis equal