2 : _fact(1), _complete(false), _P(0), _pivots(0), _L(0), _U(0) {}
5 : _fact(1), _complete(false), _P(0), _pivots(0), _L(0), _U(0) {
11 "Could not initialize"+std::string(e.
what()),
12 "DecompLU<T>::DecompLU"));
46 size_t n = mat.size();
51 for (i = 0; i < n; i++) {
52 for (j = 0; j < n; j++) {
53 _P[i][j] = ( i == j ) ? 1 : 0;
55 _U[i][j] = ( i == j ) ? 1 : 0;
60 for (i = 0; i < n; i++)
64 for (k = 0; k < n; k++) {
68 max = fabs(mat[k][k]);
69 for (j = k + 1; j < n; j++) {
70 if ( max < fabs(mat[j][k]) ) {
71 max = fabs(mat[j][k]);
78 std::swap(mat[pivot], mat[k]);
79 std::swap(_P[pivot], _P[k]);
80 std::swap(_pivots[pivot], _pivots[k]);
89 for (j = k+1; j < n; j++)
90 mat[k][j] /= mat[k][k];
93 for (i = k+1; i < n; i++)
94 for (j = k+1; j < n; j++)
95 mat[i][j] -= mat[i][k]*mat[k][j];
100 for (i = 0; i < n; i++) {
101 for (j = i; j < n; j++) {
103 _L[j][i] = mat[j][i];
106 _U[i][j] = ( i == j ) ? 1 : mat[i][j];
115 size_t n = _L.size();
116 for (
size_t i = 0; i < n; i++)
124 std::vector<std::vector<T>> mat(m);
126 for (i = 0; i < m; i++)
const char * what() const
Return char buffer of message+" at "+location, memory remains owned by Exception. ...
Definition: Exception.hh:52
Defines the LU decomposition algorithm of a square matrix.
Definition: DecompLU.hh:19
std::vector< std::vector< T > > _L
L Matrix.
Definition: DecompLU.hh:83
std::vector< std::vector< T > > NewMatrix(size_t m, size_t n)
Returns a matrix of m rows and n columns.
Definition: DecompLU-inl.hh:122
void IsSquare(const std::string &location, const std::string &what, const std::vector< std::vector< T >> &matrix)
Asserts that a matrix is square.
Definition: Assert.hh:116
std::vector< std::vector< T > > _P
Permutation matrix.
Definition: DecompLU.hh:81
void DecomposeCrout(std::vector< std::vector< T >> mat)
Decomposes a square matrix into a parity matrix P, a lower triangular matrix L and an upper triangula...
Definition: DecompLU-inl.hh:35
std::vector< T > _pivots
Premutation vector (IDs of the rows)
Definition: DecompLU.hh:82
DecompLU()
Default constructor, initilizes an empty matrix of dimension 0x0.
Definition: DecompLU-inl.hh:1
T _fact
Parity of the permutation (1 or -1)
Definition: DecompLU.hh:79
Global exception object for all non-standard exceptions thrown by the code.
Definition: Exception.hh:30
~DecompLU()
Destructor.
Definition: DecompLU-inl.hh:33
void IsNotEmpty(const std::string &location, const std::string &what, const std::vector< T > &vector)
Asserts that a vector is not empty.
Definition: Assert.hh:53
std::vector< std::vector< T > > _U
U Matrix.
Definition: DecompLU.hh:84
T Determinant()
Returns the determinant of the decomposed matrix.
Definition: DecompLU-inl.hh:113
DecompLU & operator=(const DecompLU &decLU)
Equality operator.
Definition: DecompLU-inl.hh:20
bool _complete
True if the decomposition was successful.
Definition: DecompLU.hh:80