C++_Eigen函数库用法笔记——Matrix and Vector Arithmetic
- 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(){Matrix2d a;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
- binary operator + as in
- 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(){Matrix2d a;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
- TranspositionMatrixXcf a = MatrixXcf::Random(2,2);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)
a = a.transpose()
does not replace a
with its transpose- 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 toa = a*b
#include <iostream>#include <Eigen/Dense>using namespace Eigen;int main(){Matrix2d mat;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
- binary operator * as in
- Trace(求迹的和)
#include <iostream>#include <Eigen/Dense>using namespace std;int main(){Eigen::Matrix2d mat;mat << 1, 2,3, 4;cout << "Here is mat.trace(): " << mat.trace() << endl;}Here is mat.trace(): 5
C++_Eigen函数库用法笔记——Matrix and Vector Arithmetic的更多相关文章
- C++_Eigen函数库用法笔记——The Array class and Coefficient-wise operations
The advantages of Array Addition and subtraction Array multiplication abs() & sqrt() Converting ...
- 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 ...
- C++_Eigen函数库用法笔记——Advanced Initialization
The comma initializer a simple example join and block initialize join two row vectors together ini ...
- PHP中正则替换函数preg_replace用法笔记
今天应老板的需求,需要将不是我们的页面修改一个链接,用js+iframe应该也能实现,但是我想尝试一下php实现方法. 首先你得先把别人的页面download到你的php中,实现方法可以用curl, ...
- 菜鸟Python学习笔记第一天:关于一些函数库的使用
2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...
- 转: ES6异步编程: co函数库的含义与用法
转: ES6异步编程: co函数库的含义与用法 co 函数库是著名程序员 TJ Holowaychuk 于2013年6月发布的一个小工具,用于 Generator 函数的自动执行. 比如,有一个 Ge ...
- makefile笔记10 - makefile 函数库文件
函数库文件也就是对 Object 文件(程序编译的中间文件)的打包文件.在 Unix 下,一般是由命令"ar"来完成打包工作. 一.函数库文件的成员 一个函数库文件由多个文件组成. ...
- OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法
函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...
- python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法
python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法 在Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数 ...
随机推荐
- 20145222黄亚奇《Java程序设计》第9周学习总结
20145222第九周<Java学习笔记>学习总结 教材学习内容总结 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找 JDBC(Ja ...
- 常用的user32API说明
整理了一下常用的user32API说明 还有软件Microsoft Spy++供大家下载 Spyv10.00.30319.rar using System; using System.Collect ...
- memcached 适用的场景
最近在看 memcached 的公共课,发现memcache的确是个好东西,可以显著地减小数据库负载,当然我们要搞清楚,任何一样技术都有它的优缺点, 在使用它的时候,搞清楚它的适用场景,才能扬长避短 ...
- php 利用socket发送GET,POST请求
作为php程序员一定会接触http协议,也只有深入了解http协议,编程水平才会更进一步.最近我一直在学习php的关于http的编程,许多东西恍然大悟,受益匪浅.希望分享给大家.本文需要有一定http ...
- IE8/9的console之坑
这几天遇到个深坑,在改别人代码时,发现ajax在ie8下请求不成功.清理了缓存后,可以请求成功!(清理缓存只是表象而已,后文说原因) 后来慢慢看代码,发现ajax成功回调了!在success回调里,我 ...
- Servlet响应的中文字符集问题
在Servlet中利用response向客户端浏览器输出中文时有时会遇到乱码问题,总结如下: response输出流有两种,一是以字节流输出,一是以字符流输出. 一.以字节流输出: 1.默认编码输出木 ...
- Git.Framework 框架随手记--ORM查询返回实体对象
使用ORM有一个优势,可以通过某种机制将数据库中的数据转化为自己想要的对象形式数据.本章记录一下如何使用Git.Framework返回实体对象 一. Git.Framework 中提供的方法 在Git ...
- XAMPP里tomcat启动报错:Make sure you have Java JDK or JRE installed and the required ports are free
以前用XAMPP的时候就是自然而然装好了就可以用,最近重装了新系统,打算在Windows 10里面配置Apache tomcat.PHP.MySQL的开发环境,迟迟试验不成功,于是直接用了XAMPP, ...
- 阿里百川IMSDK--自定义群聊界面
// 获取群对象 YWTribe *tribe = [self.tribesArray objectAtIndex:indexPath.row]; // 发起群聊 UIViewController * ...
- C头文件之<cstring>
(string.h) 这个文件夹主要是定义了几个对字符串和数组进行操作的函数.功能很强大.下面是重要函数: strcpy.strncpy strcpy,strncpy 这两个函数是对字符串的复制,很常 ...