Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to solve the problem?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anytime I need a set number of iterations for anything, I use a for loop.
Matthew Phillips
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 = Z2 + 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
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Peter I found a link to Java2HTML Tool via the url you gave for the Colt library. Man I can use that baby
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic