#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main() {
// 创建一个 2x2 的矩阵
MatrixXd m(2, 2);
m(0, 0) = 3;
m(0, 1) = 2.5;
m(1, 0) = -1;
m(1, 1) = m(0, 0) + m(0, 1);
std::cout << "Here is the matrix m:\n" << m << std::endl;
// 创建一个 2 维的向量
VectorXd v(2);
v(0) = 4;
v(1) = v(0) - 1;
std::cout << "Here is the vector v:\n" << v << std::endl;
// 矩阵和向量相乘
VectorXd result = m * v;
std::cout << "Here is the result of m * v:\n" << result << std::endl;
return 0;
}
#include <Eigen/Dense> 引入了 Eigen 库中用于处理稠密矩阵和向量的类。MatrixXd 创建了一个 2x2 的动态矩阵,并对其元素进行了赋值。VectorXd 创建了一个 2 维的动态向量,并对其元素进行了赋值。m * v 实现了矩阵与向量的乘法运算,并将结果存储在 result 中。std::cout 输出矩阵、向量以及它们的乘积结果。这个例子展示了如何使用 Eigen 库进行基本的矩阵和向量操作。
上一篇:c++reverse函数
下一篇:c++ orm
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站