Logo by reallybigname - 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: Did you know ? you can use LaTex inside Postings on fractalforums.com!
 
*
Welcome, Guest. Please login or register. April 25, 2024, 07:51:48 AM


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]   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: Java Mandelbrot segment  (Read 2044 times)
0 Members and 1 Guest are viewing this topic.
fractalwizz
Conqueror
*******
Posts: 129



WWW
« on: November 24, 2008, 08:42:57 PM »

This is the code I was given to generate the mandelbrot.
How would I edit it to produce other exponents of the set?
Code:
private boolean escapesToInfinity(double a, double b) {
        double x = 0;
        double y = 0;
        int iterations = 0;
        do {
            double xnew = x * x - y * y + a;
            double ynew = 2 * x * y + b;
            x = xnew;
            y = ynew;
            iterations++;
            if (iterations == MAX_ITERATIONS) {
                return false;
            }
        } while (x <= 2 && y <= 2);
        return true;
    }

Logged

cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #1 on: November 25, 2008, 01:48:07 AM »

if you want integer powers, the
 double xnew = x * x - y * y + a;
 double ynew = 2 * x * y + b;
without the +a , +b parts, is the complex square, if you repeat this, you get z^4, z^6 and so on

 double xnew = x * x - y * y ;
 double ynew = 2 * x * y ;

... and add a nd b afterwards

 double xnew = xnew+a ;
 double ynew = ynew + b ;

 afro
Logged

---

divide and conquer - iterate and rule - chaos is No random!
fractalwizz
Conqueror
*******
Posts: 129



WWW
« Reply #2 on: November 25, 2008, 03:31:11 AM »

So, how would that look like in the end code wise?
Logged

cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #3 on: November 25, 2008, 10:16:00 AM »

try this: (far from perfect )
Code:

// power=1 -> z^2
// power=2 -> z^4 ...
private boolean escapesToInfinity(double a, double b, int power) {
        double x = 0;
        double y = 0;
        int iterations = 0;
        do {

           for(int i =0;i<power;i++)
            {
              double xnew = x * x - y * y ;
              double ynew = 2 * x * y ;
              x = xnew;
              y = ynew;
            }
            // Finally add the seed
            x=x+a;
            y=y+b;

            // Continue with iteration
            iterations++;
            if (iterations == MAX_ITERATIONS) {
                return false;
            }
        } while (x <= 2 && y <= 2);
        return true;
    }

Logged

---

divide and conquer - iterate and rule - chaos is No random!
Duncan C
Fractal Fanatic
****
Posts: 348



WWW
« Reply #4 on: December 20, 2008, 04:53:26 AM »

This is the code I was given to generate the mandelbrot. <snip>
How would I edit it to produce other exponents of the set?


For Z3, here's what I get: (somebody check me, I'm tired)
Code:
private boolean escapesToInfinity(double a, double b) {
        double x = 0;
        double y = 0;
        int iterations = 0;
        do {
            double xnew = x*x*x - y*y*x - 2*x*y*y + a;
            double ynew = 2*x*x*y + x*x*y - y*y*y + b;
            x = xnew;
            y = ynew;
            iterations++;
            if (iterations == MAX_ITERATIONS) {
                return false;
            }
        } while (x <= 2 && y <= 2);
        return true;
    }

You have to figure the odd powers by hand, working out the algebra with complex numbers. Z can also be written as the complex number (x+bi). What I did to find Z3 was to write out (x+yi) (x+yi) (x+yi). First I multiplied (x+yi)(x+yi), and got the Z2 result. I then multiplied my Z2 (in long form) by another (x+yi)

Every time you calculate i*i, the i turns to -1.

So,
   Z2 becomes
   (x+yi)(x+yi) becomes
   x2 + 2xyi - y2

I then multiply THAT by (x+yi):

  (x2 + 2xyi - y2) (x+yi) becomes

  x3 + 2x2yi - y2x + x2yi - 2xy2 - y3i

