玩命加载中 . . .

Eigen_矩阵属性


元素累加累乘

mat.sum()
mat.prod()

平均值

mat.mean()  

最值

mat.minCoeff()
mat.maxCoeff()

mat.trace()

对角元素

mat.diagonal()

特征值与特征向量

EigenSolver<Matrix3d> eigen_solver(mat);
eigen_solver.pseudoEigenvalueMatrix()
// 特征值排成矩阵形式
eigen_solver.pseudoEigenvectors()
// 每一列是一个特征向量

代码示例

#include <iostream>
#include <cstring>
#include "Eigen/Dense"
using namespace std;
using namespace Eigen;
int main()
{
    Matrix2d mat;
    mat << 1, 2,
    3, 4;
    cout << "Here is mat.sum():       " << mat.sum()       << endl;
    cout << "Here is mat.prod():      " << mat.prod()      << endl;
    cout << "Here is mat.mean():      " << mat.mean()      << endl;
    cout << "Here is mat.minCoeff():  " << mat.minCoeff()  << endl;
    cout << "Here is mat.maxCoeff():  " << mat.maxCoeff()  << endl;
    cout << "Here is mat.trace():     " << mat.trace()     << endl;

    // Here is mat.sum():       10
    // Here is mat.prod():      24
    // Here is mat.mean():      2.5
    // Here is mat.minCoeff():  1
    // Here is mat.maxCoeff():  4
    // Here is mat.trace():     5

    Matrix3d mat;
	mat << 1, 2, 4,
           3, 4, 5,
           9, 8, 7;
	cout << mat.diagonal() << endl;
    // 1
    // 4
    // 7

    cout << mat.eigenvalues() << endl;
    // (14.8426,0)
    // (-3.10313,0)
    // (0.260538,0)

	EigenSolver<Matrix3d> eigen_solver(mat);
	MatrixXd eig_value = eigen_solver.pseudoEigenvalueMatrix();
	
	cout << "matrix values = \n" << eig_value << endl;
    // matrix values =
    // 14.8426        0        0
    //     0   -3.10313        0
    //     0        0   0.260538

	MatrixXd eig_vector = eigen_solver.pseudoEigenvectors();
	cout << "matrix vectors = \n" << eig_vector << endl;
    // matrix vectors =
    // -0.307083 -0.629353  0.493782
    // -0.467283 -0.291072 -0.826916
    // -0.829064  0.791116  0.322174
}

文章作者: kunpeng
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 kunpeng !
  目录