• Addition and subtraction
  • Scalar multiplication and division
  • Transposition
  • Matrix-matrix and matrix-vector multiplication
  • Trace(求迹的和)
 

  • Addition and subtraction

    • binary operator + as in a+b
    • binary operator - as in a-b
    • unary operator - as in -a
    • compound operator += as in a+=b
    • compound operator -= as in a-=b
      #include <iostream>
      #include <Eigen/Dense>
      using namespace Eigen;
      int main()
      {
      a << 1, 2,
      3, 4;
      MatrixXd b(2,2);
      b << 2, 3,
      1, 4;
      std::cout << "a + b =\n" << a + b << std::endl;
      std::cout << "a - b =\n" << a - b << std::endl;
      std::cout << "Doing a += b;" << std::endl;
      a += b;
      std::cout << "Now a =\n" << a << std::endl;
      Vector3d v(1,2,3);
      Vector3d w(1,0,0);
      std::cout << "-v + w - v =\n" << -v + w - v << std::endl;
      }

      a + b =
      3 5
      4 8
      a - b =
      -1 -1
       2  0
      Doing a += b;
      Now a =
      3 5
      4 8
      -v + w - v =
      -1
      -4
      -6
  • Scalar multiplication and division
    • binary operator * as in matrix*scalar
    • binary operator * as in scalar*matrix
    • binary operator / as in matrix/scalar
    • compound operator *= as in matrix*=scalar
    • compound operator /= as in matrix/=scalar
      #include <iostream>
      #include <Eigen/Dense>
      using namespace Eigen;
      int main()
      {
        a << 1, 2,
             3, 4;
      Vector3d v(1,2,3);
        std::cout << "a * 2.5 =\n" << a * 2.5 << std::endl;
        std::cout << "0.1 * v =\n" << 0.1 * v << std::endl;
        std::cout << "Doing v *= 2;" << std::endl;
        v *= 2;
        std::cout << "Now v =\n" << v << std::endl;
      }

      a * 2.5 =
      2.5   5
      7.5  10
      0.1 * v =
      0.1
      0.2
      0.3
      Doing v *= 2;
      Now v =
      2
      4
      6
  • Transposition

    cout << "Here is the matrix a\n" << a << endl;
    cout << "Here is the matrix a^T\n" << a.transpose() << endl;

    Here is the matrix a
     (-0.211,0.68) (-0.605,0.823)
     (0.597,0.566)  (0.536,-0.33)
    Here is the matrix a^T
     (-0.211,0.68)  (0.597,0.566)
    (-0.605,0.823)  (0.536,-0.33)
          the instruction a = a.transpose() does not replace a with its transpose
          For in-place transposition,simply use the transposeInPlace()                
