Eigen 矩阵定义#include <Eigen/Dense>Matrix<double, 3, 3> A;               // Fixed rows and cols. Same as Matrix3d.Matrix<double, 3, Dynamic> B;         // Fixed rows, dynamic cols.Matrix<double, Dynamic, Dynamic> C;   // Full dynamic. Same as MatrixXd.Matrix<double, 3, 3, RowMajor> E;     // Row major; default is column-major.Matrix3f P, Q, R;                     // 3x3 float matrix.Vector3f x, y, z;                     // 3x1 float matrix.RowVector3f a, b, c;                  // 1x3 float matrix.VectorXd v;                           // Dynamic column vector of doubles// Eigen          // Matlab           // commentsx.size()          // length(x)        // vector sizeC.rows()          // size(C,1)        // number of rowsC.cols()          // size(C,2)        // number of columnsx(i)              // x(i+1)           // Matlab is 1-basedC(i,j)            // C(i+1,j+1)       //Eigen 基础使用// Basic usage// Eigen        // Matlab           // commentsx.size()        // length(x)        // vector sizeC.rows()        // size(C,1)        // number of rowsC.cols()        // size(C,2)        // number of columnsx(i)            // x(i+1)           // Matlab is 1-basedC(i, j)         // C(i+1,j+1)       //A.resize(4, 4);   // Runtime error if assertions are on.B.resize(4, 9);   // Runtime error if assertions are on.A.resize(3, 3);   // Ok; size didn't change.B.resize(3, 9);   // Ok; only dynamic cols changed.A << 1, 2, 3,     // Initialize A. The elements can also be4, 5, 6,     // matrices, which are stacked along cols7, 8, 9;     // and then the rows are stacked.B << A, A, A;     // B is three horizontally stacked A's.A.fill(10);       // Fill A with all 10's.Eigen 特殊矩阵生成// Eigen                            // MatlabMatrixXd::Identity(rows,cols)       // eye(rows,cols)C.setIdentity(rows,cols)            // C = eye(rows,cols)MatrixXd::Zero(rows,cols)           // zeros(rows,cols)C.setZero(rows,cols)                // C = ones(rows,cols)MatrixXd::Ones(rows,cols)           // ones(rows,cols)C.setOnes(rows,cols)                // C = ones(rows,cols)MatrixXd::Random(rows,cols)         // rand(rows,cols)*2-1        // MatrixXd::Random returns uniform random numbers in (-1, 1).C.setRandom(rows,cols)              // C = rand(rows,cols)*2-1VectorXd::LinSpaced(size,low,high)  // linspace(low,high,size)'v.setLinSpaced(size,low,high)       // v = linspace(low,high,size)'Eigen 矩阵分块// Matrix slicing and blocks. All expressions listed here are read/write.// Templated size versions are faster. Note that Matlab is 1-based (a size N// vector is x(1)...x(N)).// Eigen                           // Matlabx.head(n)                          // x(1:n)x.head<n>()                        // x(1:n)x.tail(n)                          // x(end - n + 1: end)x.tail<n>()                        // x(end - n + 1: end)x.segment(i, n)                    // x(i+1 : i+n)x.segment<n>(i)                    // x(i+1 : i+n)P.block(i, j, rows, cols)          // P(i+1 : i+rows, j+1 : j+cols)P.block<rows, cols>(i, j)          // P(i+1 : i+rows, j+1 : j+cols)P.row(i)                           // P(i+1, :)P.col(j)                           // P(:, j+1)P.leftCols<cols>()                 // P(:, 1:cols)P.leftCols(cols)                   // P(:, 1:cols)P.middleCols<cols>(j)              // P(:, j+1:j+cols)P.middleCols(j, cols)              // P(:, j+1:j+cols)P.rightCols<cols>()                // P(:, end-cols+1:end)P.rightCols(cols)                  // P(:, end-cols+1:end)P.topRows<rows>()                  // P(1:rows, :)P.topRows(rows)                    // P(1:rows, :)P.middleRows<rows>(i)              // P(i+1:i+rows, :)P.middleRows(i, rows)              // P(i+1:i+rows, :)P.bottomRows<rows>()               // P(end-rows+1:end, :)P.bottomRows(rows)                 // P(end-rows+1:end, :)P.topLeftCorner(rows, cols)        // P(1:rows, 1:cols)P.topRightCorner(rows, cols)       // P(1:rows, end-cols+1:end)P.bottomLeftCorner(rows, cols)     // P(end-rows+1:end, 1:cols)P.bottomRightCorner(rows, cols)    // P(end-rows+1:end, end-cols+1:end)P.topLeftCorner<rows,cols>()       // P(1:rows, 1:cols)P.topRightCorner<rows,cols>()      // P(1:rows, end-cols+1:end)P.bottomLeftCorner<rows,cols>()    // P(end-rows+1:end, 1:cols)P.bottomRightCorner<rows,cols>()   // P(end-rows+1:end, end-cols+1:end)Eigen 矩阵元素交换// Of particular note is Eigen's swap function which is highly optimized.// Eigen                           // MatlabR.row(i) = P.col(j);               // R(i, :) = P(:, i)R.col(j1).swap(mat1.col(j2));      // R(:, [j1 j2]) = R(:, [j2, j1])Eigen 矩阵转置// Views, transpose, etc; all read-write except for .adjoint().// Eigen                           // MatlabR.adjoint()                        // R'R.transpose()                      // R.' or conj(R')R.diagonal()                       // diag(R)x.asDiagonal()                     // diag(x)R.transpose().colwise().reverse(); // rot90(R)R.conjugate()                      // conj(R)Eigen 矩阵乘积// All the same as Matlab, but matlab doesn't have *= style operators.// Matrix-vector.  Matrix-matrix.   Matrix-scalar.y  = M*x;          R  = P*Q;        R  = P*s;a  = b*M;          R  = P - Q;      R  = s*P;a *= M;            R  = P + Q;      R  = P/s;R *= Q;          R  = s*P;R += Q;          R *= s;R -= Q;          R /= s;Eigen 矩阵单个元素操作// Vectorized operations on each element independently// Eigen                  // MatlabR = P.cwiseProduct(Q);    // R = P .* QR = P.array() * s.array();// R = P .* sR = P.cwiseQuotient(Q);   // R = P ./ QR = P.array() / Q.array();// R = P ./ QR = P.array() + s.array();// R = P + sR = P.array() - s.array();// R = P - sR.array() += s;           // R = R + sR.array() -= s;           // R = R - sR.array() < Q.array();    // R < QR.array() <= Q.array();   // R <= QR.cwiseInverse();         // 1 ./ PR.array().inverse();      // 1 ./ PR.array().sin()           // sin(P)R.array().cos()           // cos(P)R.array().pow(s)          // P .^ sR.array().square()        // P .^ 2R.array().cube()          // P .^ 3R.cwiseSqrt()             // sqrt(P)R.array().sqrt()          // sqrt(P)R.array().exp()           // exp(P)R.array().log()           // log(P)R.cwiseMax(P)             // max(R, P)R.array().max(P.array())  // max(R, P)R.cwiseMin(P)             // min(R, P)R.array().min(P.array())  // min(R, P)R.cwiseAbs()              // abs(P)R.array().abs()           // abs(P)R.cwiseAbs2()             // abs(P.^2)R.array().abs2()          // abs(P.^2)(R.array() < s).select(P,Q);  // (R < s ? P : Q)Eigen 矩阵化简// Reductions.int r, c;// Eigen                  // MatlabR.minCoeff()              // min(R(:))R.maxCoeff()              // max(R(:))s = R.minCoeff(&r, &c)    // [s, i] = min(R(:)); [r, c] = ind2sub(size(R), i);s = R.maxCoeff(&r, &c)    // [s, i] = max(R(:)); [r, c] = ind2sub(size(R), i);R.sum()                   // sum(R(:))R.colwise().sum()         // sum(R)R.rowwise().sum()         // sum(R, 2) or sum(R')'R.prod()                  // prod(R(:))R.colwise().prod()        // prod(R)R.rowwise().prod()        // prod(R, 2) or prod(R')'R.trace()                 // trace(R)R.all()                   // all(R(:))R.colwise().all()         // all(R)R.rowwise().all()         // all(R, 2)R.any()                   // any(R(:))R.colwise().any()         // any(R)R.rowwise().any()         // any(R, 2)Eigen 矩阵点乘// Dot products, norms, etc.// Eigen                  // Matlabx.norm()                  // norm(x).    Note that norm(R) doesn't work in Eigen.x.squaredNorm()           // dot(x, x)   Note the equivalence is not true for complexx.dot(y)                  // dot(x, y)x.cross(y)                // cross(x, y) Requires #include <Eigen/Geometry>Eigen 矩阵类型转换 Type conversion// Eigen                           // MatlabA.cast<double>();                  // double(A)A.cast<float>();                   // single(A)A.cast<int>();                     // int32(A)A.real();                          // real(A)A.imag();                          // imag(A)// if the original type equals destination type, no work is doneEigen 求解线性方程组 Ax = b// Solve Ax = b. Result stored in x. Matlab: x = A \ b.x = A.ldlt().solve(b));  // A sym. p.s.d.    #include <Eigen/Cholesky>x = A.llt() .solve(b));  // A sym. p.d.      #include <Eigen/Cholesky>x = A.lu()  .solve(b));  // Stable and fast. #include <Eigen/LU>x = A.qr()  .solve(b));  // No pivoting.     #include <Eigen/QR>x = A.svd() .solve(b));  // Stable, slowest. #include <Eigen/SVD>// .ldlt() -> .matrixL() and .matrixD()// .llt()  -> .matrixL()// .lu()   -> .matrixL() and .matrixU()// .qr()   -> .matrixQ() and .matrixR()// .svd()  -> .matrixU(), .singularValues(), and .matrixV()Eigen 矩阵特征值// Eigenvalue problems// Eigen                          // MatlabA.eigenvalues();                  // eig(A);EigenSolver<Matrix3d> eig(A);     // [vec val] = eig(A)eig.eigenvalues();                // diag(val)eig.eigenvectors();               // vec// For self-adjoint matrices use SelfAdjointEigenSolver<>

