1 package JSci.util; 2 3 import JSci.maths.Complex; 4 import JSci.maths.matrices.*; 5 6 10 public final class MatrixToolkit { 11 private MatrixToolkit() {} 12 13 16 public static DoubleSquareMatrix randomSquareMatrix(int size) { 17 return (DoubleSquareMatrix)new DoubleSquareMatrix(size).mapElements(RandomMap.MAP); 18 } 19 22 public static DoubleTridiagonalMatrix randomTridiagonalMatrix(int size) { 23 return new DoubleTridiagonalMatrix(toArray(randomSquareMatrix(size))); 24 } 25 28 public static DoubleDiagonalMatrix randomDiagonalMatrix(int size) { 29 return new DoubleDiagonalMatrix(toArray(randomSquareMatrix(size))); 30 } 31 32 35 public static ComplexSquareMatrix randomComplexSquareMatrix(int size) { 36 return (ComplexSquareMatrix)new ComplexSquareMatrix(size).mapElements(RandomMap.MAP); 37 } 38 41 public static ComplexTridiagonalMatrix randomComplexTridiagonalMatrix(int size) { 42 return new ComplexTridiagonalMatrix(toArray(randomComplexSquareMatrix(size))); 43 } 44 47 public static ComplexDiagonalMatrix randomComplexDiagonalMatrix(int size) { 48 return new ComplexDiagonalMatrix(toArray(randomComplexSquareMatrix(size))); 49 } 50 51 54 public static double[][] toArray(AbstractDoubleMatrix v) { 55 double array[][]=new double[v.rows()][v.columns()]; 56 for(int j,i=0;i<array.length;i++) { 57 for(j=0;j<array[0].length;j++) 58 array[i][j]=v.getElement(i,j); 59 } 60 return array; 61 } 62 65 public static Complex[][] toArray(AbstractComplexMatrix v) { 66 Complex array[][]=new Complex[v.rows()][v.columns()]; 67 for(int j,i=0;i<array.length;i++) { 68 for(j=0;j<array[0].length;j++) 69 array[i][j]=v.getElement(i,j); 70 } 71 return array; 72 } 73 } 74 | Popular Tags |