LU decomposition of a square matrix
More...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
|
int | lu_decomposition (double **A, double **L, double **U, int mat_size) |
| Perform LU decomposition on matrix. More...
|
|
void | display (double **A, int N) |
| Function to display square matrix.
|
|
int | main (int argc, char **argv) |
| Main function.
|
|
◆ lu_decomposition()
int lu_decomposition |
( |
double ** |
A, |
|
|
double ** |
L, |
|
|
double ** |
U, |
|
|
int |
mat_size |
|
) |
| |
Perform LU decomposition on matrix.
- Parameters
-
[in] | A | matrix to decompose |
[out] | L | output L matrix |
[out] | U | output U matrix |
[in] | mat_size | input square matrix size |
25 for (row = 0; row < mat_size; row++)
31 for (col = row; col < mat_size; col++)
35 for (j = 0; j < row; j++) lu_sum +=
L[row][j] * U[j][col];
38 U[row][col] = A[row][col] - lu_sum;
45 for (col = row; col < mat_size; col++)
55 for (j = 0; j < row; j++) lu_sum +=
L[col][j] * U[j][row];
58 L[col][row] = (A[col][row] - lu_sum) / U[row][row];