Mandel

Mandelbrot

As the logistic function the mandelbrot set depends on one variable, although a complex variable with its imaginary and real part:

z_{n+1}={z_n}^2+c
x_{n+1}+i*y_{n+1}={x_n}^2+2i*{x_n}{y_n}-{y_n}^2+c_real+i*c_imag
x_{n+1}={x_n}^2-{y_n}^2+c_real
y_{n+1}=2*{x_n}{y_n}+c_imag

The important part is the orbit stability or if it stays bounded, that can be obtained by iterating a predetermined number with, e.g., a C function. The orbit is unstable if tends to infinity, the c function will ignore an orbit if surpasses a known limit:

vert{z_n}vert>M

The condition sets the Mandelbrot boundary,The iteration counts can be used into an RGB color map, the image and its colors obtained with the c function emphasizes the boundary and its depth showing how many times the magnitude(|z|) keeps inside the chosen limit. Now comes the last step, making the plot.

Library:

#include < stdio.h >
#include < math.h >
#include < stdlib.h >

M:

#define M 20

A structure and a local function:

struct complex
{
	double re, im;
}x, c;

double module(struct complex x)
{
	return sqrt(x.re*x.re +x.im*x.im);
}

An the main function:

int main(int argc, char** argv)
{
	double xx;
	int n, count;
	struct complex;

	FILE *fout;
	fout=fopen("Mandelbrot.dat", "w");

The final part you have to itinerate the function adding up how many times falls inside the limit condition - the “for ” or a “while” structure will do the job -, using a rectangle with steps of 0.005. As an example:

Re c in delim{[}{-2;0,5}{]} , Im c in delim{[}{-1;1}{]}

The file will be generated using:

fprintf(fout, "%gt %g %dn", c.re, c.im, count);

The linux user will open the file by typing in his terminal:

Plot [-2:0.5][-1:1] 'mandelbrot.dat' u 1:2:3 w image