# How to solve the problem?

Mike_Shn
Greenhorn
Posts: 7
Hello
Does anybody know how to solve the problem in Java?
write a program that has 100 iterations of the mandelbrot equation for a fixed value of c(eg. -0.2 +0.8i) also print at the beggining value of c.
Thanks

Matthew Phillips
Ranch Hand
Posts: 2676
Anytime I need a set number of iterations for anything, I use a for loop.
Matthew Phillips

Art Metzer
Ranch Hand
Posts: 241
Not knowing what the Mandelbrot equation was, I did a Google search and landed here.
So you have to generate iterations of complex numbers based on the Mandelbrot equation, Z = Z<sup>2</sup> + C.
What I would do is define a class, ComplexNumber. It would have two instance variables (real and imaginary), a constructor that you would define, and methods like:
public double magnitude() {...}
public ComplexNumber add( ComplexNumber c ) {...}
public ComplexNumber multiply( ComplexNumber c ) {...}
public ComplexNumber squared() {...}
public String toString() {...}
public boolean isReal() {...}
Stuff like that. Then I would write a separate driver class to do your dirty work here. Something like
ComplexNumber constant = new ComplexNumber( -0.2, 0.8 );
ComplexNumber z = new ComplexNumber( 0.0, 0.0 );
for ( int i = 0; i < 100; ++i ) {
z = ( z.squared() ).add( constant );
System.out.println( z );
}
My two cents' worth,
Art

Peter Tran
Bartender
Posts: 783
Art,
The nice thing about JAVA is that you probably don't have to reinvent the wheel. I would recommend using the Complex class that is part of the Colt library distribution.
The Colt library is a phenomenal set of code. You can learn a lot from studying the different design patterns used in the library. It's one of the best documented piece of software library I've ever used that's written by one person!
As a great example of what JavaDoc should look like, see the class summary for the cern.colt.matrix class.
If every programmer wrote Javadoc like this, the world would be a better place.
-Peter

[This message has been edited by Peter Tran (edited September 26, 2001).]

Johannes de Jong
tumbleweed
Bartender
Posts: 5089
Hey Peter I found a link to Java2HTML Tool via the url you gave for the Colt library. Man I can use that baby

Cindy Glass
"The Hood"
Sheriff
Posts: 8521
Mike_Shn,
Please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
You need to get rid of that underscore, and hopefully spell out your last name (I don't think that I can pronounce that - if it is REAL forgive me).
Thanks,
Cindy