Mandelbrot Set

Mike Shn
Ranch Hand
Posts: 149
Hello
Would someone give me a good solution to the problem?
I have wrote the Mandelbrot class
class Mandelbrot {
public static void main (String[] arguments)
{

// Local Declaration
double cu = -0.1155989; // real part
double cv = 0.7639405; // imaginary part
double zu = 0.0; // real part
double zv = 0.0; // imaginary part

System.out.println("C= " + cu + " + " + cv + "i");
System.out.println("Z0= " + zu + " + " + zv + "i");

for(int i = 0; i <= 100; i++) {
double newu = 2 *(zu * zu) - zv * zv;
double newv = 2 * zv * zv;
newu +=cu;
newv +=cv;
zu = newu;
zv = newv;
System.out.println("z" + i + " = " + zu + " + " + zv + "i");
}

}
}
But how to modify I don't know.
Write a program that reads c and the number of generations from the command line, and prints that many iterations of the Mandelbrot equation. Also print (at the beginning of the output) the value used for c.
Be sure to handle all user errors (e.g. not providing two values on the command line) to the extent possible. Check the ranges of the data the user enters (e.g. don't let the number of generations be less than 0). Print an error message and exit if a value outside the allowed range is entered. Provide a default value if none is given.
Detect if divergence has occurred (absolute value greater than 2) and stop output if so. Note that this test does not require you to know about or use any square root, power, exponent, or other mathematical functions that Java may or may not have.
c (e.g. -0.2 + 0.8i) and Mandelbrot equation is The Mandelbrot Set is defined by a simple iterative function:
zt+1 = zt2 + c
z0 = 0

Thanks

Kris Nelson
Ranch Hand
Posts: 35
The Mandelbrot Set, eh?
Sounds like a nasty homework assignment from back in college. The Mandelbrot Set is a beautiful thing if you can get it to do what you want it to.
I actually developed an applet of The Mandelbrot Set if you or anybody else wanted to try it out ( http://www.webnelly.com/applets/mandelbrot.jsp ).
Note: You need the JRE 1.3.1 plug-in from Sun for your browser for this applet.
I'll try and put up some of the code soon. It's fun to struggle with it for awhile.
------------------
WebNelly.com
Java/XML Web Development
Check it out! http://www.webnelly.com
[This message has been edited by Kris Nelson (edited November 07, 2001).]

Mike Shn
Ranch Hand
Posts: 149
Hi
Would you show the code for me please? I'll promise that I will not copy it, I just want a look...
serious
Thanks

Matthew Margolis
Ranch Hand
Posts: 32
could you tell us a bit more about what exactly you are having trouble with? It would be easier to answer your questions and in the end better for you if we could offer some help and you come to the right conclusion. You can only learn if you try...

Kris Nelson
Ranch Hand
Posts: 35
Sorry Mike,
My applet calculates the number of escapes for each X and Y coordinate in the grid. Therefore, the algorithm I used wouldn't be much use to you.
Also, Matthew has a point. Everyone here will be glad to offer any assistance. You need to break down the problem down into parts. Based on your "specs" I recommend the following:
*** Hard code a value for c and the number of iterations as opposed to getting it from the command line (which you have already done). You can worry about the validation and the rest once you know that your output is correct.
*** Test the values that you have hard-coded. Your code seems to run fine, although I suggest knocking down the for loop from 100 to only 10. If you use a value for c that you know the first couple of iterations for, then you can see if the output is correct. If possible, you should test it with at least two different values for c.
*** Then worry about the rest.
Does the code you have posted (or are working on) currently give you the correct output based on the hard coded values?

------------------
WebNelly.com
Java/XML Web Development
Check it out!
http://www.webnelly.com

Mike Shn
Ranch Hand
Posts: 149
Hi
Finally I wrote the code , but it gives some errors. Would you look a the problem please?

MandelbrotUtilities.java:37: cannot resolve symbol
symbol : method abs ()
location: class ComplexNumber
ad[j] = returnNthIteration( complexnumber1, j ).abs();
^
2 errors

Thanks a lot
[This message has been edited by Cindy Glass (edited November 08, 2001).]

Kris Nelson
Ranch Hand
Posts: 35
Mike,
It's a start, but we need the code for your ComplexNumber class that this class extends. The one compiler error you listed refers to the abs() method in the ComplexNumber class, so we need more code.

------------------
WebNelly.com
Java/XML Web Development
Check it out!
http://www.webnelly.com

Colin Kenworthy
Ranch Hand
Posts: 88
The message seems to imply that a method named abs() in the ComplexNumber class (or a superclass) does not exist. Maybe you called it Abs() or ABS() - remember java is case sensitive.
I also think in your first code example for class Mandelbrot:
double newu = 2 *(zu * zu) - zv * zv;
double newv = 2 * zv * zv;
this could be wrong, you might actually mean:
double newu = (zu * zu) - (zv * zv);
double newv = 2 * zu * zv;
if you are simply squaring the complex number.
[This message has been edited by Colin Kenworthy (edited November 08, 2001).]