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 {
41 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);
42 
49  FMATVEC_EXPORT Vector<Ref, std::complex<double>> eigval(const SquareMatrix<Ref, double> &A);
50 
59  FMATVEC_EXPORT int eigvec(const SquareMatrix<Ref, double> &A, SquareMatrix<Ref, std::complex<double>> &V, Vector<Ref, std::complex<double>> &w);
60 
71  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);
72 
79  FMATVEC_EXPORT Vector<Ref, double> eigval(const Matrix<Symmetric, Ref, Ref, double> &A);
80 
92  FMATVEC_EXPORT Vector<Ref, double> eigvalSel(const Matrix<Symmetric, Ref, Ref, double> &A, int il, int iu, double abstol = 0);
93 
115  FMATVEC_EXPORT int Doolittle_LU_with_Pivoting_Solve(double *A, double B[], const int pivot[], double x[], int n);
116 
126  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
127  FMATVEC_EXPORT Matrix<General, Var, Var, double> slvLU(const SquareMatrix<Var, double> &A, const Matrix<General, Var, Var, double> &X, int & info);
128 
138  FMATVEC_EXPORT Vector<Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x);
139 
150  FMATVEC_EXPORT Vector<Ref, double> slvLU(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x, int & info);
151  FMATVEC_EXPORT Vector<Var, double> slvLU(const SquareMatrix<Var, double> &A, const Vector<Var, double> &x, int & info);
152 
163  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);
164  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);
165 
176  FMATVEC_EXPORT Vector<Ref, double> slvLUFac(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x, const Vector<Ref, int> &ipiv);
177  FMATVEC_EXPORT Vector<Var, double> slvLUFac(const SquareMatrix<Var, double> &A, const Vector<Var, double> &x, const Vector<Var, int> &ipiv);
178 
188  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLL(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
189 
199  FMATVEC_EXPORT Vector<Ref, double> slvLL(const Matrix<Symmetric, Ref, Ref, double> &A, const Vector<Ref, double> &x);
200 
210  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvQR(const SquareMatrix<Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
211 
221  FMATVEC_EXPORT Vector<Ref, double> slvQR(const SquareMatrix<Ref, double> &A, const Vector<Ref, double> &x);
222 
230  FMATVEC_EXPORT SquareMatrix<Ref, double> inv(const SquareMatrix<Ref, double> &A);
231 
239  FMATVEC_EXPORT Matrix<Symmetric, Ref, Ref, double> inv(const Matrix<Symmetric, Ref, Ref, double> &A);
240 
248  FMATVEC_EXPORT Matrix<Diagonal, Ref, Ref, double> inv(const Matrix<Diagonal, Ref, Ref, double> &A);
249 
258  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> facLU(const Matrix<General, Ref, Ref, double> &A, Vector<Ref, int> &ipiv);
259 
268  FMATVEC_EXPORT SquareMatrix<Ref, double> facLU(const SquareMatrix<Ref, double> &A, Vector<Ref, int> &ipiv);
269 
270  FMATVEC_EXPORT SquareMatrix<Var, double> facLU(const SquareMatrix<Var, double> &A, Vector<Var, int> &ipiv);
271 
283  FMATVEC_EXPORT int facLU(double *A, int pivot[], int n);
284 
292  FMATVEC_EXPORT Matrix<Symmetric, Ref, Ref, double> facLL(const Matrix<Symmetric, Ref, Ref, double> &A);
293 
300  FMATVEC_EXPORT double nrm1(const Vector<Ref, double> &x);
301 
308  FMATVEC_EXPORT double nrm2(const Vector<Ref, double> &x);
309 
316  FMATVEC_EXPORT double nrmInf(const Vector<Ref, double> &x);
317 
325  FMATVEC_EXPORT double nrm1(const Matrix<General, Ref, Ref, double> &A);
326 
333  FMATVEC_EXPORT double nrm2(const Matrix<General, Ref, Ref, double> &A);
334 
342  FMATVEC_EXPORT double nrmInf(const Matrix<General, Ref, Ref, double> &A);
343 
351  FMATVEC_EXPORT double nrmInf(const Matrix<Symmetric, Ref, Ref, double> &A);
352 
359  FMATVEC_EXPORT double nrmFro(const Matrix<General, Ref, Ref, double> &A);
360 
367  FMATVEC_EXPORT double rho(const SquareMatrix<Ref, double> &A);
368 
375  FMATVEC_EXPORT double rho(const Matrix<Symmetric, Ref, Ref, double> &A);
376 
377  FMATVEC_EXPORT Vector<Ref, double> slvLLFac(const Matrix<Symmetric, Ref, Ref, double> &A, const Vector<Ref, double> &x);
378 
379  FMATVEC_EXPORT Matrix<General, Ref, Ref, double> slvLLFac(const Matrix<Symmetric, Ref, Ref, double> &A, const Matrix<General, Ref, Ref, double> &X);
380 
381  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);
382 
383  FMATVEC_EXPORT Vector<Ref, double> slvLS(const Matrix<General, Ref, Ref, double> &A, const Vector<Ref, double> &b, double rcond = -1);
384 
385 //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 );
386 
394 //Matrix<General,Ref,Ref,double> swap(const Matrix<General,Ref,Ref,double> &A, const Vector<Ref,int> &ipiv );
395 
406  template <int size>
407  Vector<Fixed<size>, double> slvLU(const SquareMatrix<Fixed<size>, double> &A, const Vector<Fixed<size>, double> &b, int & info) {
408 
409  if (size == 0)
410  return b;
411 
412  int ipiv[size];
413 
414  SquareMatrix<Fixed<size>, double> LU = A;
415 
416  info = facLU(LU(), ipiv, size);
417 
418  Vector<Fixed<size>, double> x = b;
419  Vector<Fixed<size>, double> y = b;
420 
421  info = Doolittle_LU_with_Pivoting_Solve(LU(), y(), ipiv, x(), size);
422 
423  return x;
424 
425  }
426 
427 }
428 
429 #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:721
Matrix< Symmetric, Ref, Ref, double > facLL(const Matrix< Symmetric, Ref, Ref, double > &A)
LL decomposition.
Definition: linear_algebra_double.cc:501
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:657
Definition: fmatvec.h:39
double nrm1(const Vector< Ref, double > &x)
1-norm
Definition: linear_algebra_double.cc:520
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:162
Vector< Ref, double > eigvalSel(const Matrix< Symmetric, Ref, Ref, double > &A, int il, int iu, double abstol)
Eigenvalues.
Definition: linear_algebra_double.cc:762
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:387
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:143
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:97
Vector< Ref, std::complex< double > > eigval(const SquareMatrix< Ref, double > &A)
Eigenvalues.
Definition: linear_algebra_double.cc:637
SquareMatrix< Ref, double > inv(const SquareMatrix< Ref, double > &A)
Inverse.
Definition: linear_algebra_double.cc:328
double nrmFro(const Matrix< General, Ref, Ref, double > &A)
Frobenius-norm.
Definition: linear_algebra_double.cc:834
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:545
double rho(const SquareMatrix< Ref, double > &A)
Spectral radius.
Definition: linear_algebra_double.cc:782