SVD分解的c++代码(Eigen 库)

 

使用Eigen 库:进行svd分解,形如 A = U * S * VT

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

U = svd.matrixU();

V = svd.matrixV();

A = svd.singularValues();

 

 

 

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/68491414

 

posted @ 2018-04-20 17:51  ostartech  阅读(11717)  评论(0编辑  收藏  举报