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', ' ')的函数 ...
随机推荐
- [CareerCup] 8.3 Musical Jukebox 点唱机
8.3 Design a musical jukebox using object-oriented principles. CareerCup这书实在是太不负责任了,就写了个半调子的程序,说是完整版 ...
- 20145222黄亚奇《Java程序设计》第10周学习总结
20145222 <Java程序设计>第10周学习总结 学习总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接 ...
- 上位机用USB做虚拟串口,总算抓到一个纯代码的总结了,没有坑的完美解决。
用libUSB来实现自己的驱动+下位机理论速度.=1M字节每秒. 达到极限速度 WINDOWS已经自带虚拟串口驱动,只不过还需要一个Inf文件 方法1:直接下载一个串口inf,来修改文件. 方 ...
- Android中的Intent Filter匹配规则介绍
本文主要介绍了隐式Intent匹配目标组件的规则,若有叙述不清晰或是不准确的地方希望大家指出,谢谢大家: ) 1. Intent简介 Intent用于在一个组件(Component,如Activity ...
- windows程序防狼术入门
当初由于一些原因以及兴趣,学习了一段时间软件逆向,对于软件加密解密有了点粗略的了解.而后看到某些同学辛辛苦苦的搞出个软件,自己费心费力去加密,但搞出来后往往能被秒破,实不忍心.今天大概总结下一些基本的 ...
- 微信小程序开发常见问题分析
距离微信小程序内测版发布已经有十几天的时间了,网上对微信小程序的讨论也异常火爆,从发布到现在微信小程序一直占领着各种技术论坛的头条,当然各种平台也对微信小程序有新闻报道,毕竟腾讯在国内影响力还是很大的 ...
- [wikioi2069]油画(贪心)
题目:http://www.wikioi.com/problem/2069/ 分析: 首先这个问题比较复杂,涉及到两个重要的考虑点,一个是当前拿来的颜色是否保留,一个是若保留后那么应该把当前盘子的哪个 ...
- PHP中的日期加减方法示例
几乎所有从事程序开发的程序员都遇到时间处理问题,PHP开发也一样,幸运的是PHP提供了很多关于日期时间函数.只要经常使用这些函数,搭配使用,日期时间处理上就熟能生巧了. 今天要讲的这个例子,需求是这样 ...
- 一条命令使win7可以直接运行.net3.5程序
dism /online /get-features 获取 功能名称 dism /online /enable-feature /featurename:NetFx3 启用win7自带的.net f ...
- 作业一_随笔3_调研Android的开发环境的发展演变
调研某一移动应用/平台的开发环境的发展演变:Android 其实,一开始,我只知道,苹果手机用IOS系统,其他很多手机时候安卓系统.我百度知道Android开发主要是android studio和Ec ...