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