Functions associated with LU Decomposition of a square matrix.
More...
#include <iostream>
#include <valarray>
#include <vector>
Go to the source code of this file.
Functions associated with LU Decomposition of a square matrix.
- Author
- Krishna Vedala
◆ matrix
◆ determinant_lu()
template<typename T >
double determinant_lu |
( |
const matrix< T > & |
A | ) |
|
Compute determinant of an NxN square matrix using LU decomposition. Using LU decomposition, the determinant is given by the product of diagonal elements of matrices L and U.
- Template Parameters
-
T | datatype of input matrix - int, unsigned int, double, etc |
- Parameters
-
- Returns
- determinant of matrix A
98 for (
size_t i = 0; i < A.
size(); i++) {
99 result *= L[i][i] * U[i][i];
◆ lu_decomposition()
template<typename T >
int lu_decomposition |
( |
const matrix< T > & |
A, |
|
|
matrix< double > * |
L, |
|
|
matrix< double > * |
U |
|
) |
| |
Perform LU decomposition on matrix
- Parameters
-
[in] | A | matrix to decompose |
[out] | L | output L matrix |
[out] | U | output U matrix |
- Returns
- 0 if no errors
-
negative if error occurred
40 for (row = 0; row <
mat_size; row++) {
45 for (col = row; col <
mat_size; col++) {
48 for (j = 0; j < row; j++) {
49 lu_sum += L[0][row][j] * U[0][j][col];
53 U[0][row][col] = A[row][col] - lu_sum;
60 for (col = row; col <
mat_size; col++) {
68 for (j = 0; j < row; j++) {
69 lu_sum += L[0][col][j] * U[0][j][row];
73 L[0][col][row] = (A[col][row] - lu_sum) / U[0][row][row];