1 package JSci.tests; 2 3 import JSci.maths.*; 4 import JSci.maths.matrices.*; 5 import JSci.maths.vectors.AbstractDoubleVector; 6 import JSci.maths.vectors.DoubleVector; 7 import JSci.util.MatrixToolkit; 8 9 13 public class DoubleMatrixEigenTest extends junit.framework.TestCase { 14 private final int N=5; 15 private AbstractDoubleSquareMatrix sqmat; 16 private double eval[]; 17 private AbstractDoubleVector evec[]; 18 19 public static void main(String arg[]) { 20 junit.textui.TestRunner.run(DoubleMatrixEigenTest.class); 21 } 22 public DoubleMatrixEigenTest(String name) { 23 super(name); 24 } 25 protected void setUp() { 26 JSci.GlobalSettings.ZERO_TOL=1.0e-6; 27 sqmat=MatrixToolkit.randomSquareMatrix(N); 28 sqmat=(DoubleSquareMatrix) sqmat.add(sqmat.transpose()); eval=new double[N]; 30 evec=new DoubleVector[N]; 31 try { 32 eval=LinearMath.eigenSolveSymmetric(sqmat,evec); 33 } catch(MaximumIterationsExceededException e) {fail(e.toString());} 34 } 35 public void testEigenvectors() { 36 for(int i=0;i<N;i++) 37 assertEquals(sqmat.multiply(evec[i]), evec[i].scalarMultiply(eval[i])); 38 } 39 public void testTrace() { 40 double tr=0.0; 41 for(int i=0;i<N;i++) 42 tr+=eval[i]; 43 assertEquals(sqmat.trace(), tr, JSci.GlobalSettings.ZERO_TOL); 44 } 45 public void testDet() { 46 double det=1.0; 47 for(int i=0;i<N;i++) 48 det*=eval[i]; 49 assertEquals(sqmat.det(), det, JSci.GlobalSettings.ZERO_TOL); 50 } 51 } 52 53 | Popular Tags |