step1 下载Eigen库
step2 在clion中Cmake包含Eigen文件夹
cmake_minimum_required(VERSION 3.17)
project(untitled)
set(CMAKE_CXX_STANDARD 11)
include_directories("F://eigen")
add_executable(untitled main.cpp)
step3 利用奇异值分解求矩阵的秩
#include <iostream>
#include <Eigen/SVD>
#include <Eigen/Dense>
using namespace Eigen;
int main()
{
Matrix<double,4,4> A;
A<<1,2,3,4,
0,2,3,4,
0,0,3,4,
0,0,0,0;
JacobiSVD<Eigen::MatrixXd> svd(A);
std::cout<<"A :\n"<<A<<std::endl;
std::cout<<"rank:\n"<<svd.rank()<<std::endl;
return 0;