Eigen库基本操作相关推荐

  1. 关于C++中Eigen库效率提升的思考

    目录 引言 一.什么是Eigen? 二.使用步骤 1.引入库 2.建立矩阵 3.基本操作 三.具体的例子--矩阵乘法 1.Eigen库 2.GPU并行计算 总结 可能的方案 引言 在处理矩阵运算上,各 ...

  2. Eigen库学习教程(全)

    说明:本教程主要是对eigen官网文档做了一个简要的翻译,参考了eigen官网以及一些博主的技术贴,在此表示感谢. Eigen是一个高层次的C ++库,有效支持线性代数,矩阵和矢量运算,数值分析及其相 ...

  3. 使用 Eigen 库写第一个程序

    一.使用 Eigen 库时编译器设置 使用 Eigen 库之前需要下载库文件,并进行简单的设置. 下载地址: http://eigen.tuxfamily.org/index.php?title=Ma ...

  4. ROS中使用Eigen库[不定期更新]

    前期说明 ROS中的数据操作需要线性代数,Eigen库是C++中的线性代数计算库. Eigen库独立于ROS,但是在ROS中可以使用. Eigen库可以参见http://eigen.tuxfamily ...

  5. Eigen库对齐问题:declspec(align('16')) 的形参将不被对齐

    一:错误提示:error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned 英文提示:erro ...

  6. eigen库学习笔记(2)

    这里主要整理矩阵运算相关内容.其中备注了与Matlab的命令对比. eigen库的矩阵运算 Eigen 矩阵定义 Eigen 基础使用 Eigen 特殊矩阵生成 Eigen 矩阵分块 Eigen 矩阵 ...

  7. eigen库学习笔记

    #简介 Eigen是有关线性代数(矩阵.向量等)的c++模板库.支持SSE2/3/4, ARM NEON (32-bit and 64-bit), PowerPC AltiVec/VSX (32-bi ...

  8. Linux下添加eigen头文件,移植Eigen库到SylixOS下及使用方法

    1. 开发环境 宿主机:Windows 7 集成开发环境:Real-Evo IDE 3.5.3 虚拟机:Ubuntu 目标机:x86 2. Eigen简介 Eigen是一个提供了线性代数.矩阵.向量操 ...

  9. 0.前言 与 Eigen库的使用整理

    [C++ 基于Eigen库实现CRN前向推理] 前言:背景 与 Eigen库的使用整理 前言:(Eigen库使用记录) 第一部分:WavFile.class (实现读取wav/pcm,实现STFT) ...

