LAL  7.5.0.1-ec27e42
MatrixUtils.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Teviet Creighton
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #ifndef _MATRIXUTILS_H
21 #define _MATRIXUTILS_H
22 
23 #include <lal/LALStdlib.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /**
30  * \defgroup MatrixUtils_h Header MatrixUtils.h
31  * \ingroup lal_utilities
32  * \author Creighton, T. D.
33  *
34  * \brief Provides routines to solve linear systems.
35  *
36  * ### Synopsis ###
37  *
38  * \code
39  * #include <lal/MatrixUtils.h>
40  * \endcode
41  *
42  * This header covers routines to solve linear systems of equations and
43  * eigensystems, using algorithms adapted from Chapters~2 and~11 of
44  * Numerical Recipes \cite ptvf1992 . The only routines at present are
45  * for computing eigenvalues and eigenvectors of real symmetric matrices.
46  * Routines for inverting or computing the determinant of arbitrary
47  * square matrices will likely follow.
48  *
49  * ### Notation ###
50  *
51  * A \e matrix is represented in LAL by a <tt><datatype>Array</tt>
52  * structure with a <tt>dimLength->length</tt> field of 2; the
53  * <tt>dimLength->data</tt> field gives the dimensions \f$[M,N]\f$ of the
54  * matrix. Using the place-index notation common in tensor calculus, a
55  * matrix is a two-index tensor:
56  * \f{equation}{
57  * \mathsf{A}^a{}_b = \left[\begin{array}{cccc}
58  * A^1{}_1 & A^1{}_2 & \cdots & A^1{}_N \\
59  * A^2{}_1 & A^2{}_2 & \cdots & A^2{}_N \\
60  * \vdots & \vdots & \ddots & \vdots \\
61  * A^M{}_1 & A^M{}_2 & \cdots & A^M{}_N
62  * \end{array}\right] \;,
63  * \f}
64  * that is, the first (raised) index represents the row number and the
65  * second (lowered) index the column number. The standard C array
66  * structure declares this object as, say, <tt>float a[M][N]</tt>, where
67  * the element \f$A^i{}_j\f$ is stored in <tt>a[i][j]</tt>. The LAL array
68  * structure <tt>REAL4Array a</tt> stores data in a flattened block of
69  * memory, where the element \f$A^i{}_j\f$ is stored in <tt>a.data[i*M+j]</tt>.
70  *
71  * A <em>row vector</em> is a matrix with only one row (\f$M=1\f$). In the
72  * above place-index notation, it is represented with a single lowered
73  * index:
74  * \f{equation}{
75  * \mathsf{r}_a = \left[\begin{array}{cccc} r_1 & r_2 & \cdots & r_N
76  * \end{array}\right] \;.
77  * \f}
78  * A <em>column vector</em> is a matrix with only one column (\f$N=1\f$). In
79  * the above place-index notation, it is represented with a single raised
80  * index:
81  * \f{equation}{
82  * \mathsf{c}^a = \left[\begin{array}{c} c^1 \\ c^2 \\ \vdots \\ c^M
83  * \end{array}\right] \;.
84  * \f}
85  * In LAL, both of these objects are conventionally represented as a LAL
86  * vector structure. Whether the object is to be used as a row or column
87  * vector must be determined from context; it is not specified by the
88  * datatype.
89  *
90  * ### Properties ###
91  *
92  * The basic matrix operations are addition, scalar multiplication, and
93  * vector multiplication. We assume the reader is familiar with these.
94  * In addition, we will refer to the following unary operations on
95  * \e square matrices:
96  *
97  * \e Inversion: The inverse \f$(\mathsf{A}^{-1}){}^a{}_b\f$ of a
98  * matrix \f$\mathsf{A}^a{}_b\f$ is one such that their matrix product is the
99  * identity matrix \f$\delta^a{}_b\f$ (whose elements \f$\delta^i{}_j\f$ are just
100  * the Kronecker delta function).
101  *
102  * \e Transposition: The transpose \f$(\mathsf{A}^T){}^a{}_b\f$ of a
103  * matrix \f$\mathsf{A}^a{}_b\f$ is given by interchanging the indecies on
104  * each component: \f$(A^T){}^i{}_j=A^j{}_i\f$.
105  *
106  * \e Conjugation: The Hermitian conjugate (adjoint)
107  * \f$(\mathsf{A}^\dag){}^a{}_b\f$ of a matrix \f$\mathsf{A}^a{}_b\f$ is given by
108  * interchanging the indecies and taking the complex conjugate of each
109  * component: \f$(A^\dag){}^i{}_j={A^j{}_i}^*\f$.
110  *
111  * A matrix that is identical to its own transpose is called
112  * \e symmetric. A matrix whose transpose is identical to the
113  * original matrix's inverse is called \e orthogonal. A matrix that
114  * is identical to its own Hermitian conjugate is called \e Hermitian
115  * (or <em>self-adjoint</em>. A matrix whose Hermitian conjugate is
116  * identical to the original matrix's inverse is called \e unitary.
117  *
118  * At present, the routines under this header only deal with \e real
119  * matrices (i.e.\ matrices, vectors, and scalars whose components are
120  * all real). In this case, symmetric is equivalent to Hermitian, and
121  * orthogonal is equivalent to unitary.
122  *
123  */
124 /** @{ */
125 
126 /** \name Error Codes */
127 /** @{ */
128 #define MATRIXUTILSH_ENUL 1 /**< Unexpected null pointer in arguments */
129 #define MATRIXUTILSH_EDIM 2 /**< Bad matrix dimensions */
130 #define MATRIXUTILSH_EITER 3 /**< Did not converge after maximum iterations */
131 #define MATRIXUTILSH_ESING 4 /**< Singular matrix */
132 #define MATRIXUTILSH_EMEM 5 /**< Memory allocation error */
133 /** @} */
134 
135 /** @} */
136 
137 #define MATRIXUTILSH_MSGENUL "Unexpected null pointer in arguments"
138 #define MATRIXUTILSH_MSGEDIM "Bad matrix dimensions"
139 #define MATRIXUTILSH_MSGEITER "Did not converge after maximum iterations"
140 #define MATRIXUTILSH_MSGESING "Singular matrix"
141 #define MATRIXUTILSH_MSGEMEM "Memory allocation error"
142 
143 
144 /* ---------- Function prototypes. ---------- */
145 /** \addtogroup MatrixOps_c */
146 /** @{ */
147 void
149 
150 void
152 /** @} */
153 
154 
155 void
156 LALSMatrixInverse( LALStatus *, REAL4 *det, REAL4Array *matrix, REAL4Array *inverse );
157 
158 void
159 LALDMatrixDeterminant( LALStatus *, REAL8 *det, REAL8Array *matrix );
160 
161 void
162 LALDMatrixInverse( LALStatus *, REAL8 *det, REAL8Array *matrix, REAL8Array *inverse );
163 
164 void
165 LALDMatrixDeterminantErr( LALStatus *, REAL8 det[2], REAL8Array *matrix, REAL8Array *matrixErr );
166 
167 
168 void
170 
171 void
173 
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif /* _MATRIXUTILS_H */
void LALDMatrixInverse(LALStatus *, REAL8 *det, REAL8Array *matrix, REAL8Array *inverse)
Definition: DetInverse.c:734
void LALDMatrixDeterminant(LALStatus *, REAL8 *det, REAL8Array *matrix)
Definition: DetInverse.c:691
void LALSMatrixInverse(LALStatus *, REAL4 *det, REAL4Array *matrix, REAL4Array *inverse)
Definition: DetInverse.c:616
void LALDMatrixDeterminantErr(LALStatus *, REAL8 det[2], REAL8Array *matrix, REAL8Array *matrixErr)
Definition: DetInverse.c:808
void LALDSymmetricEigenVectors(LALStatus *, REAL8Vector *values, REAL8Array *matrix)
Definition: Eigen.c:772
void LALSSymmetricEigenVectors(LALStatus *, REAL4Vector *values, REAL4Array *matrix)
Definition: Eigen.c:734
double REAL8
Double precision real floating-point number (8 bytes).
float REAL4
Single precision real floating-point number (4 bytes).
void LALDMatrixMultiply(LALStatus *, REAL8Array *out, REAL8Array *in1, REAL8Array *in2)
Definition: MatrixOps.c:71
void LALDMatrixTranspose(LALStatus *, REAL8Array *out, REAL8Array *in1)
Definition: MatrixOps.c:128
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
Multidimentional array of REAL4, see DATATYPE-Array types for more details.
Definition: LALDatatypes.h:220
Vector of type REAL4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:145
Multidimentional array of REAL8, see DATATYPE-Array types for more details.
Definition: LALDatatypes.h:226
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154