Any term in the above without an i in it gets added to xnew (the real part of the new Z value), and any term with an i in it gets added to ynew (the imaginary part of the new z value.)

That means

   xnew = x3 - y2x - 2xy2
   ynew = 2x2y + x2y - y3

Finally, we add in our c, which this code represents as a+bi, so we get

   xnew = x3 - y2x - 2xy2 + a
   ynew = 2x2y + x2y - y3 + b

Most programming languages don't have a clean notation for integer powers that's also efficient, so you just write them as repeated multiplications. Thus, the final form becomes what I put in the code block above:


   xnew = x*x*x - y*y*x - 2xy*y + a
   ynew = 2x*x*y + x*x*y - y*y*y + b


I hope that makes sense.


Regards,

Duncan
Logged

Regards,

Duncan C
fractalwizz
Conqueror
*******
Posts: 129



WWW
« Reply #5 on: December 20, 2008, 02:08:49 PM »

It works. Thanks.
Logged

Duncan C
Fractal Fanatic
****
Posts: 348



WWW
« Reply #6 on: December 25, 2008, 02:54:06 AM »

It works. Thanks.

Which one did you try? Trifox's even power code, or my Z3?

I'd have to figure out Z5 for you, but I don't have time right now.


Duncan C
Logged

Regards,

Duncan C
fractalwizz
Conqueror
*******
Posts: 129



WWW
« Reply #7 on: December 25, 2008, 05:15:00 PM »

I have tried both and they work
Logged

cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #8 on: December 26, 2008, 08:24:43 PM »

cheesy

but now you shouldf think about implementing rational powers, e.g. z^2.5
or even complex powers cheesy
this is done via the polar view of complex numbers....

 i have to search
out the formula, and can post it here fort you ...
Logged

---

divide and conquer - iterate and rule - chaos is No random!
HPDZ
Iterator
*
Posts: 157


WWW
« Reply #9 on: December 29, 2008, 06:58:52 PM »

Here's how to raise a complex number to the power of another complex number. It's a fair amount of calculation:

First let us write

Z = a + bi
Y = c + di

We want Z to the power of Y

ZY = (a2+b2)Y/2e(iY Arg(Z))

where

Arg(Z) = the argument (polar angle) of Z = arctan(b/a)

To expand this all out to its real and imaginary parts explicitly:

First calculate u = c arg(Z) + (d ln(a2+b2))/2

Then ZY = (a2+b2)c/2 e(-d arg(Z)) [cos(u) + i sin(u)]

If you set d=0 you get the formula for raising a complex number Z to an arbitrary real-valued exponent c:

Zc = (a2+b2)c/2 {cos[c Arg(Z)] + i sin[c Arg(Z)]}
Logged

Zoom deeply.
www.hpdz.net
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #10 on: December 29, 2008, 08:01:24 PM »

thank you, good explanation!
Logged

---

divide and conquer - iterate and rule - chaos is No random!
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Java applet for exploring the Mandelbrot set Announcements & News Paton 5 7128 Last post March 26, 2007, 06:03:34 PM
by Paton
[URGENT] Somebody can help me develope fractal using java? Let's collaborate on something! maknyosss 1 744 Last post June 20, 2009, 04:18:34 PM
by David Makin
SuperFractalThing: Arbitrary precision mandelbrot set rendering in Java. Announcements & News « 1 2 ... 16 17 » mrflay 252 102859 Last post August 17, 2016, 11:59:31 PM
by cKleinhuis
Is JAVA safe to use now? General Discussion chaos_crystal 14 7748 Last post December 10, 2013, 11:39:25 PM
by Mrz00m
*Continued* SuperFractalThing: Arbitrary precision mandelbrot set rendering in Java. Announcements & News « 1 2 ... 23 24 » hapf 347 50933 Last post September 28, 2017, 10:20:19 PM
by claude

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.225 seconds with 25 queries. (Pretty URLs adds 0.013s, 2q)