Benoit Jacob | 1af61c6 | 2007-09-09 09:41:15 +0000 | [diff] [blame] | 1 | #include "../src/All" |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 2 | |
| 3 | using namespace std; |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 4 | |
| 5 | int main(int, char **) |
| 6 | { |
Benoit Jacob | 28c44a9 | 2007-09-27 19:54:04 +0000 | [diff] [blame] | 7 | EiMatrix<double,2,2> m; // 2x2 fixed-size matrix with uninitialized entries |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 8 | m(0,0) = 1; |
| 9 | m(0,1) = 2; |
| 10 | m(1,0) = 3; |
| 11 | m(1,1) = 4; |
Benoit Jacob | 55227b1 | 2007-09-26 14:06:14 +0000 | [diff] [blame] | 12 | |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 13 | 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 Jacob | 5160e9d | 2007-09-27 19:38:40 +0000 | [diff] [blame] | 15 | EiMatrixXd m2(4,4); // dynamic matrix with initial size 4x4 and uninitialized entries |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 16 | // 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 Jacob | 1dab53d | 2007-09-09 08:17:08 +0000 | [diff] [blame] | 19 | m2.block(0,1,0,1) = m; |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 20 | cout << "In the bottom-left block, we put the matrix m*m, which is:" << endl << m*m << endl; |
Benoit Jacob | 1dab53d | 2007-09-09 08:17:08 +0000 | [diff] [blame] | 21 | m2.block(2,3,0,1) = m * m; |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 22 | cout << "In the top-right block, we put the matrix m+m, which is:" << endl << m+m << endl; |
Benoit Jacob | 1dab53d | 2007-09-09 08:17:08 +0000 | [diff] [blame] | 23 | m2.block(0,1,2,3) = m + m; |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 24 | cout << "In the bottom-right block, we put the matrix m-m, which is:" << endl << m-m << endl; |
Benoit Jacob | 1dab53d | 2007-09-09 08:17:08 +0000 | [diff] [blame] | 25 | m2.block(2,3,2,3) = m - m; |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 26 | cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl; |
| 27 | |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 28 | cout << "The central 2x2 block of m2 is:" << endl << m2.block(1,2,1,2) << endl; |
Benoit Jacob | 96524fc | 2007-10-01 07:45:30 +0000 | [diff] [blame^] | 29 | 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 Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 31 | 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 Jacob | 96524fc | 2007-10-01 07:45:30 +0000 | [diff] [blame^] | 33 | |
Benoit Jacob | 61158b1 | 2007-09-07 08:18:21 +0000 | [diff] [blame] | 34 | return 0; |
| 35 | } |