Here is my mandelbrot function
function mandelbrot
% Mandelbrot set fractal
% ouput image resolution, WIDTHxHEIGHT
W = 100; %number of points in x axis
H = 100; %number of points in y axis
% fractal x y range
ymin = -0.5;
ymax = 0.5;
xmin = -2;
xmax = 0;
% maximum number of iterations
interation_max = 1000;
% Generate linearly spaced points from X_MIN to X_MAX
x = linspace(xmin, xmax, W);
% Generate linearly spaced points from Y_MIN to Y_MAX
y = linspace(ymin, ymax, H);
% Create a linear 2d grid
% X is 2d a array, column value are varying and row values are constant
% Y is 2d a array, row value are varying and column values are constant
[X, Y] = meshgrid(x, y);
% Allocate space for output
zval = zeros(H, W);
xn = 0;
yn = 0;
xnew = 0;
ynew = 0;
a = 0;
b = 0;
nPoints = W * H;
for m = 1:nPoints
a = X(m);
b = Y(m);
xn = 0;
yn = 0;
k = 1;
while (k <= interation_max) && ((xn^2+yn^2) < 4)
xnew = xn^2 - yn^2 + a;
ynew = 2*xn*yn + b;
xn = xnew;
yn = ynew;
k = k+1;
end
zval(m) = k;
end
cmap = flipud(jet(interation_max));
colormap(cmap);
image(x,y,zval); %show image
end