Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eigen Library - Pseudo-Inverse of Matrix (Matlab - pinv)

I am trying to find the pseudo-inverse of a matrix using the Eigen Library. They have a class that does implement it, however I do not know how to put script the syntax.

This is how it is shown on the website (https://eigen.tuxfamily.org/dox/classEigen_1_1CompleteOrthogonalDecomposition.html#ab2fd4c81aa1cd8bc917c7f135505cb7f):

const Inverse Eigen::CompleteOrthogonalDecomposition< MatrixType >::pseudoInverse ( ) const

like image 593
Hisham Mohammad Avatar asked Dec 18 '22 06:12

Hisham Mohammad


1 Answers

It's a method of the CompleteOrthogonalDecomposition class. So you have to perform that decomposition of a matrix before you use it. For example

#include <Eigen/QR>    

Eigen::MatrixXd A = ... // fill in A
Eigen::MatrixXd pinv = A.completeOrthogonalDecomposition().pseudoInverse();
like image 88
Sean Avatar answered Dec 24 '22 01:12

Sean