o2scl_linalg Namespace Reference

The namespace for linear algebra classes and functions. More...


Data Structures

class  linear_solver
 A generic solver for the linear system $ A x = b $ [abstract base]. More...
class  linear_solver_lu
 Generic linear solver using LU decomposition. More...
class  linear_solver_qr
 Generic linear solver using QR decomposition. More...
class  linear_solver_hh
 Generic Householder linear solver. More...
class  gsl_solver_LU
 GSL solver by LU decomposition. More...
class  gsl_solver_QR
 GSL solver by QR decomposition. More...
class  gsl_solver_HH
 GSL Householder solver. More...

Functions

void create_givens (const double a, const double b, double &c, double &s)
 Desc.
template<class mat1_t , class mat2_t >
void apply_givens_qr (size_t M, size_t N, mat1_t &Q, mat2_t &R, size_t i, size_t j, double c, double s)
 Apply a rotation to matrices from the QR decomposition.
template<class mat1_t , class mat2_t >
void apply_givens_lq (size_t M, size_t N, mat1_t &Q, mat2_t &L, size_t i, size_t j, double c, double s)
 Apply a rotation to matrices from the LQ decomposition.
template<class vec_t >
void apply_givens_vec (vec_t &v, size_t i, size_t j, double c, double s)
 Apply a rotation to a vector, $ v \rightarrow G^{T} v $.
template<class mat_t , class vec_t >
int HH_solve (size_t n, mat_t &A, const vec_t &b, vec_t &x)
 Solve linear system after Householder decomposition.
template<class mat_t , class vec_t >
int HH_svx (size_t N, size_t M, mat_t &A, vec_t &x)
 Solve a linear system after Householder decomposition in place.
template<class vec_t >
double householder_transform (const size_t n, vec_t &v)
 Replace the vector v with a householder vector and a coefficient tau that annihilates the last n-1 elements of v.
template<class mat_t >
double householder_transform_subcol (mat_t &A, const size_t ir, const size_t ic, const size_t n)
 Compute the householder transform of a vector formed with the last n rows of a column of a matrix.
template<class vec_t , class mat_t >
int householder_hm (const size_t M, const size_t N, double tau, const vec_t &v, mat_t &A)
 Apply a householder transformation v,tau to matrix m.
template<class mat_t >
int householder_hm_sub (mat_t &M, const size_t ir, const size_t ic, const size_t nr, const size_t nc, const mat_t &M2, const size_t ir2, const size_t ic2, double tau)
 Apply a householder transformation v, tau to submatrix of m.
template<class vec_t >
int householder_hv (const size_t N, double tau, const vec_t &v, vec_t &w)
 Apply a householder transformation v to vector w.
template<class mat_t , class vec_t >
int householder_hv_sub (const mat_t &M, vec_t &w, double tau, const size_t ie, const size_t N)
 Apply a householder transformation v to vector w.
template<class mat1_t , class mat2_t >
int householder_hm_sub2 (const size_t M, const size_t ic, double tau, const mat1_t &mv, mat2_t &A)
 Special version of householder transformation for QR_unpack().
template<class mat_t >
int LU_decomp (const size_t N, mat_t &A, o2scl::permutation &p, int &signum)
 Compute the LU decomposition of the matrix A.
template<class mat_t , class vec_t >
int LU_solve (const size_t N, const mat_t &LU, const o2scl::permutation &p, const vec_t &b, vec_t &x)
 Solve a linear system after LU decomposition.
template<class mat_t , class vec_t >
int LU_svx (const size_t N, const mat_t &LU, const o2scl::permutation &p, vec_t &x)
 Solve a linear system after LU decomposition in place.
template<class mat_t , class vec_t >
int LU_refine (const size_t N, const mat_t &A, const mat_t &LU, const o2scl::permutation &p, const vec_t &b, vec_t &x, vec_t &residual)
 Refine the solution of a linear system.
template<class mat_t , class mat_col_t >
int LU_invert (const size_t N, const mat_t &LU, const o2scl::permutation &p, mat_t &inverse)
 Compute the inverse of a matrix from its LU decomposition.
