blob: a5b0195312d04fffe1ff73b8d46a7e948464d585 [file] [log] [blame]
Benoit Jacob1af61c62007-09-09 09:41:15 +00001#include "../src/All"
Benoit Jacob61158b12007-09-07 08:18:21 +00002
3using namespace std;
Benoit Jacob61158b12007-09-07 08:18:21 +00004
5int main(int, char **)
6{
Benoit Jacob28c44a92007-09-27 19:54:04 +00007 EiMatrix<double,2,2> m; // 2x2 fixed-size matrix with uninitialized entries
Benoit Jacob61158b12007-09-07 08:18:21 +00008 m(0,0) = 1;
9 m(0,1) = 2;
10 m(1,0) = 3;
11 m(1,1) = 4;
Benoit Jacob55227b12007-09-26 14:06:14 +000012
Benoit Jacob61158b12007-09-07 08:18:21 +000013 cout << "Here is a 2x2 matrix m:" << endl << m << endl;
14 cout << "Let us now build a 4x4 matrix m2 by assembling together four 2x2 blocks." << endl;
Benoit Jacob5160e9d2007-09-27 19:38:40 +000015 EiMatrixXd m2(4,4); // dynamic matrix with initial size 4x4 and uninitialized entries
Benoit Jacob61158b12007-09-07 08:18:21 +000016 // notice how we are mixing fixed-size and dynamic-size types.
17
18 cout << "In the top-left block, we put the matrix m shown above." << endl;
Benoit Jacob1dab53d2007-09-09 08:17:08 +000019 m2.block(0,1,0,1) = m;
Benoit Jacob61158b12007-09-07 08:18:21 +000020 cout << "In the bottom-left block, we put the matrix m*m, which is:" << endl << m*m << endl;
Benoit Jacob1dab53d2007-09-09 08:17:08 +000021 m2.block(2,3,0,1) = m * m;
Benoit Jacob61158b12007-09-07 08:18:21 +000022 cout << "In the top-right block, we put the matrix m+m, which is:" << endl << m+m << endl;
Benoit Jacob1dab53d2007-09-09 08:17:08 +000023 m2.block(0,1,2,3) = m + m;
Benoit Jacob61158b12007-09-07 08:18:21 +000024 cout << "In the bottom-right block, we put the matrix m-m, which is:" << endl << m-m << endl;
Benoit Jacob1dab53d2007-09-09 08:17:08 +000025 m2.block(2,3,2,3) = m - m;
Benoit Jacob61158b12007-09-07 08:18:21 +000026 cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl;
27
Benoit Jacob61158b12007-09-07 08:18:21 +000028 cout << "The central 2x2 block of m2 is:" << endl << m2.block(1,2,1,2) << endl;
Benoit Jacob96524fc2007-10-01 07:45:30 +000029 cout << "Row 0 of m2 is:" << endl << m2.row(0) << endl;
30 cout << "The third element in that row is " << m2.row(0)[2] << endl;
Benoit Jacob61158b12007-09-07 08:18:21 +000031 cout << "Column 1 of m2 is:" << endl << m2.col(1) << endl;
32 cout << "The matrix m2 with row 0 and column 1 removed is:" << endl << m2.minor(0,1) << endl;
Benoit Jacob96524fc2007-10-01 07:45:30 +000033
Benoit Jacob61158b12007-09-07 08:18:21 +000034 return 0;
35}