% Parameters
max_iter = 100; % Maximum number of iterations
x_min = -2;     % Minimum x value
x_max = 1;      % Maximum x value
y_min = -1.5;   % Minimum y value
y_max = 1.5;    % Maximum y value
width = 800;    % Width of the image
height = 600;   % Height of the image

% Create a grid of complex numbers
x = linspace(x_min, x_max, width);
y = linspace(y_min, y_max, height);
[X, Y] = meshgrid(x, y);
C = X + 1i * Y; % Complex plane

% Initialize the output matrix
Z = zeros(size(C));
output = zeros(size(C));

% Mandelbrot iteration
for n = 1:max_iter
    mask = abs(Z) <= 2; % Mask for points within the radius
    output(mask) = output(mask) + 1; % Increment the count
    Z(mask) = Z(mask).^2 + C(mask); % Update Z
end

% Display the Mandelbrot set
imagesc(x, y, output);
colormap(hot); % Change colormap
axis xy; % Correct the axis orientation
colorbar; % Show color scale
title('Mandelbrot Set');
xlabel('Re(z)');
ylabel('Im(z)');