C++Eigen库的配置和基本使⽤
1.配置
1.下载
2.配置
⽂件夹名字较长,解压后可重命名,如我命名为eigen3,把D:\program\eigen3添加到visual studio项⽬属性⾥的库⽬录即可。在程序头部包含
#include <Eigen/Den>
即可使⽤Eigen的各项功能了。
2.基本使⽤
// testEigen3.cpp : 定义控制台应⽤程序的⼊⼝点。
//
#include "stdafx.h"
#include <ios人民广场吃炸鸡
tream>
#include <Eigen/D歧视的意思
en>
using namespace Eige捅马蜂窝冯骥才
n;
using namespace std;
int m找团购
ain()
{
MatrixXf a(4, 1);//必须要进⾏初始化
a = MatrixXf::Zero(4, 1);//初始化为0
cout << "初始化为0" << endl << a << endl;
a = MatrixXf::Ones(4, 1);//初始化为1,矩阵⼤⼩与初始化相关,因为是动态矩阵
cout << "初始化为1" << endl <<关于母爱
a << endl;
a.tZero();//矩阵置零
a << 1, 2, 3, 4;//⼿动赋值
MatrixXf b(1, 4);
b.tRandom();//随机⽣成⼀个矩阵
MatrixXf c(3, 3);
c.tIdentity();
cout <死亡证明村委会怎么写
< "置单位矩阵:" << endl << c << endl;
c.tRandom()十二月坊
;
MatrixXf d = c;
d = d.inver();
cout << "矩阵c:" << endl << c << endl;
cout << "矩阵a:" << endl << a << endl;
cout << "矩阵b:" << b << endl;
cout << "访问a(0):" << endl << a(0) << endl;
cout << "矩阵相乘:" << endl << a*b << endl;
cout << "矩阵数乘:" << endl << 2 * a &lri过去式
t;< endl;
cout << "矩阵c求逆d:" << endl << d << endl;
cout << "逆矩阵回乘:" << endl << d*c << endl;
cout << "逆矩阵d转置:" << endl << d.transpo() << endl;
Vector3d v(1, 2, 3);
Vector3d w(1, 0, 0);
cout << "向量相加:" << endl << v + w << endl;
return 0;
}
运⾏结果