c++计算eigen随笔(2)

矩阵与 矩阵加法

 #include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
using namespace std;
int main()
{
MatrixXd m(3,3);
  m(0,0) = 10;
  m(0,1) = 20;
  m(0,2) = 120;
  m(1,0) = 30;
  m(1,1) =  40;
  m(1,2) = 340;
  m(2,0) = 50;
  m(2,1)= 60;
  m(2,2)= 560;
  cout << "m =" << endl << m << endl;
  auto v=MatrixXd::Constant(3,3,1000);
 cout << "v =" << endl << v << endl;
  cout << "m + v =" << endl << m+v << endl;
}
m =
 10  20 120
 30  40 340
 50  60 560
v =
1000 1000 1000
1000 1000 1000
1000 1000 1000
m + v =
1010 1020 1120
1030 1040 1340
1050 1060 1560

矩阵与向量乘法

#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
using namespace std;
int main()
{
  MatrixXd m = MatrixXd::Random(3,3);
  m = (m + MatrixXd::Constant(3,3,1.2)) * 50;
  cout << "m =" << endl << m << endl;
  VectorXd v(3);
  v << 1, 2, 3;
  cout << "m * v =" << endl << m * v << endl;
}
m =
10.0008  55.865 14.7045
23.1538 63.2767 77.8865
85.5605 31.8959 77.9296
m * v =
165.844
383.367
383.141
发布了385 篇原创文章 · 获赞 13 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/AI_LX/article/details/104239571