File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to solve the problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to solve the problem?" Watch "How to solve the problem?" New topic

How to solve the problem?


Joined: Sep 04, 2001
Posts: 7
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.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Anytime I need a set number of iterations for anything, I use a for loop.
Matthew Phillips

Matthew Phillips
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
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,
Peter Tran

Joined: Jan 02, 2001
Posts: 783
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.

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

Joined: Jan 27, 2001
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"

Joined: Sep 29, 2000
Posts: 8521
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).

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: How to solve the problem?
It's not a secret anymore!