Logo by LAR2 - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. March 28, 2024, 05:07:42 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: "Modular" complex arithmetic  (Read 2161 times)
Description: An experiment without too many high hopes?
0 Members and 1 Guest are viewing this topic.
stigomaster
Guest
« on: December 16, 2009, 08:09:23 PM »

i somehow got the idea that I should try to make a "mod" function for complex numbers. I figured I might not let the magnitude of the number exceed a certain value. So what I'm trying to do right now is to plot a Mandelbrot set where the iterated point zn never goes outside the disc defined by the initial c value. I imagine that the plot would look very different for different iteration values. Moreover, because you won't be able to say that a point bails out, I would like to colour the points based on angle and magnitude.

I'm attaching a picture, although the program still has big flaws and the result is therefore far from what it is supposed to be.


* mandeldrip.jpg (32.61 KB, 400x300 - viewed 298 times.)
Logged
kram1032
Fractal Senior
******
Posts: 1863


« Reply #1 on: December 16, 2009, 08:17:36 PM »

complex mod is usually defined as mod(abs(z),a)*sign(z)

though, both terms modulo might be a bit more complicate

mod(abs(z),abs(c))*sign(z) (*sign(c)?)
Logged
stigomaster
Guest
« Reply #2 on: December 16, 2009, 10:38:09 PM »

I think I got the program to work as I wanted to now, at least it produces some satisfying output smiley I'll just put up some pics now, maybe I'll write some more later. Comments are fun!


* drip1.jpg (80.18 KB, 400x301 - viewed 288 times.)

* drip2.jpg (85.24 KB, 400x299 - viewed 280 times.)

* drip3.jpg (73.75 KB, 400x300 - viewed 294 times.)
Logged
kram1032
Fractal Senior
******
Posts: 1863


« Reply #3 on: December 16, 2009, 10:59:58 PM »

which values did you use? smiley

What happens for mod(z,2)?

nice wave patterns smiley
Logged
stigomaster
Guest
« Reply #4 on: December 18, 2009, 03:54:52 PM »

Turns out there was a little bug in the colouring algorithm, but I fixed it. To clear up my mod algorithm, I will now simply post the source code for the funtion smiley I call this function at every iteration.
Code:
void modCplx(double *r, double *i, double mod) {
double magn = sqrt(*r * *r + *i * *i);
double phase = (*r >= 0) ? asin(*i / magn) : 0.0 - asin(*i / magn) + 3.14159265359;

while(magn > mod) magn -= mod;

*r = cos(phase) * magn;
*i = sin(phase) * magn;
}

Quote
What happens for mod(z,2)?
Well, it certainly does not look too bad! I attach a series of renders at iteration values from 1 to 10. Coordinates are (-8, -6), (8, 6). The colouring algorithm is pretty simple; It's HSL where hue is the phase of z_n, saturation is 1 and light is abs(z_n)/abs(c).


* column.jpg (393.45 KB, 400x1800 - viewed 133 times.)
Logged
stigomaster
Guest
« Reply #5 on: December 18, 2009, 03:59:05 PM »

And hey, I'll put up some zooms too. The first is into my original function ("mod" (z_n, abs c ) ) and the second into the mod 2 version.


* dripzoom.jpg (265.12 KB, 800x600 - viewed 127 times.)

* zoommod2.jpg (250.46 KB, 800x600 - viewed 109 times.)
Logged
kram1032
Fractal Senior
******
Posts: 1863


« Reply #6 on: December 18, 2009, 04:47:02 PM »

very psychedelic smiley
Logged
TimGolden
Forums Freshman
**
Posts: 11



WWW
« Reply #7 on: December 19, 2009, 04:02:50 PM »

Great Experiment stigomaster.

Seems to me the challenge will be to get a function that has low populations in some regions. If a wrapping distance does not mesh with these low populations then there is bound to be a flooding of the space; essentially a loss of detail. Still you've got graphics! Do they stabilize? I'm guessing not.

 - Tim
Logged
Timeroot
Fractal Fertilizer
*****
Posts: 362


The pwnge.


WWW
« Reply #8 on: March 27, 2010, 07:34:11 AM »

^necro

I was looking back over this, and I'm not satisfied with the definition of mod. mod(z,a)=mod(abs(z),a)*sign(z) doesn't even hold for real negative values. If you want something along these lines, the best definitions would be:

mod(z,a)=mod(abs(z),a)
mod(z,a)=mod(abs(z),a)*sign(z) - (sign(z)-1)/2

I think maybe the most correct version, extended more or less analytically, uses Fourier series. The Fourier series for z mod 2pi is:

pi - 2(sin(z)/1 + sin(2z)/2 + sin(3z)/3 ...)

To convert to another mod, we use the simple formula mod(z,a)=mod(z*2*pi/a,2*pi)*a/(2*pi) - at least, I think that's it, someone check my maths - and then we've got a complex definition of sine!  afro

Thoughts on this?
Logged

Someday, man will understand primary theory; how every aspect of our universe has come about. Then we will describe all of physics, build a complete understanding of genetic engineering, catalog all planets, and find intelligent life. And then we'll just puzzle over fractals for eternity.
stigomaster
Guest
« Reply #9 on: March 27, 2010, 11:44:28 AM »

