pouët.net

complex powers and mandelbrot / fractals

category: general [glöplog]
 
err... I'm having a bit of trouble understanding complex powers.

There's a Mandelbrot set renderer out there that implements 'complex powers'.. but I've been unable to work out whether they're 'true' complex powers or not, or if my implementation is incorrect. I've used math libraries which have a complex power function built in, and they don't achieve the same result.

In the renderer that implements complex powers, the set looks like this :

BB Image

So raising it to p(2,0i) yields the same results as z = z * z + c, etc.

Using a math library to calculate "z ^ @power + c" doesn't yield the same results. I also tried recreating the algorithm mentioned on this page : http://en.wikipedia.org/wiki/Exponential_function#Computation_of__where_both_a_and_b_are_complex, with no results. (I just get a blank bitmap).

You think he is genuinely raising z to a complex, or is he using some trickery to gain the results displayed in the above image..?

(I'll also post the code I extrapolated from the wikipedia page. if you can decipher it, please let me know if I'm going horribly wrong somewhere)

Code: //_z ^ _p, where both _z and _p are complex Complex _z; // some complex number Complex _p; // raised to this complex number Complex pow; // store results here Double _r = Math.Sqrt(_z.Real*_z.Real + _z.Imag * _z.Imag); //abs Double _t = Math.Atan2(_z.Real, _z.Imag); // theta pow.Real = (Math.Pow(_r, _p.Real)) * Math.Exp(-_p.Imag * _t) * Math.Cos(_p.Real * _t + _p.Imag * Math.Log(_r)); pow.Imag = (Math.Pow(_r, _p.Real)) * Math.Exp(-_p.Imag * _t) * Math.Sin(_p.Real * _t + _p.Imag * Math.Log(_r)); // pow should now contain result
added on the 2008-02-08 07:14:41 by chameleon chameleon
It should read
Code:Double _t = Math.Atan2(_z.Imag, _z.Real); // Real, Imag swapped


Also, you might want to compute log(r²)=2 log(r) directly, without going through the sqrt first, and use that in the pow computation as well. You should end up with something like

Code: Double _logr2 = Math.Log(_z.Real*_z.Real + _z.Imag*_z.Imag); Double _t = Math.Atan2(_z.Imag, _z.Real); Double _newr = Math.Exp(_logr2 * _p.Real * 0.5 - _t * _p.Imag); Double _newt = _t * _p.Real + logr2 * _p.Imag * 0.5; pow.Real = _newr * Math.Cos(_newt); pow.Imag = _newr * Math.Sin(_newt);


(unless I forgot something important :)
added on the 2008-02-08 07:47:49 by ryg ryg
thanks .... but still no luck :( there must be something I'm missing...

I actually mailed the guy who wrote the program. he sent me back the expected answer, x^y = exp(y*log(x)).

hmm.. btw.. is the image showing up? basically, if _p = (x + 0i) then the algorithm (z = z ^ p + c) acts the same as (z = z ^ x + c), but if _p = (2 + 1i) then you get a whole different set of images.. ahh... I've been searching for days, lol.
added on the 2008-02-08 08:49:30 by chameleon chameleon
NERD ALERT!
added on the 2008-02-08 10:04:38 by kurli kurli
Repost image plz its teh b0rked X(
added on the 2008-02-08 10:19:13 by doomdoom doomdoom
chameleon, I think your problem is easy. On the first iteration your point is z=(0,0), then r=0, and your log is fucked up (NAN/INF!!!)

On the first iteration (n=1), just do z=c, and on the others apply the z=z^p+c. It works fine here (and don't forget the trick ryg mentioned for the square roots).
added on the 2008-02-08 10:55:54 by iq iq
Quote:
You think he is genuinely raising z to a complex, or is he using some trickery to gain the results displayed in the above image..?


Nah, it's integer powers of complex numbers. And that integer is usually 2. So it's basically just multiplication of complex numbers, which is easy (look up on wikipedia if you need more details).

Complex powers of complex numbers are not really well-defined, because z^w would be exp(w*log(z)), and the logarithm itself is not really well-defined (it is well-defined on a branched cover of the complex plane, but judging from your problems you don't want to go there :)
added on the 2008-02-08 14:28:59 by blala blala

login