3 Downloads

Updated 04 Sep 2001

No License

The Mandelbrot set is computed by operating on a fairly simple equation that contains complex numbers of the form

x + yi where i = sqrt(-1)

The Mandelbrot equation is

z <- z^2 + c

where

z = x + yi and c = a + bi

substituting these values into z^2 + c we have

(x + yi)^2 + a + bi

x^2 + 2xyi - y^2 + a + bi

separating the real and imaginary parts of z gives

x <- x^2 - y^2 + a

y <- 2xy + b

To determine whether a point (a,b) in the complex plane is a member of the Mandelbrot set, the real and imaginary parts of the equation are iterated. The x and y values are first initialized to zero. The constants a and b, the point in the plane, are then substituted into the equations giving

x <- a and y <- b

for the first iteration. The two new values for x and y, along with the constants a and b, are now substituted into the equations again. This procedure (iteration) continues until the absolute value of x + yi 2, i.e., sqrt(x^2 + ^y2) 2. For those cases where this value never exceeds 2, the maximum number of iterations is preset. A value of about 500 is usually adequate, although this value is raised to several thousand when smaller details at high magnification are examined. The number of times the equations are iterated before the value of sqrt(x^2 + y^2) 2 is called the dwell. Those initial points (a,b) where the dwell is infinite, or for more practical purposes attains the preset maximum, are members of the Mandelbrot set. Another way to describe this is to say that for points within the Mandelbrot set, the sequence of points produced by this iteration procedure is bounded inside a circle of radius 2, where points outside the set are unbounded and continue to grow and escape the circle.

The Mandelbrot set exists entirely within the area defined by

-2 <= a <= 2 and -2 <= b <= 2

in the complex plane. A Mandelbrot image is produced by taking this area of the complex plane and dividing it into an array of 1200 x 1200 points. Each one of these points becomes the constant (a,b). The iteration procedure previously described is used on each of the 1.44 million points, coloring each point in the Mandelbrot set black and all others white. The algorithm is:

maxcount <- 1000

for b <- 2 to -2 stepdown 1/300

for a <- -2 to 2 step 1/300

x <- 0

y <- 0

count <- 0

while sqrt(x^2 + y^2) < 2 and count < maxcount

x <- x^2 - y^2 + a

y <- 2*x*y + b

count <- count + 1

end while

if count = maxcount plot(a,b,BLACK)

else plot(a,b,WHITE)

end for a

end for b

While the algorithm is not that complex, the amount of computation is enormous. Depending on programming language and style, the inner loop has at least four multiplications and a square root. For a point in the Mandelbrot set, this loop is executed 1000 times and there are over a million points to check! It is not surprising that the Mandelbrot set was not discovered until the age of computers.

Altan Bassa (2021). Mandelbrot (https://www.mathworks.com/matlabcentral/fileexchange/644-mandelbrot), MATLAB Central File Exchange. Retrieved .

Created with
R10

Compatible with any release

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

wang andythank

ken darrowCortland SetlowJust what I needed. That line ought to be

while (-2<a)&(a<2)&(-2<b)&(b<2)&(n<r);

There's some kind of character code issue.

To repeat, change ‹ to a less-than sign.

jim chaseThere appears to be an error in the program, which you can correct by replacing the line with while statement to :

while (sqrt(a^2+b^2)< 2)&&(n < r)

Then it sort-of does something like the picture on Student MatLab R13.

Daniel SollIf running under Linux, remove ‹ and insert < instead.

bard joelFile does not work

CJ Kloxintono V.Jason BoldFile does not work as is