aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to solve the problem?" Watch "How to solve the problem?" New topic
Author

How to solve the problem?

Mike_Shn
Greenhorn

Joined: Sep 04, 2001
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

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,
Art
Peter Tran
Bartender

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

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"
Sheriff

Joined: Sep 29, 2000
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

"JavaRanch, where the deer and the Certified play" - David O'Meara
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to solve the problem?