mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Extend tutorial page 5: Advanced initialization.
This commit is contained in:
5
doc/snippets/Tutorial_AdvancedInitialization_Block.cpp
Normal file
5
doc/snippets/Tutorial_AdvancedInitialization_Block.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
MatrixXf matA(2, 2);
|
||||
matA << 1, 2, 3, 4;
|
||||
MatrixXf matB(4, 4);
|
||||
matB << matA, matA/10, matA/10, matA;
|
||||
std::cout << matB << std::endl;
|
||||
@@ -0,0 +1,4 @@
|
||||
MatrixXf mat = MatrixXf::Random(2, 3);
|
||||
std::cout << mat << std::endl << std::endl;
|
||||
mat = (MatrixXf(2,2) << 0, 1, 1, 0).finished() * mat;
|
||||
std::cout << mat << std::endl;
|
||||
@@ -0,0 +1,7 @@
|
||||
ArrayXXf table(10, 4);
|
||||
table.col(0) = ArrayXf::LinSpaced(10, 0, 90);
|
||||
table.col(1) = M_PI / 180 * table.col(0);
|
||||
table.col(2) = table.col(1).sin();
|
||||
table.col(3) = table.col(1).cos();
|
||||
std::cout << " Degrees Radians Sine Cosine\n";
|
||||
std::cout << table << std::endl;
|
||||
20
doc/snippets/Tutorial_AdvancedInitialization_ThreeWays.cpp
Normal file
20
doc/snippets/Tutorial_AdvancedInitialization_ThreeWays.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
const int size = 6;
|
||||
MatrixXd mat1(size, size);
|
||||
mat1.topLeftCorner(size/2, size/2) = MatrixXd::Zero(size/2, size/2);
|
||||
mat1.topRightCorner(size/2, size/2) = MatrixXd::Identity(size/2, size/2);
|
||||
mat1.bottomLeftCorner(size/2, size/2) = MatrixXd::Identity(size/2, size/2);
|
||||
mat1.bottomRightCorner(size/2, size/2) = MatrixXd::Zero(size/2, size/2);
|
||||
std::cout << mat1 << std::endl << std::endl;
|
||||
|
||||
MatrixXd mat2(size, size);
|
||||
mat2.topLeftCorner(size/2, size/2).setZero();
|
||||
mat2.topRightCorner(size/2, size/2).setIdentity();
|
||||
mat2.bottomLeftCorner(size/2, size/2).setIdentity();
|
||||
mat2.bottomRightCorner(size/2, size/2).setZero();
|
||||
std::cout << mat2 << std::endl << std::endl;
|
||||
|
||||
MatrixXd mat3(size, size);
|
||||
mat3 << MatrixXd::Zero(size/2, size/2), MatrixXd::Identity(size/2, size/2),
|
||||
MatrixXd::Identity(size/2, size/2), MatrixXd::Zero(size/2, size/2);
|
||||
std::cout << mat3 << std::endl;
|
||||
|
||||
13
doc/snippets/Tutorial_AdvancedInitialization_Zero.cpp
Normal file
13
doc/snippets/Tutorial_AdvancedInitialization_Zero.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
std::cout << "A fixed-size array:\n";
|
||||
Array33f a1 = Array33f::Zero();
|
||||
std::cout << a1 << "\n\n";
|
||||
|
||||
|
||||
std::cout << "A one-dimensional dynamic-size array:\n";
|
||||
ArrayXf a2 = ArrayXf::Zero(3);
|
||||
std::cout << a2 << "\n\n";
|
||||
|
||||
|
||||
std::cout << "A two-dimensional dynamic-size array:\n";
|
||||
ArrayXXf a3 = ArrayXXf::Zero(3, 4);
|
||||
std::cout << a3 << "\n";
|
||||
5
doc/snippets/Tutorial_commainit_01b.cpp
Normal file
5
doc/snippets/Tutorial_commainit_01b.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
Matrix3f m;
|
||||
m.row(0) << 1, 2, 3;
|
||||
m.block(1,0,2,2) << 4, 5, 7, 8;
|
||||
m.col(2).tail(2) << 6, 9;
|
||||
std::cout << m;
|
||||
Reference in New Issue
Block a user