My mod function goes like this: First I convert to polar coordinates, and if the magnitude is greater than a given value I subtract that value from the magnitude until it is within the bounds. Then I convert back into cartesian and do another iteration. Thus, the angle remains the same. As far as I can see, this algorithm works for all complex numbers, even negative real numbers.
Logged
kram1032
Fractal Senior
******
Posts: 1863


« Reply #10 on: March 27, 2010, 11:48:23 AM »

How did you get that result, Timeroot? smiley
I mean, the fourier of z mod 2pi....


Wolfram Alpha can solve it smiley
the formula without that sum is:
\pi-i (\log(1-e^{i z})-\log(e^{-i z} (-1+e^{i z})))

if I put in your formula to get to a general mod, I get
a (i \log(1-e^{-{2 i \pi z\over a}}-i \log(1-e^{{2 i \pi z\over a}})+\pi)\over2 \pi

however, log()-log() can be rewritten as log( / ), if I'm not mistaken.
If you do this, the whole formula simplifys to
a (i log(-e^{-{2 i \pi z\over a}})+\pi)\over 2 \pi

Further simplifications can only be done if you assume a and z to be positive, according to Wolfram Alpha... in that case, the ultimatedly simplified formula would be:
a (\pi+i (i \pi-{2 i \pi z\over a})) \over 2 \pi

Nice other aproach but I don't see, how the definition given further above doesn't hold for negative values.
In case of z being real and negative, the definition simplifies to common mod just as usual...
« Last Edit: March 27, 2010, 12:04:00 PM by kram1032 » Logged
stigomaster
Guest
« Reply #11 on: March 27, 2010, 12:37:16 PM »

My approach was purely geometrical, I just got the idea of holding points back kind of like a mod function.
Logged
Timeroot
Fractal Fertilizer
*****
Posts: 362


The pwnge.


WWW
« Reply #12 on: March 27, 2010, 06:37:42 PM »

kram, when you're dealing with multivalued functions like log, simplifying sometimes doesn't always make it quite clear, what with different branches and all. I think it's perfectly fine to simplify further - W|A just couldn't tell the "history" at that step, so it didn't know what acceptable, exactly. If we take the other branch of log(z), with -i*pi instead of i*pi, we have:

\frac{a(\pi + i(- i \pi - \frac{2 i \pi z}{a}))}{2 \pi} = \frac{a (\pi - \pi + \frac{2 \pi z}{a}}{2 \pi} = \frac{2 \pi z}{2 pi} = z

This is correct, when you think that the log function can add or subtract 2 pi, in a sense, whenever it wants. I'm worried that your expression would not always give the right branch, especially if UF tried to simplify it or something wonky like that.

The reason mod(abs(z),a)*sign(z) doesn't work, shall be illustrated with an example: mod(-1.6,1). This should end up being 0.4, because the next smallest integer is -2, and -1.6 - (-2) = 0.4.

mod(abs(-1.6),1)*sign(-1.6) = mod(1.6,1)*-1 = -0.6

See? It's one less than it should be! For all negative numbers, it will be exactly one less than the correct value!  Azn
« Last Edit: March 27, 2010, 10:09:00 PM by Timeroot, Reason: Fixed maths. (See post below) » Logged

Someday, man will understand primary theory; how every aspect of our universe has come about. Then we will describe all of physics, build a complete understanding of genetic engineering, catalog all planets, and find intelligent life. And then we'll just puzzle over fractals for eternity.
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #13 on: March 27, 2010, 07:43:47 PM »

The reason mod(abs(z),a)*sign(z) doesn't work, shall be illustrated with an example: mod(-1.6,1). This should end up being 0.6, because the next smallest integer is -2, and -1.6 - (-2) = 0.6.

Last time I looked -1.6-(-2) was 0.4 smiley
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
Timeroot
Fractal Fertilizer
*****
Posts: 362


The pwnge.


WWW
« Reply #14 on: March 27, 2010, 10:09:22 PM »

^fixed. But in any case, do you see my point as to why it's wrong?
Logged

Someday, man will understand primary theory; how every aspect of our universe has come about. Then we will describe all of physics, build a complete understanding of genetic engineering, catalog all planets, and find intelligent life. And then we'll just puzzle over fractals for eternity.
Pages: [1] 2   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
The "operator" i is more complex than that! Complex Numbers « 1 2 3 4 » jehovajah 47 16309 Last post July 17, 2017, 06:30:05 AM
by jehovajah
Special "offset" and "rotate" options from Fractallab possible in M3d-formula? Mandelbulb 3d « 1 2 » SaMMy 18 27322 Last post April 05, 2011, 12:20:52 PM
by DarkBeam
"Analysis of a Complex Kind" course General Discussion slon_ru 0 1419 Last post July 11, 2013, 02:01:57 AM
by slon_ru
A "forgotten" theorem about complex numbers (new) Theories & Research hgjf2 3 534 Last post July 22, 2013, 04:24:32 PM
by kram1032

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.242 seconds with 24 queries. (Pretty URLs adds 0.026s, 2q)