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.
|
|
|
Logged
|
|
|
|
kram1032
|
|
« 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 I'll just put up some pics now, maybe I'll write some more later. Comments are fun!
|
|
|
Logged
|
|
|
|
kram1032
|
|
« Reply #3 on: December 16, 2009, 10:59:58 PM » |
|
which values did you use? What happens for mod(z,2)? nice wave patterns
|
|
|
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 I call this function at every iteration. 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; } 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).
|
|
|
|
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.
|
|
|
Logged
|
|
|
|
kram1032
|
|
« Reply #6 on: December 18, 2009, 04:47:02 PM » |
|
very psychedelic
|
|
|
Logged
|
|
|
|
TimGolden
Forums Freshman
Posts: 11
|
|
« 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
|
|
« 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! 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
|
|
« Reply #10 on: March 27, 2010, 11:48:23 AM » |
|
How did you get that result, Timeroot? I mean, the fourier of z mod 2pi.... Wolfram Alpha can solve it the formula without that sum is: if I put in your formula to get to a general mod, I get however, log()-log() can be rewritten as log( / ), if I'm not mistaken. If you do this, the whole formula simplifys to 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: 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
|
|
« 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: 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!
|
|
« 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
|
|
« 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
|
|
|
Logged
|
|
|
|
Timeroot
|
|
« 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.
|
|
|
|