最新文章

  1. 有效的rtsp流媒体测试地址汇总
  2. 一、Linux Shell基础
  3. Hadoop的安装与使用
  4. .Net Core in Docker极简入门(下篇)
  5. linux硬盘保护卡,保护卡下安装Linux
  6. Cannot open precompiled header file: 'Debug/shuju1.pch': No such file or directory
  7. Android应用程序与SurfaceFlinger服务的连接过程分析
  8. Android开发学习之卡片式布局的简单实现
  9. Sql Create Function简单例子
  10. HCIE-Security Day4:安全策略和状态检测
  11. 微信小程序大全:767个小程序
  12. 阿里巴巴Java开发手册代码规范
  13. 验证码识别登录:使用超级鹰(验证码识别第三方包)识别超级鹰网站登录
  14. SQL SERVER STATISTICS
  15. 解决Error: Assertion failed (chunk.m_size <= 0xFFFF)和Set OPENCV_ENABLE_NONFREE CMake option问题
  16. android 拔插键盘自动切换输入法
  17. SwiftUI的多列列表
  18. @Transactional的介绍和使用
  19. 10KV空压机继电保护定值设定
  20. Boundary Loss 原理与代码解析

热门文章

  1. 伽卡他卡电子教室 百度百科_怎么创建人物百度百科?人物百度百科创作技巧...
  2. c++ 出现1.#IND、1.#INF
  3. 【多线程】join()和detach()的用法
  4. 并发新特性—Executor 框架与线程池
  5. isInfoEnabled究竟多有用?
  6. Java Applet 基础
  7. 为何你叫妹子笑,却拍出无数黑照?
  8. OpenCV之core 模块. 核心功能(1)Mat - 基本图像容器 OpenCV如何扫描图像、利用查找表和计时 矩阵的掩码操作 使用OpenCV对两幅图像求和(求混合(blending))
  9. 【OpenCV】透视变换 Perspective Transformation(续)
  10. 使用matlab版卷及神经网络 MatconvNe和预训练的imageNet进行图像检Image retrieval using MatconvNet and pre-trained imageNet