2007-09-09 17:41:15 +08:00
|
|
|
#include "../src/All"
|
2007-09-07 16:18:21 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main(int, char **)
|
|
|
|
{
|
2007-09-28 03:54:04 +08:00
|
|
|
EiMatrix<double,2,2> m; // 2x2 fixed-size matrix with uninitialized entries
|
2007-09-07 16:18:21 +08:00
|
|
|
m(0,0) = 1;
|
|
|
|
m(0,1) = 2;
|
|
|
|
m(1,0) = 3;
|
|
|
|
m(1,1) = 4;
|
2007-09-26 22:06:14 +08:00
|
|
|
|
2007-09-07 16:18:21 +08:00
|
|
|
cout << "Here is a 2x2 matrix m:" << endl << m << endl;
|
|
|
|
cout << "Let us now build a 4x4 matrix m2 by assembling together four 2x2 blocks." << endl;
|
2007-09-28 03:38:40 +08:00
|
|
|
EiMatrixXd m2(4,4); // dynamic matrix with initial size 4x4 and uninitialized entries
|
2007-09-07 16:18:21 +08:00
|
|
|
// notice how we are mixing fixed-size and dynamic-size types.
|
|
|
|
|
|
|
|
cout << "In the top-left block, we put the matrix m shown above." << endl;
|
2007-09-09 16:17:08 +08:00
|
|
|
m2.block(0,1,0,1) = m;
|
2007-09-07 16:18:21 +08:00
|
|
|
cout << "In the bottom-left block, we put the matrix m*m, which is:" << endl << m*m << endl;
|
2007-09-09 16:17:08 +08:00
|
|
|
m2.block(2,3,0,1) = m * m;
|
2007-09-07 16:18:21 +08:00
|
|
|
cout << "In the top-right block, we put the matrix m+m, which is:" << endl << m+m << endl;
|
2007-09-09 16:17:08 +08:00
|
|
|
m2.block(0,1,2,3) = m + m;
|
2007-09-07 16:18:21 +08:00
|
|
|
cout << "In the bottom-right block, we put the matrix m-m, which is:" << endl << m-m << endl;
|
2007-09-09 16:17:08 +08:00
|
|
|
m2.block(2,3,2,3) = m - m;
|
2007-09-07 16:18:21 +08:00
|
|
|
cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl;
|
|
|
|
|
2007-10-01 15:45:30 +08:00
|
|
|
cout << "Row 0 of m2 is:" << endl << m2.row(0) << endl;
|
|
|
|
cout << "The third element in that row is " << m2.row(0)[2] << endl;
|
2007-09-07 16:18:21 +08:00
|
|
|
cout << "Column 1 of m2 is:" << endl << m2.col(1) << endl;
|
2007-10-02 02:20:35 +08:00
|
|
|
cout << "The transpose of m2 is:" << endl << m2.transpose() << endl;
|
2007-09-07 16:18:21 +08:00
|
|
|
cout << "The matrix m2 with row 0 and column 1 removed is:" << endl << m2.minor(0,1) << endl;
|
2007-10-01 15:45:30 +08:00
|
|
|
|
2007-09-07 16:18:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|