fmatvec  0.0.0
linear_algebra_double.h
1 /* Copyright (C) 2003-2005 Martin Förg
2 
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact:
18  * martin.o.foerg@googlemail.com
19  *
20  */
21 
22 #ifndef linear_algebrad_h
23 #define linear_algebrad_h
24 
25 #include "square_matrix.h"
26 #include "vector.h"
27 #include "row_vector.h"
28 #include "diagonal_matrix.h"
29 #include "symmetric_matrix.h"
30 #include "band_matrix.h"
31 #include <complex>
32 
33 //-------------------------------------
34 // Matrix operations
35 //-------------------------------------
36 
37 namespace fmatvec {
38 
42  FMATVEC_EXPORT int svd(Matrix<General, Ref, Ref, double> &A, Matrix<General, Ref, Ref, double> &S, SquareMatrix<Ref, double> &U, SquareMatrix<Ref, double> &VT, int Rueckgabe);
43 
50  FMATVEC_EXPORT Vector<Ref, std::complex<double>> eigval(const SquareMatrix<Ref, double> &A);
51 
60  FMATVEC_EXPORT int eigvec(const SquareMatrix<Ref, double> &A, SquareMatrix<Ref, std::complex<double>> &V, Vector<Ref, std::complex<double>> &w);
61 
72  FMATVEC_EXPORT int eigvec(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<Symmetric, Ref, Ref, double> &B, SquareMatrix<Ref, double> &eigenvectors, Vector<Ref, double> &eigenvalues);
73 
80  FMATVEC_EXPORT Vector<Ref, double> eigval(const Matrix<Symmetric, Ref, Ref, double> &A);
81 
93  FMATVEC_EXPORT Vector<Ref, double> eigvalSel(const Matrix<Symmetric, Ref, Ref, double> &A, int il, int iu, double abstol = 0);
94 
116  FMATVEC_EXPORT int Doolittle_LU_with_Pivoting_Solve(double *A, double B[], const int pivot[], double x[], int n);
117 
127  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
128  FMATVEC_EXPORT Matrix<General, Var, Var, double> slvLU(const SquareMatrix<Var, double> &A, const Matrix<General, Var, Var, double> &X, int & info);
129 
139  FMATVEC_EXPORT Vector<Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x);
140 
151  FMATVEC_EXPORT Vector<Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x, int & info);
152  FMATVEC_EXPORT Vector<Var, double> slvLU(const SquareMatrix<Var, double> &A, const Vector<Var, double> &x, int & info);
153 
164  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLUFac(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &X, const Vector<Ref, int> &ipiv);
165  FMATVEC_EXPORT Matrix<General, Var, Var, double> slvLUFac(const SquareMatrix<Var, double> &A, const Matrix<General, Var, Var, double> &X, const Vector<Var, int> &ipiv);
166 
177  FMATVEC_EXPORT Vector<Ref, double> slvLUFac(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x, const Vector<Ref, int> &ipiv);
178  FMATVEC_EXPORT Vector<Var, double> slvLUFac(const SquareMatrix<Var, double> &A, const Vector<Var, double> &x, const Vector<Var, int> &ipiv);
179 
189  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLL(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
190 
200  FMATVEC_EXPORT Vector<Ref, double> slvLL(const Matrix<Symmetric, Ref, Ref, double> &A, const Vector<Ref, double> &x);
201 
211  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvQR(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
212 
222  FMATVEC_EXPORT Vector<Ref, double> slvQR(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x);
223 
231  FMATVEC_EXPORT SquareMatrix<Ref, double> inv(const SquareMatrix<Ref, double> &A);
232 
240  FMATVEC_EXPORT Matrix<Symmetric, Ref, Ref, double> inv(const Matrix<Symmetric, Ref, Ref, double> &A);
241 
249  FMATVEC_EXPORT Matrix<Diagonal, Ref, Ref, double> inv(const Matrix<Diagonal, Ref, Ref, double> &A);
250 
259  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> facLU(const Matrix<General, Ref, Ref, double> &A, Vector<Ref, int> &ipiv);
260 
269  FMATVEC_EXPORT SquareMatrix<Ref, double> facLU(const SquareMatrix<Ref, double> &A, Vector<Ref, int> &ipiv);
270 
271  FMATVEC_EXPORT SquareMatrix<Var, double> facLU(const SquareMatrix<Var, double> &A, Vector<Var, int> &ipiv);
272 
284  FMATVEC_EXPORT int facLU(double *A, int pivot[], int n);
285 
293  FMATVEC_EXPORT Matrix<Symmetric, Ref, Ref, double> facLL(const Matrix<Symmetric, Ref, Ref, double> &A);
294 
301  FMATVEC_EXPORT double nrm1(const Vector<Ref, double> &x);
302 
309  FMATVEC_EXPORT double nrm2(const Vector<Ref, double> &x);
310 
317  FMATVEC_EXPORT double nrmInf(const Vector<Ref, double> &x);
318 
326  FMATVEC_EXPORT double nrm1(const Matrix<General, Ref, Ref, double> &A);
327 
334  FMATVEC_EXPORT double nrm2(const Matrix<General, Ref, Ref, double> &A);
335 
343  FMATVEC_EXPORT double nrmInf(const Matrix<General, Ref, Ref, double> &A);
344 
352  FMATVEC_EXPORT double nrmInf(const Matrix<Symmetric, Ref, Ref, double> &A);
353 
360  FMATVEC_EXPORT double nrmFro(const Matrix<General, Ref, Ref, double> &A);
361 
368  FMATVEC_EXPORT double rho(const SquareMatrix<Ref, double> &A);
369 
376  FMATVEC_EXPORT double rho(const Matrix<Symmetric, Ref, Ref, double> &A);
377 
378  FMATVEC_EXPORT Vector<Ref, double> slvLLFac(const Matrix<Symmetric, Ref, Ref, double> &A, const Vector<Ref, double> &x);
379 
380  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLLFac(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
381 
382  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLS(const Matrix<General, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &B, double rcond = -1);
383 
384  FMATVEC_EXPORT Vector<Ref, double> slvLS(const Matrix<General, Ref, Ref, double> &A, const Vector<Ref, double> &b, double rcond = -1);
385 
386 //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 );
387 
395 //Matrix<General,Ref,Ref,double> swap(const Matrix<General,Ref,Ref,double> &A, const Vector<Ref,int> &ipiv );
396 
407  template <int size>
408  Vector<Fixed<size>, double> slvLU(const SquareMatrix<Fixed<size>, double> &A, const Vector<Fixed<size>, double> &b, int & info) {
409 
410  if (size == 0)
411  return b;
412 
413  int ipiv[size];
414 
415  SquareMatrix<Fixed<size>, double> LU = A;
416 
417  info = facLU(LU(), ipiv, size);
418 
419  Vector<Fixed<size>, double> x = b;
420  Vector<Fixed<size>, double> y = b;
421 
422  info = Doolittle_LU_with_Pivoting_Solve(LU(), y(), ipiv, x(), size);
423 
424  return x;
425 
426  }
427 
428 }
429 
430 #endif
int svd(Matrix< General, Ref, Ref, double > &A, Matrix< General, Ref, Ref, double > &S, SquareMatrix< Ref, double > &U, SquareMatrix< Ref, double > &VT, int Rueckgabe)
Definition: linear_algebra_double.cc:723
Matrix< Symmetric, Ref, Ref, double > facLL(const Matrix< Symmetric, Ref, Ref, double > &A)
LL decomposition.
Definition: linear_algebra_double.cc:503
int eigvec(const SquareMatrix< Ref, double > &A, SquareMatrix< Ref, std::complex< double >> &V, Vector< Ref, std::complex< double >> &w)
Eigenvectors and Eigenvalues.
Definition: linear_algebra_double.cc:659
Definition: fmatvec.h:39
double nrm1(const Vector< Ref, double > &x)
1-norm
Definition: linear_algebra_double.cc:522
int Doolittle_LU_with_Pivoting_Solve(double *A, double B[], const int pivot[], double x[], int n)
solve linear system with LU decomposed matrix
Definition: linear_algebra_double.cc:164
Vector< Ref, double > eigvalSel(const Matrix< Symmetric, Ref, Ref, double > &A, int il, int iu, double abstol)
Eigenvalues.
Definition: linear_algebra_double.cc:764
Vector< Ref, std::complex< double > > slvLU(const SquareMatrix< Ref, std::complex< double >> &A, const Vector< Ref, std::complex< double >> &x)
System of linear equations.
Definition: linear_algebra_complex.cc:47
Definition: fmatvec.h:45
Definition: fmatvec.h:48
Matrix< General, Ref, Ref, double > facLU(const Matrix< General, Ref, Ref, double > &A, Vector< Ref, int > &ipiv)
LU decomposition.
Definition: linear_algebra_double.cc:389
Matrix< General, Ref, Ref, double > slvQR(const SquareMatrix< Ref, double > &A, const Matrix< General, Ref, Ref, double > &X)
Systems of linear equations.
Definition: linear_algebra_double.cc:145
Namespace fmatvec.
Definition: _memory.cc:28
Matrix< General, Ref, Ref, double > slvLUFac(const SquareMatrix< Ref, double > &A, const Matrix< General, Ref, Ref, double > &X, const Vector< Ref, int > &ipiv)
Systems of linear equations.
Definition: linear_algebra_double.cc:99
Vector< Ref, std::complex< double > > eigval(const SquareMatrix< Ref, double > &A)
Eigenvalues.
Definition: linear_algebra_double.cc:639
SquareMatrix< Ref, double > inv(const SquareMatrix< Ref, double > &A)
Inverse.
Definition: linear_algebra_double.cc:330
double nrmFro(const Matrix< General, Ref, Ref, double > &A)
Frobenius-norm.
Definition: linear_algebra_double.cc:836
Vector< Ref, double > slvLL(const Matrix< Symmetric, Ref, Ref, double > &A, const Vector< Ref, double > &x)
System of linear equations.
Definition: linear_algebra_double.cc:547
double rho(const SquareMatrix< Ref, double > &A)
Spectral radius.
Definition: linear_algebra_double.cc:784