source: pacpussensors/trunk/Vislab/lib3dv/eigen/Eigen-install/doc/snippets/compile_TopicAliasing_cwise.cpp@ 136

Last change on this file since 136 was 136, checked in by ldecherf, 7 years ago

Doc

File size: 774 bytes
Line 
1#include <Eigen/Dense>
2#include <iostream>
3
4using namespace Eigen;
5using namespace std;
6
7int main(int, char**)
8{
9 cout.precision(3);
10 MatrixXf mat(2,2);
11mat << 1, 2, 4, 7;
12cout << "Here is the matrix mat:\n" << mat << endl << endl;
13
14mat = 2 * mat;
15cout << "After 'mat = 2 * mat', mat = \n" << mat << endl << endl;
16
17
18mat = mat - MatrixXf::Identity(2,2);
19cout << "After the subtraction, it becomes\n" << mat << endl << endl;
20
21
22ArrayXXf arr = mat;
23arr = arr.square();
24cout << "After squaring, it becomes\n" << arr << endl << endl;
25
26// Combining all operations in one statement:
27mat << 1, 2, 4, 7;
28mat = (2 * mat - MatrixXf::Identity(2,2)).array().square();
29cout << "Doing everything at once yields\n" << mat << endl << endl;
30
31 return 0;
32}
Note: See TracBrowser for help on using the repository browser.