%Mandelbrot set clf clear xmin = -2.1; xmax = +0.6; ymin = -1.1; ymax = +1.1; %number of points = resolution in x and y direction nPoints = 31; %upper limit for |z|, consider series has diverged if exceeded zmax = 1e6; %the 'i' index walks along the 'x' direction for i=1:nPoints % the 'j' index walks along the 'y' direction for j=1:nPoints %%%% map the index 'i' onto the interval [xmin,xmax] %%%% i=1 must yield 'xmin' %%%% i=nPoints must yield 'xmax' x(i) = % add line here %%%% map the index 'j' onto the interval [ymin,ymax] %%%% j=1 must yield 'ymin' %%%% j=nPoints must yield 'ymax' y(j) = % add line here c = complex(x(i),y(j)); % this converts (x,y) to a complex number 'c' z = complex(0.0,0.0); % iteration starts with complex number = 0 it_max = 50; % no more than 50 iterations please for n = 1:it_max %%%% add the iteration formula for the Mandelbrot set z = if (abs(z)>zmax) % stop the iteration of z exceed limit break; end end %store the results in the matrix ZZ(nPoints,nPoints) if (abs(z)<=zmax) ZZ(j,i)=0; % make it '0' for blue if |z| is small and series has not diverged else ZZ(j,i)=1; % make it '1' for red if |z| is large and series has diverged end end fprintf('Iteration %d\n',i); end imagesc(x,y,ZZ); % plot the image