template<class mat_t >
double LU_det (const size_t N, const mat_t &LU, int signum)
 Compute the determinant of a matrix from its LU decomposition.
template<class mat_t >
double LU_lndet (const size_t N, const mat_t &LU)
 Compute the logarithm of the absolute value of the determinant of a matrix from its LU decomposition.
template<class mat_t >
int LU_sgndet (const size_t N, const mat_t &LU, int signum)
 Compute the sign of the determinant of a matrix from its LU decomposition.
template<class mat_t , class vec_t >
int QR_decomp (size_t M, size_t N, mat_t &A, vec_t &tau)
 Compute the QR decomposition of matrix A.
template<class mat_t , class vec_t , class vec2_t >
int QR_solve (size_t N, const mat_t &QR, const vec_t &tau, const vec2_t &b, vec2_t &x)
 Solve the system A x = b using the QR factorization.
template<class mat_t , class vec_t , class vec2_t >
int QR_svx (size_t M, size_t N, const mat_t &QR, const vec_t &tau, vec2_t &x)
 Solve the system A x = b in place using the QR factorization.
template<class mat_t , class vec_t , class vec2_t >
int QR_QTvec (const size_t M, const size_t N, const mat_t &QR, const vec_t &tau, vec2_t &v)
 Form the product Q^T v from a QR factorized matrix.
template<class mat1_t , class mat2_t , class mat3_t , class vec_t >
int QR_unpack (const size_t M, const size_t N, const mat1_t &QR, const vec_t &tau, mat2_t &Q, mat3_t &R)
 Unpack the QR matrix to the individual Q and R components.
template<class mat1_t , class mat2_t , class vec1_t , class vec2_t >
int QR_update (size_t M, size_t N, mat1_t &Q, mat2_t &R, vec1_t &w, vec2_t &v)
 Update a QR factorisation for A= Q R , A' = A + u v^T,.
template<class vec_t , class vec2_t >
int solve_tridiag_sym (const vec_t &diag, const vec2_t &offdiag, const vec_t &b, vec_t &x, size_t N)
 Solve a symmetric tridiagonal linear system.
template<class vec_t , class vec2_t >
int solve_tridiag_nonsym (const vec_t &diag, const vec2_t &abovediag, const vec2_t &belowdiag, const vec_t &rhs, vec_t &x, size_t N)
 Solve an asymmetric tridiagonal linear system.
template<class vec_t >
int solve_cyc_tridiag_sym (const vec_t &diag, const vec_t &offdiag, const vec_t &b, vec_t &x, size_t N)
 Solve a symmetric cyclic tridiagonal linear system.
template<class vec_t >
int solve_cyc_tridiag_nonsym (const vec_t &diag, const vec_t &abovediag, const vec_t &belowdiag, const vec_t &rhs, vec_t &x, size_t N)
 Solve an asymmetric cyclic tridiagonal linear system.


Detailed Description

The namespace for linear algebra classes and functions.

This namespace documentation is in the file src/base/lib_settings.h


Function Documentation

void o2scl_linalg::apply_givens_lq ( size_t  M,
size_t  N,
mat1_t &  Q,
mat2_t &  L,
size_t  i,
size_t  j,
double  c,
double  s 
) [inline]

Apply a rotation to matrices from the LQ decomposition.

This performs $ Q \rightarrow Q G $ and $ L \rightarrow L G^{T} $.

Definition at line 83 of file givens_base.h.

void o2scl_linalg::apply_givens_qr ( size_t  M,
size_t  N,
mat1_t &  Q,
mat2_t &  R,
size_t  i,
size_t  j,
double  c,
double  s 
) [inline]

Apply a rotation to matrices from the QR decomposition.

This performs $ Q \rightarrow Q G $ and $ R \rightarrow G^{T} R $.

Definition at line 57 of file givens_base.h.

int o2scl_linalg::householder_hm_sub ( mat_t &  M,
const size_t  ir,
const size_t  ic,
const size_t  nr,
const size_t  nc,
const mat_t &  M2,
const size_t  ir2,
const size_t  ic2,
double  tau 
) [inline]

Apply a householder transformation v, tau to submatrix of m.

Used in QR_decomp().

Definition at line 163 of file householder_base.h.

