博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++使用Eigen库计算矩阵特征值
阅读量:4098 次
发布时间:2019-05-25

本文共 1123 字,大约阅读时间需要 3 分钟。

是一个方便使用的c++矩阵运算库,只要包含Eigen的源码头文件,就能使用。
下面的例子是计算矩阵的特征值特征向量,并把特征向量矩阵实部和虚部分开。

#include 
#include
using namespace std;using namespace Eigen;int main(){ Matrix3d A; //定义3*3 double 型矩阵 A << 1, 2, 3, 5,-5,3,4,6,9; cout << "Here is a matrix, A:" << endl << A << endl << endl; EigenSolver
es(A); cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl; MatrixXcd vect = es.eigenvectors();//特征向量矩阵 cout << "复数形式输出:" << endl << vect << endl; MatrixXd realvect(vect.rows(), vect.cols()); MatrixXd imagvect(vect.rows(), vect.cols()); cout << "虚实拆分:" << endl; /*两种拆分方式等价 for (size_t i = 0; i < vect.rows(); i++) { for (size_t j = 0; j < vect.cols(); j++) { realvect(i, j) = real(vect(i, j)); imagvect(i, j) = imag(vect(i, j)); } }*/ for (size_t i = 0; i < vect.size(); i++) { *(realvect.data() + i) = real(*(vect.data() + i)); *(imagvect.data() + i) = imag(*(vect.data() + i)); } cout << "realvect:" << endl << realvect << endl; cout << "imagvect:" << endl << imagvect << endl;}

转载地址:http://yrqii.baihongyu.com/

你可能感兴趣的文章
MFC矩阵运算
查看>>
最小二乘法拟合:原理,python源码,C++源码
查看>>
ubuntu 安装mysql
查看>>
Win32编程绘图实例--字母图
查看>>
c# 计算器
查看>>
C# 简单的矩阵运算
查看>>
gcc 常用选项详解
查看>>
c++输入文件流ifstream用法详解
查看>>
c++输出文件流ofstream用法详解
查看>>
字符编码:ASCII,Unicode 和 UTF-8
查看>>
QT跨MinGW和MSVC两种编译器的解决办法
查看>>
firewalld的基本使用
查看>>
Linux下SVN客户端使用教程
查看>>
i2c-tools
查看>>
Linux分区方案
查看>>
nc 命令详解
查看>>
如何使用 systemd 中的定时器
查看>>
git命令速查表
查看>>
linux进程监控和自动重启的简单实现
查看>>
OpenFeign学习(三):OpenFeign配置生成代理对象
查看>>