Formula explained

\(f(z)=z^2+c\) represents the Mandelbrot Set.
But what is \(c\)?
\(c\) is a complex number.
Complex numbers contain a real part (\(a\)) and an imaginary part (\(b\cdot i\)). Together they form a complex number: \(c:=a+b\cdot i\).
The complex thingy about this? The imaginary unit \(i\) must satisfy the equation \(i^2=-1\).

In the Mandelbrot Set, you do not have ordinary \(x\)- and \(y\)-axes:
You use the real part of the complex number as \(x\)-axis and the imaginary one as \(y\)-axis.

You can now fill the formula with complex numbers of a coordinate system with said axes.
To get a representative solution, you have to recursively put the output of the formula in itself over and over again. The more repetitions, the more exact is the outcome.

Let´s say you want to have a Mandelbrot Set with three repetitions.
The formula would look like this: \(f(z)=f(f(0)^2+c)^2+c\).
Or like this: \(f(0)=((0^2+c)^2+c)^2+c\) (\(z\) has value \(0\) at the first repetition).

You have to watch out when squaring a complex number! Keep in mind that \(i^2=-1\):
\(c^2=(a+b\cdot i)^2=a^2+2 a b i+b^2\cdot i^2=a^2+2 a b i+b^2\cdot (-1)=a^2+2 a b i - b^2=a^2-b^2+2 a b i\)

\(a^2-b^2+2abi\) is something we can work with. It is possible to calculate the real part and the imaginary part separately:
\(g(a)=a^2-b^2+m\)
\(h(b)=2ab+n\)
(\(m\) and \(n\) are constants that represent the values of \(a\) and \(b\) before the first repetition: \((m:=a)\) and \((n:=b)\))

Colors

You probably connect colorful pictures with the Mandelbrot Set.
So what does the formula have to do with those pictures?

What we want to know is, whether a complex number is getting bigger and bigger or getting closer to zero when inserted to the formular.
If close to zero, this complex number is 'within' the Mandelbrot Set and often painted black.
A number that is getting bigger with every repetition is not in the Mandelbrot Set and therefore painted in a color.
The color is mostly connotated with the number of repetitions it takes to exceed a certain value - this value should be at least \(2\).

To get more exact pictures of the Mandelbrot Set, the number of repetitions has to be as high as possible.
If you want to see how this looks like in Java code, click here.