• 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. Linux常用指令---find | locate(查找)

    1.locate locate指令和find找寻档案的功能类似,但locate是透过update程序将硬盘中的所有档案和目录资料先建立一个索引数据库,在 执行loacte时直接找该索引,查询速度会较快 ...

  2. IT应届生如何准备找工作?

    今天和一个弟弟吃饭,他明年年初即将计算机研究生毕业.谈论到怎么找工作,觉得自己会的不多,心里非常发虚.虽然我当年找工作也走了很多弯路,思路并不是很清晰.但是工作了这么多年,对企业需要什么样子的人还是有 ...

  3. python实现简易数据库之一——存储和索引建立

    最近没事做了一个数据库project,要求实现一个简单的数据库,能满足几个特定的查询,这里主要介绍一下我们的实现过程,代码放在过ithub,可参看这里.都说python的运行速度很慢,但因为时间比较急 ...

  4. 推荐一款超强大的基于Angularjs的自动完成(Autocomplete)标签及标签组插件–ngTagsInput

    前言 今天利用中午午休时间,给大家分享推荐一款基于Angularjs的自动完成(Autocomplete)标签及标签组插件--ngTagsInput,功能超强大的.不信,你试试就知道^_^... Au ...

  5. Node基础:域名解析DNS(ok)

    写在前面 Nodejs学习手册,基础总结之DNS模块.对从事web开发的同学来说,DNS解析再熟悉不过,在nodejs中也有一个模块可以完成dns解析的工作,使用非常简单.直接进入主题. 域名解析:d ...

  6. spring cloud教程之使用spring boot创建一个应用

    <7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...

  7. js的深度拷贝和浅拷贝

    从extend看浅拷贝和深拷贝 请先查看: http://blog.sina.com.cn/s/blog_912389e5010120n2.html

  8. DOM(九)使用DOM设置文本框

    1.控制用户输入的字符个数 对于单行文本框和密码输入框,可以利用maxlength属性控制用户输入的字符个数. 对于多行文本,maxlength为自定义属性,其值最多输入的字符的个数,在onkeypr ...

  9. linux 安装redmine 遇到的问题

    1.编译安装ruby-2.3.1时 需要先安装libyaml.libyaml-devel 2. 安装gem install rake ERROR: Loading command: install ( ...

  10. python 参数

    摘自:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00137473844933 ...