linear_algebra_double.h
00001 /* Copyright (C) 2003-2005  Martin Förg
00002 
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  * 
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00016  *
00017  * Contact:
00018  *   martin.o.foerg@googlemail.com
00019  *
00020  */
00021 
00022 #ifndef linear_algebrad_h
00023 #define linear_algebrad_h
00024 
00025 #include "square_matrix.h"
00026 #include "vector.h"
00027 #include "row_vector.h"
00028 #include "diagonal_matrix.h"
00029 #include "symmetric_matrix.h"
00030 #include "band_matrix.h"
00031 #include <complex>
00032 
00033 //-------------------------------------
00034 // Matrix operations
00035 //-------------------------------------
00036 
00037 namespace fmatvec {
00041 int svd(Matrix<General, Ref, Ref, double> &A,    Matrix<General, Ref, Ref, double> &S,  SquareMatrix<Ref, double> &U, SquareMatrix<Ref, double> &VT, int Rueckgabe);
00042 
00049   Vector<Ref, std::complex<double> > eigval(const SquareMatrix<Ref, double> &A);
00050 
00061   int eigvec(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<Symmetric, Ref, Ref, double> &B, SquareMatrix<Ref, double> &eigenvectors, Vector<Ref, double> &eigenvalues);
00062 
00069   Vector<Ref, double> eigval(const Matrix<Symmetric, Ref, Ref, double> &A);
00070 
00082   Vector<Ref, double> eigvalSel(const Matrix<Symmetric, Ref, Ref, double> &A, int il, int iu, double abstol = 0);
00083 
00105   int Doolittle_LU_with_Pivoting_Solve(double *A, double B[], int pivot[], double x[], int n);
00106 
00116   Matrix<General, Ref, Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &B);
00117 
00127   Vector<Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &b);
00128 
00139   Vector<Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x, int & info);
00140 
00151   Matrix<General, Ref, Ref, double> slvLUFac(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &B, const Vector<Ref, int> &ipiv);
00152 
00163   Vector<Ref, double> slvLUFac(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &b, const Vector<Ref, int> &ipiv);
00164 
00174   Matrix<General, Ref, Ref, double> slvLL(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &B);
00175 
00185   Vector<Ref, double> slvLL(const Matrix<Symmetric, Ref, Ref, double> &A, const Vector<Ref, double> &b);
00186 
00196   Matrix<General, Ref, Ref, double> slvQR(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &B);
00197 
00207   Vector<Ref, double> slvQR(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &b);
00208 
00216   SquareMatrix<Ref, double> inv(const SquareMatrix<Ref, double> &A);
00217 
00225   Matrix<Symmetric, Ref, Ref, double> inv(const Matrix<Symmetric, Ref, Ref, double> &A);
00226 
00234   Matrix<Diagonal, Ref, Ref, double> inv(const Matrix<Diagonal, Ref, Ref, double> &A);
00235 
00244   Matrix<General, Ref, Ref, double> facLU(const Matrix<General, Ref, Ref, double> &A, Vector<Ref, int> &ipiv);
00245 
00254   SquareMatrix<Ref, double> facLU(const SquareMatrix<Ref, double> &A, Vector<Ref, int> &ipiv);
00255 
00267   int facLU(double *A, int pivot[], int n);
00268   
00276   Matrix<Symmetric, Ref, Ref, double> facLL(const Matrix<Symmetric, Ref, Ref, double> &A);
00277 
00284   double nrm1(const Vector<Ref, double> &x);
00285 
00292   double nrm2(const Vector<Ref, double> &x);
00293 
00300   double nrmInf(const Vector<Ref, double> &x);
00301   
00309   double nrm1(const Matrix<General, Ref, Ref, double> &A);
00310 
00317   double nrm2(const Matrix<General, Ref, Ref, double> &A);
00318 
00326   double nrmInf(const Matrix<General, Ref, Ref, double> &A);
00327 
00334   double nrmFro(const Matrix<General, Ref, Ref, double> &A);
00335 
00342   double rho(const SquareMatrix<Ref, double> &A);
00343 
00350   double rho(const Matrix<Symmetric, Ref, Ref, double> &A);
00351 
00352   Vector<Ref, double> slvLLFac(const Matrix<Symmetric, Ref, Ref, double> &A, const Vector<Ref, double> &x);
00353 
00354   Matrix<General, Ref, Ref, double> slvLLFac(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
00355 
00356   Matrix<General, Ref, Ref, double> slvLS(const Matrix<General, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &B, double rcond = -1);
00357   
00358   Vector<Ref, double> slvLS(const Matrix<General, Ref, Ref, double> &A, const Vector<Ref, double> &b, double rcond = -1);
00359 
00360 //Matrix<General,Ref,Ref,double> slvLU(CBLAS_SIDE side, CBLAS_UPLO uplo, CBLAS_DIAG unit, const SquareMatrix<Ref,double> &A, const Matrix<General,Ref,Ref,double> &X, const Vector<Ref,int> &ipiv );
00361 
00369 //Matrix<General,Ref,Ref,double> swap(const Matrix<General,Ref,Ref,double> &A, const Vector<Ref,int> &ipiv );
00370 
00381   template <int size>
00382   Vector<Fixed<size>, double> slvLU(const SquareMatrix<Fixed<size>, double> &A, const Vector<Fixed<size>, double> &b, int & info) {
00383 
00384 #ifndef FMATVEC_NO_VOID_CHECK
00385     if (size == 0)
00386       return b;
00387 #endif
00388 
00389     int ipiv[size];
00390 
00391     SquareMatrix<Fixed<size>, double> LU = A;
00392 
00393     info = facLU(LU(), ipiv, size);
00394 
00395     Vector<Fixed<size>, double> x = b;
00396     Vector<Fixed<size>, double> y = b;
00397 
00398     info = Doolittle_LU_with_Pivoting_Solve(LU(), y(), ipiv, x(), size);
00399 
00400     return x;
00401 
00402   }
00403 
00404 }
00405 
00406 #endif