Site hosted by Angelfire.com: Build your free website today!

World of fractals

 

Home | Image Galleries | Animations | Types of Fractals | Downloads | Understanding Fractals | Contest | Links


Creating Fractals: The Mathematics

The mathematics behind fractals are incredibly interesting and captivating. You need to have a grasp on algebra and some complex number background is preferable. We already described how fractals are created through applying functions, but never explained any functions and how they work. In this section, we will describe the two most popular fractal sets and how they work, the Julia set and the Mandelbrot set.

To understand fractals, you need to understand complex numbers. Complex numbers are a way to put two coordinates (x,y) into one number with two parts. One is a real number, which is any regular number like 3, 8.5, or 12/45. The other is an imaginary number, which is defined as the square root of a negative number, and is characterized by i (defined as i^2=-1, therefore i=sqrt -1) times a coefficient.When you take a number and square it, it always becomes positive. So how do you take the square root of a negative number? You can't, that's why it's called imaginary. So, complex numbers are made up of a real number plus an imaginary number. Examples include (1+.343i), (pi+343.6i), and (0+3i). Complex numbers are used in fractals because the real number is used to represent the x coordinate, and the complex number is used to represent the y coordinate. So, if the computer wanted to iterate (3,8), it would apply the function to (3+8i). This way, the function is dealing with a number to which most of the mathematical properties such as the associative and distributive laws can be applied, instead of a set of x and y coordinates. It is important to note that the complex coordinates are not the same coordinates of the pixel they represent. Pixel coordinates are always from 0 to the bounds of the screen, usually something like (786, 233). The range we use depends on the fractal, but it is usually something like x: -3 to 3; y: -2 to 2. Therefore, to apply the function to a pixel, we divide the units into hundreds of tiny segments, and the computers deal with the tiny fractions.

Performing functions on complex numbers is similar to real numbers, but there are some important distinctions.

Adding and subtracting is easy. We do it algebraically, adding and substracting the real and complex parts seperately.

(6 + 5i) + (3 - 3i)=

6+3 + 5i-3i=

9+ 8i

Multiplying complex numbers is a little more complex. Using the distributive law, we can solve multiplication with complex numbers similarly to those with real numbers.

(4+6i)*(2-i)=

4*6-4*i+2*6i-6i*i=

24-4i+12i-6(i^2)=

24+8i+6=

30+8i

First we separated the different terms using the distributive law, then we do the multiplication. We turn i^2 into -1, and then add like terms.

Division of complex numbers is not used much in fractals, but here is the formula anyway. We will not bother going through all the steps:

(x1+y1i)/(x2+y2i) =[(x1x2 + y1y2) + i(x2y1 - x1y2)]/(x2^2 + y2^2)

If that makes sense to you, good. If not, don't worry.

Now we know about how complex numbers are used. Next, lets describe a function used to make a fractal. There are an infinite number of such functions, but we would like to show how to create a Julia set since the Julia set is one of the most famous and makes pictures such as these:

So, now we know a little about complex numbers. The next thing to do is explain a function used to generate a fractal. As is mentioned in part one, there are an infinite number of these functions, but we will use a function for a Julia set as an example. The function for certain Julia sets is: f(z)=z^2+c. That's it. The new complex coordinate is set to the old one squared plus "c". What is c? It is simply a complex number, and it can have any value you like. Different c values produce different Julia sets. Let's use (1 + 1i) as c. So, if we were to start with the point (2 + 1i), the first iteration would be:

f(z)=f(2+1i)=

(2 + 1i)^2 + (1 + 1i)=

2*2 + 2*1i + 2*1i + 1i*1i + 1 + 1i=

4 + 2i + 2i + 1(-1) + 1 + 1i=

5 + 5i -1=

4 + 5i

So the first iteration brings us to (4 + 5i). We can do it again now.

f(z)=f(4 + 5i)=

(4 + 5i)^2 + (1 + 1i)=

4*4 + 4*5i + 4*5i + 5i*5i + 1 + 1i=

16 + 20i + 20i + 25(-1) + 1 + 1i=

17 + 41i - 25=

-8 + 41i

So our second iteration gives us (-8 + 41i). We continue to do this as described in part one, and each time we test to see if it has "left the screen". Actually, we are testing to see if the point ever leaves the circle centered at the origin with radius 2. We can prove that if it leaves this circle, it is bound to go to infinity, so we simply stop iterating once it leaves the circle. The number of times we must iterate the function before it leaves the circle is used to choose the color for the original point.

We must also set a limit of iteration on our fractal. Since the points inside the Mandelbrot set never leave the screen, we will iterate our function forever if we wait for them to leave our circle. To get around this, we set a limit on the number of times we will iterate it. If the point is still in our circle after that many iterations, we assume it is part of the set. The more iterations we use, the more exact and detailed our image will be, but the longer it will take to generate. When we have done this with every pixel, we have a fractal. Other equations than this one produce different fractals. Mandelbrot sets are produced the same way as Julia sets, except that c is different for every point. When generating a Mandelbrot set, c is equal to the point we are determining the color for. We start with 0, the origin. Then we square it and add c. We square this new value and again add c. When this finally leaves the circle, or when we have reached our iteration limit, we color the point at the complex coordinate c. Then we move to the next point. C is changed to that new point, and once again we start with the origin and iterate. Of course there are many other fractals that can be created with simple equations. If you download Fractint, you can create your own formulas and run them to see what fractals they will produce.

To learn about how fractals are applied, read the lesson on Fractals and Chaos Theory in the Real World

Special thanks to The Fractory for the pictures and the basis for these lessons.

 


Home | Image Galleries | Animations | Types of Fractals | Downloads | Understanding Fractals | Contest | Links