int o2scl_linalg::householder_hv_sub ( const mat_t &  M,
vec_t &  w,
double  tau,
const size_t  ie,
const size_t  N 
) [inline]

Apply a householder transformation v to vector w.

Used in QR_QTvec().

Definition at line 231 of file householder_base.h.

double o2scl_linalg::householder_transform_subcol ( mat_t &  A,
const size_t  ir,
const size_t  ic,
const size_t  n 
) [inline]

Compute the householder transform of a vector formed with the last n rows of a column of a matrix.

Used in QR_decomp().

Definition at line 95 of file householder_base.h.

int o2scl_linalg::LU_decomp ( const size_t  N,
mat_t &  A,
o2scl::permutation &  p,
int &  signum 
) [inline]

Compute the LU decomposition of the matrix A.

On output the diagonal and upper triangular part of the input matrix A contain the matrix U. The lower triangular part of the input matrix (excluding the diagonal) contains L. The diagonal elements of L are unity, and are not stored.

The permutation matrix P is encoded in the permutation p. The j-th column of the matrix P is given by the k-th column of the identity matrix, where k = p_j the j-th element of the permutation vector. The sign of the permutation is given by signum. It has the value (-1)^n, where n is the number of interchanges in the permutation.

The algorithm used in the decomposition is Gaussian Elimination with partial pivoting (Golub & Van Loan, Matrix Computations, Algorithm 3.4.1).

Idea for future:
The "swap rows j and i_pivot" section could probably be made more efficient using a "matrix_row"-like object.

Definition at line 73 of file lu_base.h.

double o2scl_linalg::LU_det ( const size_t  N,
const mat_t &  LU,
int  signum 
) [inline]

Compute the determinant of a matrix from its LU decomposition.

These functions compute the determinant of a matrix A from its LU decomposition, LU. The determinant is computed as the product of the diagonal elements of U and the sign of the row permutation signum.

Definition at line 252 of file lu_base.h.

int o2scl_linalg::LU_invert ( const size_t  N,
const mat_t &  LU,
const o2scl::permutation &  p,
mat_t &  inverse 
) [inline]

Compute the inverse of a matrix from its LU decomposition.

These functions compute the inverse of a matrix A from its LU decomposition (LU,p), storing the result in the matrix inverse. The inverse is computed by solving the system A x = b for each column of the identity matrix. It is preferable to avoid direct use of the inverse whenever possible, as the linear solver functions can obtain the same result more efficiently and reliably (consult any introductory textbook on numerical linear algebra for details).

Idea for future:
could rewrite to avoid mat_col_t

Definition at line 217 of file lu_base.h.

double o2scl_linalg::LU_lndet ( const size_t  N,
const mat_t &  LU 
) [inline]

Compute the logarithm of the absolute value of the determinant of a matrix from its LU decomposition.

These functions compute the logarithm of the absolute value of the determinant of a matrix A, $ \ln|\det(A)| $, from its LU decomposition, LU. This function may be useful if the direct computation of the determinant would overflow or underflow.

Definition at line 275 of file lu_base.h.

int o2scl_linalg::LU_refine ( const size_t  N,
const mat_t &  A,
const mat_t &  LU,
const o2scl::permutation &  p,
const vec_t &  b,
vec_t &  x,
vec_t &  residual 
) [inline]

Refine the solution of a linear system.

These functions apply an iterative improvement to x, the solution of A x = b, using the LU decomposition of A into (LU,p). The initial residual r = A x - b is also computed and stored in residual.

Definition at line 184 of file lu_base.h.

int o2scl_linalg::LU_sgndet ( const size_t  N,
const mat_t &  LU,
int  signum 
) [inline]

Compute the sign of the determinant of a matrix from its LU decomposition.

These functions compute the sign or phase factor of the determinant of a matrix A, $ \det(A)/|\det(A)| $, from its LU decomposition, LU.

Definition at line 296 of file lu_base.h.

int o2scl_linalg::LU_solve ( const size_t  N,
const mat_t &  LU,
const o2scl::permutation &  p,
const vec_t &  b,
vec_t &  x 
) [inline]

Solve a linear system after LU decomposition.

