function Mandelbrot(iter,pixel)

% MANDELBROT(ITER,PIXEL) draws the Mandelbrot set;
% ITER gives the number of iterations and
% PIXEL indicates the number of points on the x-axis.

% MANDELBROT uses iter = 23, pixel = 400.

% This file was generated by students as a partial fulfillment 
% for the requirements of the course "Fractals", Winter term
% 2004/2005, Stuttgart University.	
	
% Author : Jochen Schurr
% Date   : Nov 2004
% Version: 1.0

% default setting
switch nargin
    case 0
        iter=40;
        pixel=600;
end

% decompose x- and y-axis according to the chosen
% proportion of r = 3:4.
r = 3/4; 
x = linspace(-2.5,1.5,pixel);
y = linspace(-1.5,1.5,round(pixel*r))';

% create the matrix C containing all pixel
% to be analysed.
[Re,Im] = meshgrid(x,y);
C = Re + i * Im;

% The matrix B assigns a number to every pixel which is
% characteristic with respect to the velocity of divergence.
% Therefore B and C have the same dimension.
B = zeros(round(pixel*r),pixel);

Cn = B;             % C0 = 0+0i
for l = 1:iter
    Cn = Cn.*Cn + C;       % performing the map
    B = B + (abs(Cn)<2);   % if |cn| > 2 the sequence diverges
end;

% plot settings
imagesc(B);
colormap(jet);

axis equal
axis off