casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MatrixMath.h
Go to the documentation of this file.
00001 //# MatrixMath.h: The AIPS++ Linear Algebra Functions
00002 //# Copyright (C) 1994,1995,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 //# Includes
00029 
00030 #include <casa/aips.h>
00031 #include <casa/BasicSL/Complex.h>
00032 
00033 #define AIPS_ARRAY_INDEX_CHECK
00034 
00035 //# Forward Declarations
00036 template <class T> class Vector;
00037 template <class T> class Matrix;
00038 template <class T> class LUdecomp;
00039 
00040 // <thrown> 
00041 //   <item> ArrayError
00042 //   <item> BlasError
00043 // </thrown>
00044 
00045 //<div><title> The AIPS++ Linear Algebra Functions </title>
00046 
00047 // 
00048 // The scalar/dot/inner product of two equal length vectors.
00049 //
00050 template <class T> T innerProduct (const Vector<T> &x, const Vector<T> &y);
00051 
00052 //
00053 // The magnitude/norm of a vector.
00054 //
00055 template <class T> T norm (const Vector<T> &x);
00056 
00057 //
00058 // Create a 3D rotation matrix (3x3).
00059 // Axis is 0,1,2 for x,y,z; angle is in radians.
00060 //
00061 template <class T> Matrix<T> Rot3D(Int axis, T angle);
00062 
00063 //
00064 // The vector/cross product of two 3-space vectors.
00065 //
00066 template <class T> 
00067    Vector<T> crossProduct (const Vector<T> &x, const Vector<T> &y);
00068 
00069 //
00070 // The matrix/outer product of a vector and a transposed vector. 
00071 // <note> The function's second argument is actually a transposed vector
00072 // stored as the only row in a 1xN matrix.
00073 // </note>
00074 //
00075 template <class T>
00076    Matrix<T> product (const Vector<T> &x, const Matrix<T> &yT);
00077 template <class T>
00078    Matrix<T> outerProduct (const Vector<T> &x, const Matrix<T> &yT);
00079 
00080 //
00081 // The vector/outer product of an MxN matrix and an N-length vector.
00082 //
00083 template <class T>
00084    Vector<T> product (const Matrix<T> &A, const Vector<T> &x);
00085 template <class T>
00086    Vector<T> outerProduct (const Matrix<T> &A, const Vector<T> &x);
00087 
00088 //
00089 // The matrix multiplication or cayley product of an MxN matrix and
00090 // an NxP matrix.
00091 //
00092 template <class T> 
00093    Matrix<T> product (const Matrix<T> &A, const Matrix<T> &B);
00094 template <class T> 
00095    Matrix<T> cayleyProduct (const Matrix<T> &A, const Matrix<T> &B);
00096 
00097 //
00098 // The NxM transpose of an MxN matrix.
00099 //
00100 template <class T> Matrix<T> transpose (const Matrix<T> &A);
00101 
00102 //
00103 //<div> complex space function specifications
00104 //
00105 
00106 //
00107 // The complex conjugate of the complex matrix A.
00108 //
00109 Matrix<Complex> conjugate (const Matrix<Complex> &A);
00110 
00111 //
00112 // The complex conjugate of the double precision complex matrix A.
00113 //
00114 Matrix<DComplex> conjugate (const Matrix<DComplex> &A);
00115 
00116 //
00117 // The conjugate/transpose or adjoint of the complex matrix A.
00118 //
00119 Matrix<Complex> adjoint (const Matrix<Complex> &A);
00120 
00121 //
00122 // The conjugate/transpose or adjoint of the double precision complex matrix A.
00123 //
00124 Matrix<DComplex> adjoint (const Matrix<DComplex> &A);
00125 
00126 //</div>
00127 
00128 // Requires linking of the LAPACK libraries. The LAPACK libraries
00129 // can be attained by FTPing to the netlib directory at 
00130 // Research.ATT.com or by contacting the Numerical Algorithms Group.
00131 // +grp
00132 //
00133 // The inverse of a matrix.  <note>The LU decomposition of the matrix
00134 // is a hidden calculation. </note>
00135 //
00136 template <class T> Matrix<T> inverse (const Matrix<T> &A);
00137 
00138 //
00139 // The inverse of an LUdecomp which is the Lower/upper 
00140 // decomposition of a matrix A.
00141 //
00142 template <class T> Matrix<T> inverse (const LUdecomp<T> &LU);
00143 
00144 //
00145 // The determinant of a matrix. <note>The LU decomposition of the matrix
00146 // is a hidden calculation. </note>
00147 //
00148 template <class T> T determinant (const Matrix<T> &A);
00149 
00150 //
00151 // the determinant (A) of an LUdecomp which is the lower/upper 
00152 // decomposition of a matrix A.
00153 //
00154 template <class T> T determinant (const LUdecomp<T> &LU);
00155 
00156 
00157 //  
00158 // Given a matrix "A", and given some vector "y" which is the right hand 
00159 // side of the equation "Ax=y", then "solve(A, y, error1, error2)" 
00160 // returns the computed vector "x". (for further details, see the LAPACK 
00161 // man page for "sgesvx".)
00162 //
00163 // solve(LUdecomp<T>, Vector<T>, ...) arguments are (in order):
00164 // 1) Matrix<T> -  (input)  the matrix "A" that is being modeled by the 
00165 //                          equation "Ax=y".
00166 // 2) Vector<T> -  (input)  the vector "y" that is being modeled by the
00167 //                          equation "Ax=y".
00168 // 3) double    -  (output) the error bound "forwardError" on the returned 
00169 //    vector x, i.e
00170 //                                            |max(x - xtrue)|
00171 //                         forwardError  >    ----------------
00172 //                                                |max(x)|
00173 //
00174 // 4) double    -  (output) the error bound "backwardError" on the input 
00175 //    vector "y". i.e. 
00176 //                        backwardError  >    |Ax-y| 
00177 //
00178 //<note>The LU decomposition of the matrix is a hidden calculation. </note>
00179 //
00180 template <class T> 
00181    Vector<T> solve (const Matrix<T> &A, const Vector<T> &y, double &ferr,
00182                     double &berr);
00183 
00184 //
00185 // Given an LUdecomp "myLU" which is the LU decomposition of some
00186 // matrix "A", and given some vector "y" which is the right hand side of
00187 // the equation "Ax=y", then "solve(myLU, y, error1, error2)" returns the 
00188 // computed vector "x". (for further details, see the LAPACK man page for
00189 // "sgesvx".)
00190 //
00191 // solve(LUdecomp<T>, Vector<T>, ...) arguments are (in order):
00192 // 1) LUdecomp<T> - (input) the LU decomposition of the matrix "A" that
00193 //                          is being modeled by the equation "Ax=y".
00194 // 2) Vector<T> -  (input)  the vector "y" that is being modeled by the
00195 //                          equation "Ax=y".
00196 // 3) double    -  (output) the error bound "forwardError" on the returned 
00197 //    vector x, i.e
00198 //                                            |max(x - xtrue)|
00199 //                         forwardError  >    ----------------
00200 //                                                |max(x)|
00201 //
00202 // 4) double    - (output) the error bound "backwardError" on the input 
00203 //    vector "y". i.e.
00204 //                        backwardError  >    |Ax-y| 
00205 //
00206 template <class T> 
00207    Vector<T> solve (const LUdecomp<T> &myLU, const Vector<T> &y, double &ferr,
00208                     double &berr);
00209 
00210 //
00211 // Given a matrix "A", and given a matrix "B" whose columns are the stored 
00212 // set of vectors "y1", "y2", ..."yN" which are independent right hand sides 
00213 // to the equation "Ax", e.g. "Ax=y", then "solve(A, B, Error1, Error2)" 
00214 // returns the computed matrix "X", whose columns are the stored set of 
00215 // vectors "x1", "x2", ..."xN" which satisfy the equation "Ax=y" for each 
00216 // respective "y". (for further details, see the LAPACK man page for
00217 // "sgesvx".)
00218 //
00219 // solve(LUdecomp<T>, Matrix<T>,...) arguments are (in order):
00220 // 1) Matrix<T> - (input) the matrix "A" that is being modeled by the 
00221 //    equation "Ax=y".
00222 // 2) Matrix<T> - (input)  MxN matrix "B" of N possible M-length 
00223 //    vectors "y1", "y2",..."yN" stored as columns in a single matrix "B" 
00224 //    where "A*x1=y1, A*x2=y2,..."A*xN=yN" => "AX=B".
00225 // 3) Vector<double> - (output) an N-length vector "Ferr" with error bounds 
00226 //    for returned matrix X, i.e. 
00227 //                                 max(X.column(i)-Xtrue.column(i))
00228 //                     Ferr(i) >   --------------------------------
00229 //                                         max(X.column(i)) 
00230 // 
00231 // 4) Vector<double> - (output) an N-length vector "Berr" with error bounds 
00232 //    for input matrix "B", i.e
00233 //                              Berr(i) > |max(A*X.column(i)-B.column(i))| 
00234 //
00235 //<note>The LU decomposition of the matrix is a hidden calculation. </note>
00236 //
00237 template <class T> 
00238    Matrix<T> solve (const Matrix<T> &A, const Matrix<T> &B, 
00239                     Vector<double> &Ferr, Vector<double> &Berr);
00240 
00241 //
00242 // Given an LUdecomp "myLU" which is the LU decomposition of some
00243 // matrix "A", and given a matrix "B" whose columns are the stored set of 
00244 // vectors "y1", "y2", ..."yN" which are independent right hand sides to 
00245 // the equation "Ax", e.g. "Ax=y", then "solve(myLU, B, Error1, Error2)" 
00246 // returns the computed matrix "X", whose columns are the stored set of 
00247 // vectors "x1", "x2", ..."xN" which satisfy the equation "Ax=y" for each 
00248 // respective "y". (for further details, see the LAPACK man page for
00249 // "sgesvx".)
00250 //
00251 // solve(LUdecomp<T>, Matrix<T>,...) arguments are (in order):
00252 // 1) LUdecomp<T> - (input) the LU decomposition of the matrix "A" that
00253 //                          is being modeled by the equation "Ax=y".
00254 // 2) Matrix<T>      - (input)  MxN matrix "B" of N possible M-length 
00255 //    vectors "y1", "y2",..."yN" stored as columns in a single matrix "B" 
00256 //    where "A*x1=y1, A*x2=y2,..."A*xN=yN" => "AX=B".
00257 // 3) Vector<double> - (output) an N-length vector "Ferr" with error bounds 
00258 //    for returned matrix X, i.e. 
00259 //                                 max(X.column(i)-Xtrue.column(i))
00260 //                     Ferr(i) >   --------------------------------
00261 //                                         max(X.column(i)) 
00262 // 
00263 // 4) Vector<double> - (output) an N-length vector "Berr" with error bounds 
00264 //    for input matrix "B", i.e
00265 //                              Berr(i) > |max(A*X.column(i)-B.column(i))| 
00266 //
00267 template <class T> 
00268    Matrix<T> solve (const LUdecomp<T> &myLU, const Matrix<T> &B, 
00269                     Vector<double> &Ferr, Vector<double> &Berr);
00270 
00271 // -grp
00272 // </div>
00273 
00274 #endif