%-----------------------------------------------------------------------
%script MANDEL   Mandelbrot Set
clc
close
h = waitbar(0,'Computing...');
x = linspace(-2.1,0.6,301);
y = linspace(-1.1,1.1,301);
[X,Y] = meshgrid(x,y);
%C = complex(X,Y);
C1 = X; C2 = Y;

Z_max = 1e6; it_max = 50;
Z1 = X; Z2 = Y;
for k = 1:it_max
   %Z = Z.^2 + C;
   Z1 = Z1.*Z1-Z2.*Z2 + X;
   Z2 = 2*Z1.*Z2 + Y;
   waitbar(k/it_max)
end
close(h)
Z = sqrt(Z1.^2+Z2.^2);
contourf(x,y,Z<Z_max,1)
title('Mandelbrot Set','FontSize',16)
