BOOL ludcmp(double** a, int n, int* indx, int* d)
Given a matrix a[0..n-1][0..n-1], this routines replaces it by the LU decomposition of a rowwise permutation of itself. a and n are input. a is output, with the diagonal elements of the lower triangular matrix are equal to 1. indx[0..n-1] is an output vector that records the row permutation effected by the partial pivoting. d is output as 1 or -1 depending on whether the number of row interchanges was even or odd, respectively. This routine is used in combination with lubksb to solve linear equations or invert a matrix. The routine returns TRUE if the decomposition was successful, otherwise it returns FALSE.
Parameters:
a | Matrix to decompose. |
---|---|
n | Size of a. |
indx | Permutation vector. |
d | Determinant helper parameter. |
Returns:
TRUE if a was successfully decomposed, FALSE otherwise. On return, a contains the LU factorization and indx contains a permutation vector.
Usage:
double** a; int* p; int d; BOOL success; a = dmatrix(0, 3, 0, 3); p = ivector(0, 3); // initialize the a[i][j] elements success = ludcmp(a, 4, p, &d); free_dmatrix(a, 0, 3, 0); free_ivector(p, 0);
Header:
#include "linalg.h"
See Also:
lubksb