SVD分解的c++代碼(Eigen 庫)

 

使用Eigen 庫:進行svd分解,形如 A = U * S * VTios

JacobiSVD<MatrixXd> svd(J, ComputeThinU | ComputeThinV); spa

U = svd.matrixU();.net

V = svd.matrixV(); code

A = svd.singularValues();blog

 

 

 

Eigen::JacobiSVD< _Matrix_Type_ > svd(a ,Eigen::ComputeThinU | Eigen::ComputeThinV);

 

 

// EigenTest.cpp : 定義控制檯應用程序的入口點。 //  #include "stdafx.h" #include <iostream> #include <Eigen/SVD> #include <Eigen/Dense>    

//using Eigen::MatrixXf; 
using namespace Eigen; using namespace Eigen::internal; using namespace Eigen::Architecture; int main() { Matrix3f A; A(0,0)=1,A(0,1)=0,A(0,2)=1; A(1,0)=0,A(1,1)=1,A(1,2)=1; A(2,0)=0,A(2,1)=0,A(2,2)=0; JacobiSVD<Eigen::MatrixXf> svd(A, ComputeThinU | ComputeThinV ); Matrix3f V = svd.matrixV(), U = svd.matrixU(); Matrix3f S = U.inverse() * A * V.transpose().inverse(); // S = U^-1 * A * VT * -1 
    std::cout<<"A :\n"<<A<<std::endl; std::cout<<"U :\n"<<U<<std::endl; std::cout<<"S :\n"<<S<<std::endl; std::cout<<"V :\n"<<V<<std::endl; std::cout<<"U * S * VT :\n"<<U * S * V.transpose()<<std::endl; system("pause"); return 0; }

 

 

SVD分解 Eigen庫 opencv庫 - CSDN博客 https://blog.csdn.net/ouyangying123/article/details/68491414get

相關文章
相關標籤/搜索