KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > util > VectorToolkit


1 package JSci.util;
2
3 import JSci.maths.Complex;
4 import JSci.maths.vectors.*;
5
6 /**
7 * This is a useful collection of vector related methods.
8 * @author Mark Hale
9 */

10 public final class VectorToolkit {
11         private VectorToolkit() {}
12
13         /**
14         * Creates a random generated vector.
15         */

16         public static AbstractDoubleVector randomVector(int size) {
17                 return new DoubleVector(size).mapComponents(RandomMap.MAP);
18         }
19         /**
20         * Creates a random generated vector.
21         */

22         public static AbstractComplexVector randomComplexVector(int size) {
23                 return new ComplexVector(size).mapComponents(RandomMap.MAP);
24         }
25         /**
26         * Converts a vector to an array.
27         */

28         public static double[] toArray(AbstractDoubleVector v) {
29                 double array[]=new double[v.dimension()];
30                 array[0]=v.getComponent(0);
31                 for(int i=1;i<array.length;i++)
32                         array[i]=v.getComponent(i);
33                 return array;
34         }
35         /**
36         * Converts a vector to an array.
37         */

38         public static Complex[] toArray(AbstractComplexVector v) {
39                 Complex array[]=new Complex[v.dimension()];
40                 array[0]=v.getComponent(0);
41                 for(int i=1;i<array.length;i++)
42                         array[i]=v.getComponent(i);
43                 return array;
44         }
45 }
46
Popular Tags