mat2 Class Template Reference

Matrix class (2x2). More...

#include <mat2.h>

Inheritance diagram for mat2:

List of all members.

Public Types

typedef af::tiny_plain
< NumType, 4 > 
base_type

Public Member Functions

 mat2 ()
 Default constructor. Elements are not initialized.
 mat2 (NumType const &e00, NumType const &e01, NumType const &e10, NumType const &e11)
 Constructor.
 mat2 (base_type const &a)
 Constructor.
 mat2 (const NumType *a)
 Constructor.
 mat2 (NumType const &diag)
 Constructor for diagonal matrix.
 mat2 (af::tiny_plain< NumType, 2 > const &diag)
 Constructor for diagonal matrix.
 mat2 (sym_mat2< NumType > const &m)
 Construction from symmetric matrix.
NumType const & operator() (std::size_t r, std::size_t c) const
 Access elements with 2-dimensional indices.
NumType & operator() (std::size_t r, std::size_t c)
 Access elements with 2-dimensional indices.
vec2< NumType > get_row (std::size_t i) const
 Return a row.
void set_row (std::size_t i, af::tiny_plain< NumType, 2 > const &v)
 Set a row.
void swap_rows (std::size_t i1, std::size_t i2)
 Swap two rows in place.
vec2< NumType > get_column (std::size_t i) const
 Return a column.
void set_column (std::size_t i, af::tiny_plain< NumType, 2 > const &v)
 Set a column.
void swap_columns (std::size_t i1, std::size_t i2)
 Swap two columns in place.
vec2< NumType > diagonal () const
 Return diagonal elements.
mat2 transpose () const
 Return the transposed matrix.
NumType trace () const
 Return trace (sum of diagonal elements).
NumType determinant () const
 Return determinant.
NumType max_abs () const
 Maximum of the absolute values of the elements of this matrix.
bool is_symmetric () const
 Test for symmetric matrix.
bool is_symmetric (NumType const &relative_tolerance) const
 Test for symmetric matrix.
mat2 co_factor_matrix_transposed () const
 Return the transposed of the co-factor matrix.
mat2 inverse () const
 Return the inverse matrix.
mat2 error_minimizing_inverse (std::size_t iterations) const
 Returns the inverse matrix, after minimizing the error numerically.
mat2scale (af::tiny_plain< NumType, 2 > const &v)
 Scale matrix in place.
mat2 ortho () const
 Return a matrix with orthogonal base vectors.
std::pair< mat2, vec2< NumType > > decompose () const
 Decomposes the matrix into a rotation and scaling part.
sym_mat2< NumType > self_times_self_transpose () const
 (*this) * this->transpose().
sym_mat2< NumType > self_transpose_times_self () const
 this->transpose() * (*this).
NumType dot (mat2 const &other)
 Sum of element-wise products.


Detailed Description

template<typename NumType>
class scitbx::mat2< NumType >

Matrix class (2x2).

This class represents a 2x2 matrix that can be used to store linear transformations.

A 2D adaptation of the scitbx::mat3 class


Member Function Documentation

bool is_symmetric (  )  const [inline]

Test for symmetric matrix.

Returns false iff the absolute value of the difference between any pair of off-diagonal elements is different from zero.

Referenced by sym_mat2< FloatType >::sym_mat2().

bool is_symmetric ( NumType const &  relative_tolerance  )  const [inline]

Test for symmetric matrix.

Returns false iff the absolute value of the difference between any pair of off-diagonal elements is larger than max_abs()*relative_tolerance.

References mat2::max_abs().

mat2 co_factor_matrix_transposed (  )  const [inline]

Return the transposed of the co-factor matrix.

The inverse matrix is obtained by dividing the result by the determinant().

References mat2::mat2().

Referenced by mat2::inverse().

mat2 inverse (  )  const [inline]

Return the inverse matrix.

An exception is thrown if the matrix is not invertible, i.e. if the determinant() is zero.

References mat2::co_factor_matrix_transposed(), and mat2::determinant().

Referenced by mat2::error_minimizing_inverse().

mat2 error_minimizing_inverse ( std::size_t  iterations  )  const [inline]

Returns the inverse matrix, after minimizing the error numerically.

Here's the theory: M*M^-1 = I-E, where E is the error M*M^-1*(I+E) = (I-E)*(I+E) M*(M^-1*(I+E)) = I^2-E^2 M*(M^-1*(I+E)) = I-E^2 let M^-1*(I+E) = M1 let E^2 = E2 M*M1*(I+E2) = (I-E2)*(I+E2) M*M2 = I-E4 M*Mi = I-E2^i Supposedly this will drive the error pretty low after only a few repetitions. The error rate should be ~E^(2^iterations), which I think is pretty good. This assumes that E is "<< 1", whatever that means. Attributed to Judah I. Rosenblatt.

2*I - (I-E) ==> 2*I - I + E = I + E

References mat2::inverse().

mat2& scale ( af::tiny_plain< NumType, 2 > const &  v  )  [inline]

Scale matrix in place.

Each row of this is multiplied element-wise with v.


The documentation for this class was generated from the following files:

Generated on Wed Oct 29 19:59:04 2008 for cctbx by  doxygen 1.5.6