From 8afaeb4ad5fbcde1fb25ab5c8f9a9d120db4b13b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 20 Aug 2008 13:07:46 +0000 Subject: doc fixes, and extended Basic Linear Algebra and Reductions sections --- doc/QuickStartGuide.dox | 141 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 109 insertions(+), 32 deletions(-) (limited to 'doc/QuickStartGuide.dox') diff --git a/doc/QuickStartGuide.dox b/doc/QuickStartGuide.dox index cff5cafe5..0128ded7b 100644 --- a/doc/QuickStartGuide.dox +++ b/doc/QuickStartGuide.dox @@ -153,53 +153,130 @@ Eigen's comma initializer usually yields to very optimized code without any over

Basic Linear Algebra

-As long as you use mathematically well defined operators, you can basically write your matrix -and vector expressions using standard arithmetic operators: +In short all mathematically well defined operators can be used right away as in the following exemple: \code -mat1 = mat1*1.5 + mat2 * mat3/4; +mat4 -= mat1*1.5 + mat2 * mat3/4; \endcode +which includes two matrix scalar products ("mat1*1.5" and "mat3/4"), a matrix-matrix product ("mat2 * mat3/4"), +a matrix addition ("+") and substraction with assignment ("-="). -\b dot \b product (inner product): -\code -scalar = vec1.dot(vec2); -\endcode - -\b outer \b product: -\code -mat = vec1 * vec2.transpose(); -\endcode - -\b cross \b product: The cross product is defined in the Geometry module, you therefore have to include it first: -\code + + + + + + + +
+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 +
+dot product (inner product)\code +scalar = vec1.dot(vec2);\endcode +
+outer product\code +mat = vec1 * vec2.transpose();\endcode +
+cross product\code #include -vec3 = vec1.cross(vec2); -\endcode +vec3 = vec1.cross(vec2);\endcode
-By default, Eigen's only allows mathematically well defined operators. -However, thanks to the .cwise() operator prefix, Eigen's matrices also provide +In Eigen only mathematically well defined operators can be used right away, +but don't worry, thanks to the .cwise() operator prefix, Eigen's matrices also provide a very powerful numerical container supporting most common coefficient wise operators: - + + + + + + + + + +
Coefficient wise product\code mat3 = mat1.cwise() * mat2; \endcode +
+Add a scalar to all coefficients\code +mat3 = mat1.cwise() + scalar; +mat3.cwise() += scalar; +mat3.cwise() -= scalar; +\endcode +
+Coefficient wise division\code +mat3 = mat1.cwise() / mat2; \endcode +
+Coefficient wise reciprocal\code +mat3 = mat1.cwise().inverse(); \endcode +
+Coefficient wise comparisons \n +(support all operators)\code +mat3 = mat1.cwise() < mat2; +mat3 = mat1.cwise() <= mat2; +mat3 = mat1.cwise() > mat2; +etc. +\endcode +
+Trigo:\n sin, cos, tan\code +mat3 = mat1.cwise().sin(); +etc. +\endcode +
+Power:\n pow, square, cube, sqrt, exp, log\code +mat3 = mat1.cwise().square(); +mat3 = mat1.cwise().pow(5); +mat3 = mat1.cwise().log(); +etc. +\endcode +
+min, max, absolute value\code +mat3 = mat1.cwise().min(mat2); +mat3 = mat1.cwise().max(mat2); +mat3 = mat1.cwise().abs(mat2); +mat3 = mat1.cwise().abs2(mat2); +\endcode
-* Coefficient wise product: \code mat3 = mat1.cwise() * mat2; \endcode -* Coefficient wise division: \code mat3 = mat1.cwise() / mat2; \endcode -* Coefficient wise reciprocal: \code mat3 = mat1.cwise().inverse(); \endcode -* Add a scalar to a matrix: \code mat3 = mat1.cwise() + scalar; \endcode -* Coefficient wise comparison: \code mat3 = mat1.cwise() < mat2; \endcode -* Finally, \c .cwise() offers many common numerical functions including abs, pow, exp, sin, cos, tan, e.g.: -\code mat3 = mat1.cwise().sin(); \endcode

Reductions

-\code -scalar = mat.sum(); scalar = mat.norm(); scalar = mat.minCoeff(); -vec = mat.colwise().sum(); vec = mat.colwise().norm(); vec = mat.colwise().minCoeff(); -vec = mat.rowwise().sum(); vec = mat.rowwise().norm(); vec = mat.rowwise().minCoeff(); +Reductions can be done matrix-wise, column-wise or row-wise, e.g.: + + + + + + + + +
\code mat \endcode +\code +5 3 1 +2 7 8 +9 4 6 \endcode -Other natively supported reduction operations include maxCoeff(), norm2(), all() and any(). +
\code mat.minCoeff(); \endcode\code 1 \endcode
\code mat.maxCoeff(); \endcode\code 9 \endcode
\code mat.colwise().minCoeff(); \endcode\code 2 3 1 \endcode
\code mat.colwise().maxCoeff(); \endcode\code 9 7 8 \endcode
\code mat.rowwise().minCoeff(); \endcode\code +1 +2 +4 +\endcode
\code mat.rowwise().maxCoeff(); \endcode\code +5 +8 +9 +\endcode
+Eigen provides several other reduction methods such as sum(), norm(), norm2(), all(), and any(). +The all() and any() functions are especially useful in combinaison with coeff-wise comparison operators.

Sub matrices

-- cgit v1.2.3