Link to home
Start Free TrialLog in
Avatar of crash020297
crash020297

asked on

fractals

This is probably ridiculous...but; I need to know how to implement a complex (a.k.a. imaginary) formula type thing in order to generate the mandelbrot set. In fact I'm making this question worth 600 points (and possibly more) in order to have someone help me with this program I need to write for a grade. I'm not looking for someone to write the program for me because then I wouldn't learn anything but I do need alot of help.
For the mandelbrot set the rule is z->z*z+c.
C is the complex number. You may already know this but I should say it any ways.
So I guess to make a run down of this question is.....I need to know how to program complex numbers and then graph them. Could someone please help?
Thank you,
crash
Avatar of ozo
ozo
Flag of United States of America image

(a + b*i) + (c + d*i) = (a+c) + (b+d)*i

(a+b*i) * (c+d*i) =
(a*c) + (a*d*i) + (b*i * c) + (b*i * d*i) =
(a*c) + ((a*d)+(b*c))*i + (b*d)*(i*i) =
((a*c)-(b*d)) + ((a*d)+(b*c))*i

ASKER CERTIFIED SOLUTION
Avatar of RONSLOW
RONSLOW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RONSLOW
RONSLOW

For info on the Mandelbrot algorithm, look at

http://www.softlab.ece.ntua.gr/faq/fractal/faq-doc-6.html

You will need to be able to multiply two complex numbers (or at least square one) and to be able to add them, and be able to get the magnitude (||) of it to test for the exit condition.

The 'nice' way to do this is to write functinos for each operation.  More efficient is to expand out the calculations as one operation.  However, most compilers will be able to do optimizations (especially if the coplex functions are made static - in which case they will often be inlined).

Also, for efficiency, the operator may be better written as working on pointers.  eg

void AddIt (Complex* this, const Complex* that) {
  this->r += that->r;
  this->i += that->i;
}

This is quicker because 1) we are only passing pointers and not the whole complex struct. 2) we aren't constructing any temporary objects.

At the same site is a page with complex operations

http://www.softlab.ece.ntua.gr/faq/fractal/faq-doc-8.html

Here is (an excerpt) the text of that page .. You should be able to use these to write complex arithmetic functions

[NOTE: If you were able to use C++, then you could write a Complex class that understood operators like + etc, or just use the complex datatype from the standard library]

>>>
(note: a,b are reals, x,y are complex, i is the square root of -1)
Powers of i: i^2 = -1
Addition: (a+i*b)+(c+i*d) = (a+c)+i*(b+d)
Multiplication: (a+i*b)*(c+i*d) = a*c-b*d + i*(a*d+b*c)
Division: (a+i*b)/(c+i*d) = (a+i*b)*(c-i*d)/(c^2+d^2)
Exponentiation: exp(a+i*b) = exp(a)(cos(b)+i*sin(b))
Sine: sin(x) = (exp(i*x)-exp(-i*x))/(2*i)
Cosine: cos(x) = (exp(i*x)+exp(-i*x))/2
Magnitude: |a+i*b| = sqrt(a^2+b^2)
Log: log(a+i*b) = log(|a+i*b|)+i*arctan(b/a)
(Note: log is multivalued.)
Log (polar coordinates): log(r*e^(i*theta)) = log(r)+i*theta
Complex powers: x^y = exp(y*log(x))
DeMoivre's theorem: x^a = r^a * [cos(a*theta) + i * sin(a*theta)]

More details can be found in any complex analysis book.
>>>
Another good way is to use fractint. Fractint is distributed with the complete source code, so you can look in there and find good and fast algorithms for generating fractals.
That might be cheating a bit .. and that program (along with many others) is referred to in the sites I suggested.

Avatar of crash020297

ASKER

Thanks alot every one! This is so very helpful!
I really appreciate it.