This function solve the square system A x = b using the LU decomposition of A into (LU, p) given by gsl_linalg_LU_decomp or gsl_linalg_complex_LU_decomp.

Definition at line 135 of file lu_base.h.

int o2scl_linalg::LU_svx ( const size_t  N,
const mat_t &  LU,
const o2scl::permutation &  p,
vec_t &  x 
) [inline]

Solve a linear system after LU decomposition in place.

These functions solve the square system A x = b in-place using the LU decomposition of A into (LU,p). On input x should contain the right-hand side b, which is replaced by the solution on output.

Definition at line 156 of file lu_base.h.

int o2scl_linalg::QR_update ( size_t  M,
size_t  N,
mat1_t &  Q,
mat2_t &  R,
vec1_t &  w,
vec2_t &  v 
) [inline]

Update a QR factorisation for A= Q R , A' = A + u v^T,.

M and N are the number of rows and columns of R.

      * Q' R' = QR + u v^T
      *       = Q (R + Q^T u v^T)
      *       = Q (R + w v^T)
      *
      * where w = Q^T u.
      *
      * Algorithm from Golub and Van Loan, "Matrix Computations", Section
      * 12.5 (Updating Matrix Factorizations, Rank-One Changes)
      

Definition at line 166 of file qr_base.h.

int o2scl_linalg::solve_cyc_tridiag_nonsym ( const vec_t &  diag,
const vec_t &  abovediag,
const vec_t &  belowdiag,
const vec_t &  rhs,
vec_t &  x,
size_t  N 
) [inline]

Solve an asymmetric cyclic tridiagonal linear system.

This function solves the following system w/o the corner elements and then use Sherman-Morrison formula to compensate for them

      *
      *        diag[0]  abovediag[0]             0   .....  belowdiag[N-1]
      *   belowdiag[0]       diag[1]  abovediag[1]   .....
      *              0  belowdiag[1]       diag[2]
      *              0             0  belowdiag[2]   .....
      *            ...           ...
      * abovediag[N-1]           ...
      

Definition at line 319 of file tridiag_base.h.

int o2scl_linalg::solve_cyc_tridiag_sym ( const vec_t &  diag,
const vec_t &  offdiag,
const vec_t &  b,
vec_t &  x,
size_t  N 
) [inline]

Solve a symmetric cyclic tridiagonal linear system.

Todo:
Put reference in correctly.
For a description of the method see [Engeln-Mullges + Uhlig, p. 96]
      *
      *      diag[0]  offdiag[0]             0   .....  offdiag[N-1]
      *   offdiag[0]     diag[1]    offdiag[1]   .....
      *            0  offdiag[1]       diag[2]
      *            0           0    offdiag[2]   .....
      *          ...         ...
      * offdiag[N-1]         ...
      

Definition at line 216 of file tridiag_base.h.

int o2scl_linalg::solve_tridiag_nonsym ( const vec_t &  diag,
const vec2_t &  abovediag,
const vec2_t &  belowdiag,
const vec_t &  rhs,
vec_t &  x,
size_t  N 
) [inline]

Solve an asymmetric tridiagonal linear system.

This function uses plain gauss elimination, only not bothering with the zeroes.

      * 
      *       diag[0]  abovediag[0]             0   .....
      *  belowdiag[0]       diag[1]  abovediag[1]   .....
      *             0  belowdiag[1]       diag[2]
      *             0             0  belowdiag[2]   .....
      

Definition at line 145 of file tridiag_base.h.

int o2scl_linalg::solve_tridiag_sym ( const vec_t &  diag,
const vec2_t &  offdiag,
const vec_t &  b,
vec_t &  x,
size_t  N 
) [inline]

Solve a symmetric tridiagonal linear system.

Idea for future:
Convert into class for memory managment and combine with other functions below
For description of method see [Engeln-Mullges + Uhlig, p. 92]
      *
      *     diag[0]  offdiag[0]             0   .....
      *  offdiag[0]     diag[1]    offdiag[1]   .....
      *           0  offdiag[1]       diag[2]
      *           0           0    offdiag[2]   .....
      

Definition at line 68 of file tridiag_base.h.


Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page