SVD svd = new SVD(A.numRows(), A.numColumns());
assertEquals(A, svd.factor(A.copy()));
}
private void assertEquals(Matrix A, SVD svd) {
TridiagMatrix S = new TridiagMatrix(svd.getS().length);
System.arraycopy(svd.getS(), 0, S.getDiagonal(), 0, svd.getS().length);
DenseMatrix U = svd.getU();
DenseMatrix Vt = svd.getVt();
// Compute U*S*Vt
Matrix s = U.mult(S.mult(Vt, new DenseMatrix(S.numRows(), Vt
.numColumns())), new DenseMatrix(A.numRows(), A.numColumns()));
// Check that A=U*S*Vt
for (int i = 0; i < A.numRows(); ++i)
for (int j = 0; j < A.numColumns(); ++j)