KickJava   Java API By Example, From Geeks To Geeks.

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


1 package JSci.maths.chaos;
2
3 import JSci.maths.*;
4
5 /**
6 * The StandardMap class provides an object that encapsulates the Standard map.
7 * x<sub>n+1</sub> = (x<sub>n</sub> + y<sub>n+1</sub>) mod 2<img border=0 alt="pi" SRC="../doc-files/pi.gif">
8 * y<sub>n+1</sub> = (y<sub>n</sub> + k sin(x<sub>n</sub>)) mod 2<img border=0 alt="pi" SRC="../doc-files/pi.gif">
9 * (Chirikov, Taylor).
10 * @version 1.0
11 * @author Mark Hale
12 */

13 public final class StandardMap extends Object JavaDoc implements MappingND {
14         private final double k;
15         /**
16         * Constructs a Standard map.
17         * @param kval the value of the k parameter
18         */

19         public StandardMap(double kval) {
20                 k=kval;
21         }
22         /**
23         * Performs the mapping.
24         * @param x a 2-D double array
25         * @return a 2-D double array
26         */

27         public double[] map(double x[]) {
28                 double ans[]=new double[2];
29                 ans[1]=(x[1]+k*Math.sin(x[0]))%NumericalConstants.TWO_PI;
30                 ans[0]=(x[0]+ans[1])%NumericalConstants.TWO_PI;
31                 return ans;
32         }
33         /**
34         * Iterates the map.
35         * @param n the number of iterations
36         * @param x the initial values (2-D)
37         * @return a 2-D double array
38         */

39         public double[] iterate(int n,double x[]) {
40                 double xn[]=map(x);
41                 for(int i=1;i<n;i++)
42                         xn=map(xn);
43                 return xn;
44         }
45 }
46
47
Popular Tags