blob: b0627083d927ab48c23c8492e6aac3a1249341c0 [file] [log] [blame]
Benoit Jacob86220782007-12-28 16:20:00 +00001#include <Eigen/Core>
Benoit Jacob61158b12007-09-07 08:18:21 +00002
Benoit Jacob3cd2a122007-12-24 11:14:25 +00003USING_PART_OF_NAMESPACE_EIGEN
Benoit Jacob61de15f2007-10-11 20:14:01 +00004
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 Jacobf12e9c52008-02-29 13:56:40 +000021 m2.block<2,2>(0,0) = 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 Jacobf12e9c52008-02-29 13:56:40 +000023 m2.block<2,2>(2,0) = 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 Jacobf12e9c52008-02-29 13:56:40 +000025 m2.block<2,2>(0,2) = 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 Jacobf12e9c52008-02-29 13:56:40 +000027 m2.block<2,2>(2,2) = 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}