01: package JSci.tests;
02:
03: import JSci.maths.*;
04: import JSci.maths.matrices.*;
05: import JSci.maths.vectors.AbstractDoubleVector;
06: import JSci.maths.vectors.DoubleVector;
07: import JSci.util.MatrixToolkit;
08:
09: /**
10: * Testcase for double eigenvalue/vector methods.
11: * @author Mark Hale
12: */
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:
23: public DoubleMatrixEigenTest(String name) {
24: super (name);
25: }
26:
27: protected void setUp() {
28: JSci.GlobalSettings.ZERO_TOL = 1.0e-6;
29: sqmat = MatrixToolkit.randomSquareMatrix(N);
30: sqmat = (DoubleSquareMatrix) sqmat.add(sqmat.transpose()); // make symmetric
31: eval = new double[N];
32: evec = new DoubleVector[N];
33: try {
34: eval = LinearMath.eigenSolveSymmetric(sqmat, evec);
35: } catch (MaximumIterationsExceededException e) {
36: fail(e.toString());
37: }
38: }
39:
40: public void testEigenvectors() {
41: for (int i = 0; i < N; i++)
42: assertEquals(sqmat.multiply(evec[i]), evec[i]
43: .scalarMultiply(eval[i]));
44: }
45:
46: public void testTrace() {
47: double tr = 0.0;
48: for (int i = 0; i < N; i++)
49: tr += eval[i];
50: assertEquals(sqmat.trace(), tr, JSci.GlobalSettings.ZERO_TOL);
51: }
52:
53: public void testDet() {
54: double det = 1.0;
55: for (int i = 0; i < N; i++)
56: det *= eval[i];
57: assertEquals(sqmat.det(), det, JSci.GlobalSettings.ZERO_TOL);
58: }
59: }
|