KickJava   Java API By Example, From Geeks To Geeks.

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


1 package JSci.maths.chaos;
2
3 import JSci.maths.*;
4
5 /**
6 * The CatMap class provides an object that encapsulates the cat map.
7 * x<sub>n+1</sub> = (x<sub>n</sub> + y<sub>n</sub>) mod 1
8 * y<sub>n+1</sub> = (x<sub>n</sub> + 2y<sub>n</sub>) mod 1
9 * (Arnol'd).
10 * @version 1.0
11 * @author Mark Hale
12 */

13 public final class CatMap extends Object JavaDoc implements MappingND {
14         /**
15         * Constructs a cat map.
16         */

17         public CatMap() {}
18         /**
19         * Performs the mapping.
20         * @param x a 2-D double array
21         * @return a 2-D double array
22         */

23         public double[] map(double x[]) {
24                 double ans[]=new double[2];
25                 ans[0]=(x[0]+x[1])%1;
26                 ans[1]=(x[0]+2*x[1])%1;
27                 return ans;
28         }
29         /**
30         * Iterates the map.
31         * @param n the number of iterations
32         * @param x the initial values (2-D)
33         * @return a 2-D double array
34         */

35         public double[] iterate(int n,double x[]) {
36                 double xn[]=map(x);
37                 for(int i=1;i<n;i++)
38                         xn=map(xn);
39                 return xn;
40         }
41 }
42
43
Popular Tags