KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > chaos > MandelbrotMap


1 package JSci.maths.chaos;
2
3 import JSci.maths.*;
4
5 /**
6 * The MandelbrotMap class provides an object that encapsulates the Mandelbrot map.
7 * z<sub>n+1</sub> = z<sub>n</sub><sup>2</sup> + c.
8 * @version 1.0
9 * @author Mark Hale
10 */

11 public final class MandelbrotMap extends Object JavaDoc implements ComplexMapping {
12         /**
13         * A complex number z such that |z| &gt; CONVERGENT_BOUND
14         * will diverge under this map.
15         */

16         public final static double CONVERGENT_BOUND=2.0;
17         private Complex a;
18         /**
19         * Constructs a Mandelbrot map.
20         * @param aval the value of the constant.
21         */

22         public MandelbrotMap(double aval) {
23                 a=new Complex(aval,0.0);
24         }
25         /**
26         * Constructs a Mandelbrot map.
27         * @param aval the value of the constant.
28         */

29         public MandelbrotMap(Complex aval) {
30                 a=aval;
31         }
32         /**
33         * Returns the constant.
34         */

35         public Complex getConstant() {
36                 return a;
37         }
38         /**
39         * Sets the constant.
40         */

41         public void setConstant(Complex aval) {
42                 a=aval;
43         }
44         /**
45         * Performs the mapping.
46         * @param x a double
47         */

48         public double map(double x) {
49                 return x*x+a.real();
50         }
51         /**
52         * Performs the mapping.
53         * @param z a complex number.
54         */

55         public Complex map(Complex z) {
56                 return map(z.real(),z.imag());
57         }
58         /**
59         * Performs the mapping.
60         */

61         public Complex map(double real,double imag) {
62                 return new Complex(real*real-imag*imag+a.real(),2.0*real*imag+a.imag());
63         }
64         /**
65         * Iterates the map.
66         * @param n the number of iterations
67         * @param x the initial value
68         */

69         public double iterate(int n,double x) {
70                 for(int i=0;i<n;i++)
71                         x=map(x);
72                 return x;
73         }
74         /**
75         * Iterates the map.
76         * @param n the number of iterations
77         * @param z the initial value
78         */

79         public Complex iterate(int n,Complex z) {
80                 for(int i=0;i<n;i++)
81                         z=map(z);
82                 return z;
83         }
84 }
85
86
Popular Tags