Make the SVD's output unitary and improved unit tests.

This commit is contained in:
Hauke Heibel
2010-09-24 16:28:20 +02:00
parent 1c54514bfc
commit 053261de88
2 changed files with 19 additions and 6 deletions

View File

@@ -445,6 +445,19 @@ SVD<MatrixType>& SVD<MatrixType>::compute(const MatrixType& matrix)
m_matU.leftCols(n) = A;
m_matU.rightCols(m-n).setZero();
// Gram Schmidt orthogonalization to fill up U
for (int col = A.cols(); col < A.rows(); ++col)
{
typename MatrixUType::ColXpr colVec = m_matU.col(col);
colVec(col) = 1;
for (int prevCol = 0; prevCol < col; ++prevCol)
{
typename MatrixUType::ColXpr prevColVec = m_matU.col(prevCol);
colVec -= colVec.dot(prevColVec)*prevColVec;
}
m_matU.col(col) = colVec.normalized();
}
m_isInitialized = true;
return *this;
}