00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2009 Jitse Niesen <jitse@maths.leeds.ac.uk> 00005 // 00006 // Eigen is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 3 of the License, or (at your option) any later version. 00010 // 00011 // Alternatively, you can redistribute it and/or 00012 // modify it under the terms of the GNU General Public License as 00013 // published by the Free Software Foundation; either version 2 of 00014 // the License, or (at your option) any later version. 00015 // 00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY 00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License and a copy of the GNU General Public License along with 00023 // Eigen. If not, see <http://www.gnu.org/licenses/>. 00024 00025 #ifndef EIGEN_MATRIX_FUNCTIONS 00026 #define EIGEN_MATRIX_FUNCTIONS 00027 00028 #include <list> 00029 #include <functional> 00030 #include <iterator> 00031 00032 #include <Eigen/Core> 00033 #include <Eigen/LU> 00034 #include <Eigen/Eigenvalues> 00035 00036 namespace Eigen { 00037 00038 /** \ingroup Unsupported_modules 00039 * \defgroup MatrixFunctions_Module Matrix functions module 00040 * \ingroup eigen_grp 00041 * \ingroup eigen_grp 00042 * \brief This module aims to provide various methods for the computation of 00043 * matrix functions. 00044 * 00045 * To use this module, add 00046 * \code 00047 * #include <unsupported/Eigen/MatrixFunctions> 00048 * \endcode 00049 * at the start of your source file. 00050 * 00051 * This module defines the following MatrixBase methods. 00052 * - \ref matrixbase_cos "MatrixBase::cos()", for computing the matrix cosine 00053 * - \ref matrixbase_cosh "MatrixBase::cosh()", for computing the matrix hyperbolic cosine 00054 * - \ref matrixbase_exp "MatrixBase::exp()", for computing the matrix exponential 00055 * - \ref matrixbase_matrixfunction "MatrixBase::matrixFunction()", for computing general matrix functions 00056 * - \ref matrixbase_sin "MatrixBase::sin()", for computing the matrix sine 00057 * - \ref matrixbase_sinh "MatrixBase::sinh()", for computing the matrix hyperbolic sine 00058 * 00059 * These methods are the main entry points to this module. 00060 * 00061 * %Matrix functions are defined as follows. Suppose that \f$ f \f$ 00062 * is an entire function (that is, a function on the complex plane 00063 * that is everywhere complex differentiable). Then its Taylor 00064 * series 00065 * \f[ f(0) + f'(0) x + \frac{f''(0)}{2} x^2 + \frac{f'''(0)}{3!} x^3 + \cdots \f] 00066 * converges to \f$ f(x) \f$. In this case, we can define the matrix 00067 * function by the same series: 00068 * \f[ f(M) = f(0) + f'(0) M + \frac{f''(0)}{2} M^2 + \frac{f'''(0)}{3!} M^3 + \cdots \f] 00069 * 00070 */ 00071 00072 #include "src/MatrixFunctions/MatrixExponential.h" 00073 #include "src/MatrixFunctions/MatrixFunction.h" 00074 00075 00076 00077 /** 00078 \page matrixbaseextra MatrixBase methods defined in the MatrixFunctions module 00079 \ingroup MatrixFunctions_Module 00080 00081 The remainder of the page documents the following MatrixBase methods 00082 which are defined in the MatrixFunctions module. 00083 00084 00085 00086 \section matrixbase_cos MatrixBase::cos() 00087 00088 Compute the matrix cosine. 00089 00090 \code 00091 const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::cos() const 00092 \endcode 00093 00094 \param[in] M a square matrix. 00095 \returns expression representing \f$ \cos(M) \f$. 00096 00097 This function calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::cos(). 00098 00099 \sa \ref matrixbase_sin "sin()" for an example. 00100 00101 00102 00103 \section matrixbase_cosh MatrixBase::cosh() 00104 00105 Compute the matrix hyberbolic cosine. 00106 00107 \code 00108 const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::cosh() const 00109 \endcode 00110 00111 \param[in] M a square matrix. 00112 \returns expression representing \f$ \cosh(M) \f$ 00113 00114 This function calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::cosh(). 00115 00116 \sa \ref matrixbase_sinh "sinh()" for an example. 00117 00118 00119 00120 \section matrixbase_exp MatrixBase::exp() 00121 00122 Compute the matrix exponential. 00123 00124 \code 00125 const MatrixExponentialReturnValue<Derived> MatrixBase<Derived>::exp() const 00126 \endcode 00127 00128 \param[in] M matrix whose exponential is to be computed. 00129 \returns expression representing the matrix exponential of \p M. 00130 00131 The matrix exponential of \f$ M \f$ is defined by 00132 \f[ \exp(M) = \sum_{k=0}^\infty \frac{M^k}{k!}. \f] 00133 The matrix exponential can be used to solve linear ordinary 00134 differential equations: the solution of \f$ y' = My \f$ with the 00135 initial condition \f$ y(0) = y_0 \f$ is given by 00136 \f$ y(t) = \exp(M) y_0 \f$. 00137 00138 The cost of the computation is approximately \f$ 20 n^3 \f$ for 00139 matrices of size \f$ n \f$. The number 20 depends weakly on the 00140 norm of the matrix. 00141 00142 The matrix exponential is computed using the scaling-and-squaring 00143 method combined with Padé approximation. The matrix is first 00144 rescaled, then the exponential of the reduced matrix is computed 00145 approximant, and then the rescaling is undone by repeated 00146 squaring. The degree of the Padé approximant is chosen such 00147 that the approximation error is less than the round-off 00148 error. However, errors may accumulate during the squaring phase. 00149 00150 Details of the algorithm can be found in: Nicholas J. Higham, "The 00151 scaling and squaring method for the matrix exponential revisited," 00152 <em>SIAM J. %Matrix Anal. Applic.</em>, <b>26</b>:1179–1193, 00153 2005. 00154 00155 Example: The following program checks that 00156 \f[ \exp \left[ \begin{array}{ccc} 00157 0 & \frac14\pi & 0 \\ 00158 -\frac14\pi & 0 & 0 \\ 00159 0 & 0 & 0 00160 \end{array} \right] = \left[ \begin{array}{ccc} 00161 \frac12\sqrt2 & -\frac12\sqrt2 & 0 \\ 00162 \frac12\sqrt2 & \frac12\sqrt2 & 0 \\ 00163 0 & 0 & 1 00164 \end{array} \right]. \f] 00165 This corresponds to a rotation of \f$ \frac14\pi \f$ radians around 00166 the z-axis. 00167 00168 \include MatrixExponential.cpp 00169 Output: \verbinclude MatrixExponential.out 00170 00171 \note \p M has to be a matrix of \c float, \c double, 00172 \c complex<float> or \c complex<double> . 00173 00174 00175 00176 \section matrixbase_matrixfunction MatrixBase::matrixFunction() 00177 00178 Compute a matrix function. 00179 00180 \code 00181 const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::matrixFunction(typename internal::stem_function<typename internal::traits<Derived>::Scalar>::type f) const 00182 \endcode 00183 00184 \param[in] M argument of matrix function, should be a square matrix. 00185 \param[in] f an entire function; \c f(x,n) should compute the n-th 00186 derivative of f at x. 00187 \returns expression representing \p f applied to \p M. 00188 00189 Suppose that \p M is a matrix whose entries have type \c Scalar. 00190 Then, the second argument, \p f, should be a function with prototype 00191 \code 00192 ComplexScalar f(ComplexScalar, int) 00193 \endcode 00194 where \c ComplexScalar = \c std::complex<Scalar> if \c Scalar is 00195 real (e.g., \c float or \c double) and \c ComplexScalar = 00196 \c Scalar if \c Scalar is complex. The return value of \c f(x,n) 00197 should be \f$ f^{(n)}(x) \f$, the n-th derivative of f at x. 00198 00199 This routine uses the algorithm described in: 00200 Philip Davies and Nicholas J. Higham, 00201 "A Schur-Parlett algorithm for computing matrix functions", 00202 <em>SIAM J. %Matrix Anal. Applic.</em>, <b>25</b>:464–485, 2003. 00203 00204 The actual work is done by the MatrixFunction class. 00205 00206 Example: The following program checks that 00207 \f[ \exp \left[ \begin{array}{ccc} 00208 0 & \frac14\pi & 0 \\ 00209 -\frac14\pi & 0 & 0 \\ 00210 0 & 0 & 0 00211 \end{array} \right] = \left[ \begin{array}{ccc} 00212 \frac12\sqrt2 & -\frac12\sqrt2 & 0 \\ 00213 \frac12\sqrt2 & \frac12\sqrt2 & 0 \\ 00214 0 & 0 & 1 00215 \end{array} \right]. \f] 00216 This corresponds to a rotation of \f$ \frac14\pi \f$ radians around 00217 the z-axis. This is the same example as used in the documentation 00218 of \ref matrixbase_exp "exp()". 00219 00220 \include MatrixFunction.cpp 00221 Output: \verbinclude MatrixFunction.out 00222 00223 Note that the function \c expfn is defined for complex numbers 00224 \c x, even though the matrix \c A is over the reals. Instead of 00225 \c expfn, we could also have used StdStemFunctions::exp: 00226 \code 00227 A.matrixFunction(StdStemFunctions<std::complex<double> >::exp, &B); 00228 \endcode 00229 00230 00231 00232 \section matrixbase_sin MatrixBase::sin() 00233 00234 Compute the matrix sine. 00235 00236 \code 00237 const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::sin() const 00238 \endcode 00239 00240 \param[in] M a square matrix. 00241 \returns expression representing \f$ \sin(M) \f$. 00242 00243 This function calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::sin(). 00244 00245 Example: \include MatrixSine.cpp 00246 Output: \verbinclude MatrixSine.out 00247 00248 00249 00250 \section matrixbase_sinh const MatrixBase::sinh() 00251 00252 Compute the matrix hyperbolic sine. 00253 00254 \code 00255 MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::sinh() const 00256 \endcode 00257 00258 \param[in] M a square matrix. 00259 \returns expression representing \f$ \sinh(M) \f$ 00260 00261 This function calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::sinh(). 00262 00263 Example: \include MatrixSinh.cpp 00264 Output: \verbinclude MatrixSinh.out 00265 00266 */ 00267 00268 } 00269 00270 #endif // EIGEN_MATRIX_FUNCTIONS 00271
| Page generated by Doxygen 1.7.4 for MRPT 0.9.5 SVN:2717 at Sun Oct 16 16:08:03 PDT 2011 | Hosted on: |