base
Matrix.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Eigenvalues>
4 
5 namespace base {
6 
11 template <typename _MatrixType>
12 static typename _MatrixType::PlainObject guaranteeSPD (const _MatrixType &A, const typename _MatrixType::RealScalar& minEig = 0.0)
13 {
14  typedef typename _MatrixType::PlainObject Matrix;
15  typedef Eigen::SelfAdjointEigenSolver<Matrix> EigenDecomp;
16  typedef typename EigenDecomp::RealVectorType EigenValues;
17 
18  // Eigenvalue decomposition
19  Eigen::SelfAdjointEigenSolver<Matrix> eigOfA (A, Eigen::ComputeEigenvectors);
20 
21  // truncate Eigenvalues:
22  EigenValues s = eigOfA.eigenvalues();
23  s = s.cwiseMax(minEig);
24 
25  // re-compose matrix:
26  Matrix spdA = eigOfA.eigenvectors() * s.asDiagonal() * eigOfA.eigenvectors().adjoint();
27 
28  return spdA;
29 };
30 
31 
32 
33 } // end namespace base
Definition: LinearAngular6DCommand.hpp:8