blob: 4400bd2d1dd4e176d0f594419e8fd259aceb730c [file] [log] [blame]
Benoit Jacob4fe78b82007-10-07 15:59:09 +00001#include "../src/Core.h"
Benoit Jacob61158b12007-09-07 08:18:21 +00002
Benoit Jacob61de15f2007-10-11 20:14:01 +00003USING_EIGEN_DATA_TYPES
4
Benoit Jacob61158b12007-09-07 08:18:21 +00005using namespace std;
Benoit Jacob61158b12007-09-07 08:18:21 +00006
7int main(int, char **)
8{
Benoit Jacob61de15f2007-10-11 20:14:01 +00009 Matrix<double,2,2> m; // 2x2 fixed-size matrix with uninitialized entries
Benoit Jacob61158b12007-09-07 08:18:21 +000010 m(0,0) = 1;
11 m(0,1) = 2;
12 m(1,0) = 3;
13 m(1,1) = 4;
Benoit Jacob55227b12007-09-26 14:06:14 +000014
Benoit Jacob61158b12007-09-07 08:18:21 +000015 cout << "Here is a 2x2 matrix m:" << endl << m << endl;
16 cout << "Let us now build a 4x4 matrix m2 by assembling together four 2x2 blocks." << endl;
Benoit Jacob61de15f2007-10-11 20:14:01 +000017 MatrixXd m2(4,4); // dynamic matrix with initial size 4x4 and uninitialized entries
Benoit Jacob61158b12007-09-07 08:18:21 +000018 // notice how we are mixing fixed-size and dynamic-size types.
19
20 cout << "In the top-left block, we put the matrix m shown above." << endl;
Benoit Jacob1dab53d2007-09-09 08:17:08 +000021 m2.block(0,1,0,1) = m;
Benoit Jacob61158b12007-09-07 08:18:21 +000022 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 +000023 m2.block(2,3,0,1) = m * m;
Benoit Jacob61158b12007-09-07 08:18:21 +000024 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 +000025 m2.block(0,1,2,3) = m + m;
Benoit Jacob61158b12007-09-07 08:18:21 +000026 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 +000027 m2.block(2,3,2,3) = m - m;
Benoit Jacob61158b12007-09-07 08:18:21 +000028 cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl;
29
Benoit Jacob96524fc2007-10-01 07:45:30 +000030 cout << "Row 0 of m2 is:" << endl << m2.row(0) << endl;
31 cout << "The third element in that row is " << m2.row(0)[2] << endl;
Benoit Jacob61158b12007-09-07 08:18:21 +000032 cout << "Column 1 of m2 is:" << endl << m2.col(1) << endl;
Benoit Jacobc768a442007-10-01 18:20:35 +000033 cout << "The transpose of m2 is:" << endl << m2.transpose() << endl;
Benoit Jacob61158b12007-09-07 08:18:21 +000034 cout << "The matrix m2 with row 0 and column 1 removed is:" << endl << m2.minor(0,1) << endl;
Benoit Jacob61158b12007-09-07 08:18:21 +000035 return 0;
36}