function [m]=mandelbrot(edge,x1,x2,y1,y2) %[m]=mandelbrot(edge,x1,x2,y1,y2) is a function to check membership in the Mandelbrot set %[m] is a 2 dimensional output array, m(edge,edge). % Each element is 0 if the point is in the Mandelbrot set or n if it is not. % n=1 to 32 is the number of terms before element was proven not to belong. % [edge] is the dimension of square array m % [x1,x2] are min and max x values which are checked,(between -4 and 1) % [y1,y2] are min and max y values which are checked, (between -2.25 and 2.25) % Note that the Student Edition of MATLAB is limited to a 127x127 array % Try calling '[m]=mandelbrot(100,-2,-1.9,.5,.6) or use mandelplot(edge,x1,x2,y1,y2) % MD Checkel 990103 maxloop=64; %number of iterations to test whether sum of terms "blows up" maxsize=9e5; %threshold value at which sum is stopped. if edge<1 edge=10; %if array is dimensioned at 0, make it a 10x10 array end m=zeros(edge); %create array with zero's in it to confirm there is room ystep=(y2-y1)/edge; %calculate the step in x and y values to generate x and y arrays xstep=(x2-x1)/edge; iy=1; for y=y1:ystep:y2 %loop at each y point to evaluate Mandelbrot sum for all x points. ix=1; for x=x1:xstep:x2 %loop to evaluate Mandelbrot sum for each x point mx=x; my=y; for i=1:maxloop %loop to build up Mandelbrot sum realnum=mx*mx; imagnum=my*my; if(realnum+imagnum)>maxsize %check if Mandelbrot sum is over threshold break end my=(mx*my)+y; %increase value of each term by original x,y values mx=(realnum-imagnum)*.5 +x; end m(iy,ix)=maxloop-i; ix=ix+1; end iy=iy+1; end