%MANDEL3 Third Mandelbrot file.
% Changes made: write "1i" instead of "i".
% Preallocate Z to correct size.
clear
xmax=2;
steps=300;       % Points in each direction?
maxiter=64;      % How many steps per point?

% Initialization
Z = zeros(steps);  % Z is steps-by-steps.
X = [-xmax:2*xmax/(steps-1):xmax];
Y = [-xmax:2*xmax/(steps-1):xmax];

for m=1:steps
  c = 1i*(Y(m));  % What y value to use?
  for n=1:steps
    c = X(n) - .5 + 1i*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