【Linux/Eigen】学习笔记(2):矩阵创建方法

在重构机器人算法时,Eigen库应该是使用率最多的库了,因为机器人的算法涉及到大量的矩阵运算。

首先说一下创建3×3的矩阵的方法,作为初学者我比较关心的是声明和赋值,用以下三种方式说明:

#include <iostream>
#include <Eigen/Dense>
using namespace std;
int main()
{
    // 声明和赋值 方法1
    Eigen::Matrix3d mat3d1;
    mat3d1 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
    cout << "method1:" << endl;
    cout << mat3d1 << endl;
    // 声明和赋值 方法2
    Eigen::Matrix<double, 3, 3> mat3d2;
    mat3d2 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
    cout << "method2:" << endl;
    cout << mat3d2 << endl;
    // 声明和赋值 方法3
    Eigen::Matrix<double, 3, 3> mat3d3;
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            mat3d3(i, j) = 100;
    cout << "method3:" << endl;
    cout << mat3d3 << endl;
    return 1;
}

上述代码的运行结果:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值