matrix.h
Go to the documentation of this file.00001 #ifndef MATRIX_H
00002 #define MATRIX_H
00003
00004
00005 #include <fstream>
00006 #include <cstdio>
00007 #include <cmath>
00008 #include <cstdlib>
00009 #include <cassert>
00010 #include <cstring>
00011
00012
00013 #ifndef BOOST_VERSION
00014 #include <boost/version.hpp>
00015 #endif
00016 #if BOOST_VERSION <= 103200
00017
00018
00019
00020
00021 #include <boost/numeric/ublas/config.hpp>
00022 #include <boost/numeric/ublas/storage.hpp>
00023 #include <boost/numeric/ublas/functional.hpp>
00024 #include <boost/numeric/ublas/operation.hpp>
00025 #endif
00026
00027 #include <boost/numeric/ublas/vector.hpp>
00028 #include <boost/numeric/ublas/matrix.hpp>
00029 #include <boost/numeric/ublas/triangular.hpp>
00030 #include <boost/numeric/ublas/lu.hpp>
00031 #include <boost/numeric/ublas/io.hpp>
00032
00033
00034
00035 double UNorm (const double *A, int n, const int m);
00036 double* M_Cholesky (double *B, double *q, const int n);
00037 double* M_InvertPos (double *B, const int n);
00038 double* M_Invert (double *Ap, double *Bp, const int n);
00039 void RowMult (const double a, double *A, const double b, const double *B, const int n);
00040 double* M_A_times_b (double *y, const double *A, const int n, const int m, const double *b);
00041 double* M_Zero (double *A, const int n);
00042 double* M_Unit (double *A, const int n);
00043 void M_Print (const double *A, const int n);
00044 void M_Print (const double *A, const double *B, const int n);
00045
00046 double *V_Zero (double *v, const int n);
00047 double *V_Unit (double *v, const int n, int k);
00048 void V_Print (const double *v, const int n);
00049 void V_Print (const double *v, const double *w, const int n);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 template<class T>
00071 boost::numeric::ublas::matrix<T> invert (boost::numeric::ublas::matrix<T> & input)
00072 {
00073 using namespace boost::numeric::ublas;
00074
00075
00076 matrix<T> inverse(zero_matrix<T>(input.size1()));
00077
00078
00079 matrix<T> A(input);
00080
00081 permutation_matrix<std::size_t> pm(A.size1());
00082
00083
00084 int res = lu_factorize(A, pm);
00085
00086 if (res != 0) return inverse;
00087
00088
00089 inverse.assign(identity_matrix<T>(A.size1()));
00090
00091
00092 lu_substitute(A, pm, inverse);
00093
00094 return inverse;
00095 }
00096
00097
00098 #endif // MATRIX_H