namespace Eigen { /** \page TutorialCore Tutorial 1/3 - Core features \ingroup Tutorial
\b Table \b of \b contents - \ref TutorialCoreGettingStarted - \ref TutorialCoreSimpleExampleFixedSize - \ref TutorialCoreSimpleExampleDynamicSize - \ref TutorialCoreMatrixTypes - \ref TutorialCoreCoefficients - \ref TutorialCoreMatrixInitialization - \ref TutorialCoreArithmeticOperators - \ref TutorialCoreReductions - \ref TutorialCoreMatrixBlocks - \ref TutorialCoreDiagonalMatrices - \ref TutorialCoreTransposeAdjoint - \ref TutorialCoreDotNorm - \ref TutorialCoreTriangularMatrix - \ref TutorialCoreSelfadjointMatrix - \ref TutorialCoreSpecialTopics \n\include Tutorial_simple_example_fixed_size.cpp | output: \include Tutorial_simple_example_fixed_size.out |
\include Tutorial_simple_example_dynamic_size.cpp | output: \include Tutorial_simple_example_dynamic_size.out |
Fixed-size matrix or vector | Dynamic-size matrix | Dynamic-size vector |
\code Matrix3f x; x = Matrix3f::Zero(); x = Matrix3f::Ones(); x = Matrix3f::Constant(value); x = Matrix3f::Identity(); x = Matrix3f::Random(); x.setZero(); x.setOnes(); x.setIdentity(); x.setConstant(value); x.setRandom(); \endcode | \code MatrixXf x; x = MatrixXf::Zero(rows, cols); x = MatrixXf::Ones(rows, cols); x = MatrixXf::Constant(rows, cols, value); x = MatrixXf::Identity(rows, cols); x = MatrixXf::Random(rows, cols); x.setZero(rows, cols); x.setOnes(rows, cols); x.setConstant(rows, cols, value); x.setIdentity(rows, cols); x.setRandom(rows, cols); \endcode | \code VectorXf x; x = VectorXf::Zero(size); x = VectorXf::Ones(size); x = VectorXf::Constant(size, value); x = VectorXf::Identity(size); x = VectorXf::Random(size); x.setZero(size); x.setOnes(size); x.setConstant(size, value); N/A x.setRandom(size); \endcode |
\redstar the Random() and setRandom() functions require the inclusion of the Array module (\c \#include \c | ||
Basis vectors \link MatrixBase::Unit [details]\endlink | ||
\code Vector3f::UnitX() // 1 0 0 Vector3f::UnitY() // 0 1 0 Vector3f::UnitZ() // 0 0 1 \endcode | \code VectorXf::Unit(size,i) VectorXf::Unit(4,1) == Vector4f(0,1,0,0) == Vector4f::UnitY() \endcode |
\code cout << MatrixXf::Constant(2, 3, sqrt(2)) << endl; RowVector3i v; v.setConstant(6); cout << "v = " << v << endl; \endcode | output: \code 1.41 1.41 1.41 1.41 1.41 1.41 v = 6 6 6 \endcode |
\code
std::vector |
\include Tutorial_commainit_01.cpp | output: \verbinclude Tutorial_commainit_01.out |
\include Tutorial_commainit_02.cpp | output: \verbinclude Tutorial_commainit_02.out |
matrix/vector product | \code col2 = mat1 * col1; row2 = row1 * mat1; row1 *= mat1; mat3 = mat1 * mat2; mat3 *= mat1; \endcode |
add/subtract | \code mat3 = mat1 + mat2; mat3 += mat1; mat3 = mat1 - mat2; mat3 -= mat1;\endcode |
scalar product | \code mat3 = mat1 * s1; mat3 = s1 * mat1; mat3 *= s1; mat3 = mat1 / s1; mat3 /= s1;\endcode |
|
|
\link MatrixBase::dot() dot product \endlink (inner product) | \code scalar = vec1.dot(vec2);\endcode |
outer product | \code mat = vec1 * vec2.transpose();\endcode |
\link MatrixBase::cross() cross product \endlink | \code
#include |
\code 5 3 1 mat = 2 7 8 9 4 6 \endcode | \code mat.minCoeff(); \endcode | \code 1 \endcode |
\code mat.colwise().minCoeff(); \endcode | \code 2 3 1 \endcode | |
\code mat.rowwise().minCoeff(); \endcode | \code 1 2 4 \endcode |
Default versions | Optimized versions when the size \n is known at compile time | |
\code vec1.start(n)\endcode | \code vec1.start | the first \c n coeffs |
\code vec1.end(n)\endcode | \code vec1.end | the last \c n coeffs |
\code vec1.segment(pos,n)\endcode | \code vec1.segment |
the \c size coeffs in \n the range [\c pos : \c pos + \c n [ |
Read-write access to sub-matrices: | ||
\code mat1.block(i,j,rows,cols)\endcode \link MatrixBase::block(int,int,int,int) (more) \endlink | \code mat1.block |
the \c rows x \c cols sub-matrix \n starting from position (\c i,\c j) |
\code mat1.corner(TopLeft,rows,cols) mat1.corner(TopRight,rows,cols) mat1.corner(BottomLeft,rows,cols) mat1.corner(BottomRight,rows,cols)\endcode \link MatrixBase::corner(CornerType,int,int) (more) \endlink | \code
mat1.corner |
the \c rows x \c cols sub-matrix \n taken in one of the four corners |
\code mat4x4.minor(i,j) = mat3x3; mat3x3 = mat4x4.minor(i,j);\endcode | \link MatrixBase::minor() minor \endlink (read-write) |
\link MatrixBase::asDiagonal() make a diagonal matrix \endlink from a vector \n this product is automatically optimized ! | \code mat3 = mat1 * vec2.asDiagonal();\endcode |
Access \link MatrixBase::diagonal() the diagonal of a matrix \endlink as a vector (read/write) | \code vec1 = mat1.diagonal(); mat1.diagonal() = vec1; \endcode |
\link MatrixBase::transpose() transposition \endlink (read-write) | \code mat3 = mat1.transpose() * mat2; mat3.transpose() = mat1 * mat2.transpose(); \endcode |
\link MatrixBase::adjoint() adjoint \endlink (read only)\n | \code mat3 = mat1.adjoint() * mat2; \endcode |
\link MatrixBase::dot() Dot-product \endlink of two vectors | \code vec1.dot(vec2);\endcode |
\link MatrixBase::norm() norm \endlink of a vector \n \link MatrixBase::squaredNorm() squared norm \endlink of a vector | \code vec.norm(); \endcode \n \code vec.squaredNorm() \endcode |
returns a \link MatrixBase::normalized() normalized \endlink vector \n \link MatrixBase::normalize() normalize \endlink a vector | \code vec3 = vec1.normalized(); vec1.normalize();\endcode |
Reference a read/write triangular part of a given \n matrix (or expression) m with optional unit diagonal: | \code
m.triangularView |
Writting to a specific triangular part:\n (only the referenced triangular part is evaluated) | \code
m1.triangularView |
Convertion to a dense matrix setting the opposite triangular part to zero: | \code
m2 = m1.triangularView |
Products: | \code
m3 += s1 * m1.adjoint().triangularView |
Solving linear equations:\n(\f$ m_2 := m_1^{-1} m_2 \f$) | \code
m1.triangularView |
Conversion to a dense matrix: | \code
m2 = m.selfadjointView |
Product with another general matrix or vector: | \code
m3 = s1 * m1.conjugate().selfadjointView |
Rank 1 and rank K update: | \code
// fast version of m1 += s1 * m2 * m2.adjoint():
m1.selfadjointView |
Rank 2 update: (\f$ m += s u v^* + s v u^* \f$) | \code
m.selfadjointView |
Solving linear equations:\n(\f$ m_2 := m_1^{-1} m_2 \f$) | \code
// via a standard Cholesky factorization
m1.selfadjointView |