First develop commit. Adding all existing files.
This commit is contained in:
40
test/math/Eigenvalues.java
Normal file
40
test/math/Eigenvalues.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package math;
|
||||
|
||||
import math.matrix.EigenvalueDecomposition;
|
||||
import math.matrix.Matrix;
|
||||
import exception.IllegalDimensionException;
|
||||
|
||||
/**
|
||||
* Test client for computing eigenvalues and eigenvectors of a real
|
||||
* symmetric matrix A = V D V^T.
|
||||
*/
|
||||
public class Eigenvalues {
|
||||
public static void main(String[] args) throws IllegalDimensionException {
|
||||
int N = 5;
|
||||
|
||||
// create a symmetric positive definite matrix
|
||||
Matrix A = Matrix.random(N, N);
|
||||
A = A.transpose().times(A);
|
||||
|
||||
// compute the spectral decomposition
|
||||
EigenvalueDecomposition e = A.eig();
|
||||
Matrix V = e.getV();
|
||||
Matrix D = e.getD();
|
||||
|
||||
System.out.print("A =");
|
||||
A.print(9, 6);
|
||||
System.out.print("D =");
|
||||
D.print(9, 6);
|
||||
System.out.print("V =");
|
||||
V.print(9, 6);
|
||||
|
||||
// check that V is orthogonal
|
||||
System.out.print("||V * V^T - I|| = ");
|
||||
System.out.println(V.times(V.transpose()).minus(Matrix.identity(N, N)).normInf());
|
||||
|
||||
// check that A V = D V
|
||||
System.out.print("||AV - DV|| = ");
|
||||
System.out.println(A.times(V).minus(V.times(D)).normInf());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user