From 16c7b1daabd2697950605706a8bc68ae32d70fc8 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 3 Sep 2009 11:17:16 +0200 Subject: add examples for makeJacobi and makeGivens --- Eigen/src/Jacobi/Jacobi.h | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'Eigen/src/Jacobi') diff --git a/Eigen/src/Jacobi/Jacobi.h b/Eigen/src/Jacobi/Jacobi.h index 66ba06b19..3e3cce665 100644 --- a/Eigen/src/Jacobi/Jacobi.h +++ b/Eigen/src/Jacobi/Jacobi.h @@ -26,16 +26,23 @@ #ifndef EIGEN_JACOBI_H #define EIGEN_JACOBI_H -/** \ingroup Jacobi +/** \ingroup Jacobi_Module + * \jacobi_module * \class PlanarRotation * \brief Represents a rotation in the plane from a cosine-sine pair. * * This class represents a Jacobi or Givens rotation. - * This is a 2D clock-wise rotation in the plane \c J of angle \f$ \theta \f$ defined by + * This is a 2D rotation in the plane \c J of angle \f$ \theta \f$ defined by * its cosine \c c and sine \c s as follow: * \f$ J = \left ( \begin{array}{cc} c & \overline s \\ -s & \overline c \end{array} \right ) \f$ * - * \sa MatrixBase::makeJacobi(), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() + * You can apply the respective counter-clockwise rotation to a column vector \c v by + * applying its adjoint on the left: \f$ v = J^* v \f$ that translates to the following Eigen code: + * \code + * v.applyOnTheLeft(J.adjoint()); + * \endcode + * + * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() */ template class PlanarRotation { @@ -79,11 +86,10 @@ template class PlanarRotation Scalar m_c, m_s; }; -/** Makes \c *this as a Jacobi rotation \a J such that applying \a J on both the right and left sides of the 2x2 matrix - * \f$ B = \left ( \begin{array}{cc} x & y \\ * & z \end{array} \right )\f$ yields - * a diagonal matrix \f$ A = J^* B J \f$ +/** Makes \c *this as a Jacobi rotation \a J such that applying \a J on both the right and left sides of the selfadjoint 2x2 matrix + * \f$ B = \left ( \begin{array}{cc} x & y \\ * & z \end{array} \right )\f$ yields a diagonal matrix \f$ A = J^* B J \f$ * - * \sa MatrixBase::makeJacobi(), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() + * \sa MatrixBase::makeJacobi(const MatrixBase&, int, int), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() */ template bool PlanarRotation::makeJacobi(RealScalar x, Scalar y, RealScalar z) @@ -116,10 +122,13 @@ bool PlanarRotation::makeJacobi(RealScalar x, Scalar y, RealScalar z) } } -/** Makes \c *this as a Jacobi rotation \c J such that applying \a J on both the right and left sides of the 2x2 matrix +/** Makes \c *this as a Jacobi rotation \c J such that applying \a J on both the right and left sides of the 2x2 selfadjoint matrix * \f$ B = \left ( \begin{array}{cc} \text{this}_{pp} & \text{this}_{pq} \\ * & \text{this}_{qq} \end{array} \right )\f$ yields * a diagonal matrix \f$ A = J^* B J \f$ * + * Example: \include Jacobi_makeJacobi.cpp + * Output: \verbinclude Jacobi_makeJacobi.out + * * \sa PlanarRotation::makeJacobi(RealScalar, Scalar, RealScalar), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() */ template @@ -136,6 +145,9 @@ inline bool PlanarRotation::makeJacobi(const MatrixBase& m, int * The value of \a z is returned if \a z is not null (the default is null). * Also note that G is built such that the cosine is always real. * + * Example: \include Jacobi_makeGivens.cpp + * Output: \verbinclude Jacobi_makeGivens.out + * * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() */ template @@ -171,9 +183,11 @@ void PlanarRotation::makeGivens(const Scalar& p, const Scalar& q, Scalar } // specialization for reals +// TODO compute z template void PlanarRotation::makeGivens(const Scalar& p, const Scalar& q, Scalar* z, ei_meta_false) { + ei_assert(z==0 && "not implemented yet"); // from Golub's "Matrix Computations", algorithm 5.1.3 if(q==0) { @@ -197,7 +211,8 @@ void PlanarRotation::makeGivens(const Scalar& p, const Scalar& q, Scalar * Implementation of MatrixBase methods ****************************************************************************************/ -/** Applies the clock wise 2D rotation \a j to the set of 2D vectors of cordinates \a x and \a y: +/** \jacobi_module + * Applies the clock wise 2D rotation \a j to the set of 2D vectors of cordinates \a x and \a y: * \f$ \left ( \begin{array}{cc} x \\ y \end{array} \right ) = J \left ( \begin{array}{cc} x \\ y \end{array} \right ) \f$ * * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() @@ -205,7 +220,8 @@ void PlanarRotation::makeGivens(const Scalar& p, const Scalar& q, Scalar template void ei_apply_rotation_in_the_plane(VectorX& _x, VectorY& _y, const PlanarRotation& j); -/** Applies the rotation in the plane \a j to the rows \a p and \a q of \c *this, i.e., it computes B = J * B, +/** \jacobi_module + * Applies the rotation in the plane \a j to the rows \a p and \a q of \c *this, i.e., it computes B = J * B, * with \f$ B = \left ( \begin{array}{cc} \text{*this.row}(p) \\ \text{*this.row}(q) \end{array} \right ) \f$. * * \sa class PlanarRotation, MatrixBase::applyOnTheRight(), ei_apply_rotation_in_the_plane() @@ -219,7 +235,8 @@ inline void MatrixBase::applyOnTheLeft(int p, int q, const PlanarRotati ei_apply_rotation_in_the_plane(x, y, j); } -/** Applies the rotation in the plane \a j to the columns \a p and \a q of \c *this, i.e., it computes B = B * J +/** \ingroup Jacobi_Module + * Applies the rotation in the plane \a j to the columns \a p and \a q of \c *this, i.e., it computes B = B * J * with \f$ B = \left ( \begin{array}{cc} \text{*this.col}(p) & \text{*this.col}(q) \end{array} \right ) \f$. * * \sa class PlanarRotation, MatrixBase::applyOnTheLeft(), ei_apply_rotation_in_the_plane() -- cgit v1.2.3