MatrixXf a(2,3); a << 1, 2, 3, 4, 5, 6;
cout << "Here is the initial matrix a:\n" << a << endl;
a.transposeInPlace();
cout << "and after being transposed:\n" << a << endl;
  • Matrix-matrix and matrix-vector multiplication

    • binary operator * as in a*b
    • compound operator *= as in a*=b (this multiplies on the right: a*=b is equivalent to a = a*b
      #include <iostream>
      #include <Eigen/Dense>
      using namespace Eigen;
      int main()
      {
      mat << 1, 2,
      3, 4;
      Vector2d u(-1,1), v(2,0);
      std::cout << "Here is mat*mat:\n" << mat*mat << std::endl;
      std::cout << "Here is mat*u:\n" << mat*u << std::endl;
      std::cout << "Here is u^T*mat:\n" << u.transpose()*mat << std::endl;
      std::cout << "Here is u^T*v:\n" << u.transpose()*v << std::endl;
      std::cout << "Here is u*v^T:\n" << u*v.transpose() << std::endl;
      std::cout << "Let's multiply mat by itself" << std::endl;
      mat = mat*mat;
      std::cout << "Now mat is mat:\n" << mat << std::endl;
      }

      Here is mat*mat:
       7 10
      15 22
      Here is mat*u:
      1
      1
      Here is u^T*mat:
      2 2
      Here is u^T*v:
      -2
      Here is u*v^T:
      -2 -0
       2  0
      Let's multiply mat by itself
      Now mat is mat:
       7 10
      15 22
  • Trace(求迹的和)

    #include <iostream>
    #include <Eigen/Dense>
    using namespace std;
    int main()
    {
      mat << 1, 2,
             3, 4;

    cout << "Here is mat.trace(): " << mat.trace() << endl;
    }

    Here is mat.trace():     5

C++_Eigen函数库用法笔记——Matrix and Vector Arithmetic的更多相关文章

  1. C++_Eigen函数库用法笔记——The Array class and Coefficient-wise operations

    The advantages of Array Addition and subtraction Array multiplication abs() & sqrt() Converting ...

  2. C++_Eigen函数库用法笔记——Block Operations

    Using block operations rvalue, i.e. it was only read from lvalues, i.e. you can assign to a block Co ...

  3. C++_Eigen函数库用法笔记——Advanced Initialization

    The comma initializer a simple example  join and block initialize  join two row vectors together ini ...

  4. PHP中正则替换函数preg_replace用法笔记

    今天应老板的需求,需要将不是我们的页面修改一个链接,用js+iframe应该也能实现,但是我想尝试一下php实现方法. 首先你得先把别人的页面download到你的php中,实现方法可以用curl, ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. 转: ES6异步编程: co函数库的含义与用法

    转: ES6异步编程: co函数库的含义与用法 co 函数库是著名程序员 TJ Holowaychuk 于2013年6月发布的一个小工具,用于 Generator 函数的自动执行. 比如,有一个 Ge ...

  7. makefile笔记10 - makefile 函数库文件

    函数库文件也就是对 Object 文件(程序编译的中间文件)的打包文件.在 Unix 下,一般是由命令"ar"来完成打包工作. 一.函数库文件的成员 一个函数库文件由多个文件组成. ...

  8. OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法

    函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...

  9. python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法

    python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法 在Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数 ...

随机推荐

  1. StringBuffer类 和 StringBuilder类

    上一篇中讲解了String类的用法.那么String有什么特点呢? 字符串特点:字符串是常量,其值在创建后就不能被修改.字符串的内容一旦发生变化,就会创建一个新的对象. 代码验证字符串特点: publ ...

  2. GDB深入研究

    GDB深入研究 一.GDB代码调试 (一)GDB调试实例 在终端中编译一个示例C语言小程序,保存到文件 gdb-sample.c 中,用GCC编译之 #include <stdio.h> ...

  3. iOS开发--应用设置及用户默认设置——转载

    [链接]iOS开发--应用设置及用户默认设置[1.bundlehttp://www.jianshu.com/p/6f2913f6b218 在iphone里面,应用都会在“设置”里面有个专属的应用设置, ...

  4. 窥探算法之美妙——寻找数组中最小的K个数&python中巧用最大堆

    原文发表在我的博客主页,转载请注明出处 前言 不论是小算法或者大系统,堆一直是某种场景下程序员比较亲睐的数据结构,而在python中,由于数据结构的极其灵活性,list,tuple, dict在很多情 ...

  5. 《android基于andFix的热修复方案》思路篇

    1:需求背景 项目上线之后,发现BUG需要修复(比如安卓兼容性等测试难以发现的问题),频繁的更新影响用户体验 2:方案要求 静默下载,耗费流量少,打完补丁后立刻生效,不用重启apk 3:解决思路 3. ...

  6. ubuntu安装 laravel 过程中出现: mcrypt php extension required 的问题 | 以及composer相关问题 | Nginx安装

    这篇文章对于Nginx的配置至关重要 如果碰到访问index.php不返回html而出现下载文件的问题,加上那段default就可以修正: https://www.digitalocean.com/c ...

  7. blur效果,模糊效果css

    .blur { -webkit-filter: blur(5px);   -moz-filter: blur(5px);   -o-filter: blur(5px);   -ms-filter: b ...

  8. 实现一个基于WCF的分布式缓存系统

    tks:http://www.cnblogs.com/xiguain/p/3913220.html

  9. 编写高质量代码改善C#程序的157个建议[4-9]

    前言 本文首先亦同步到http://www.cnblogs.com/aehyok/p/3624579.html.本文主要来学习记录一下内容: 建议4.TryParse比Parse好 建议5.使用int ...

  10. 第三章:模块加载系统(requirejs)

    任何一门语言在大规模应用阶段,必然要经历拆分模块的过程.便于维护与团队协作,与java走的最近的dojo率先引入加载器,早期的加载器都是同步的,使用document.write与同步Ajax请求实现. ...