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. More...
|
|
int | main (int argc, char **argv) |
| Main function. More...
|
|
◆ display()
void display |
( |
double ** |
A, |
|
|
int |
N |
|
) |
| |
Function to display square matrix.
68 for (
int i = 0; i < N; i++)
70 for (
int j = 0; j < N; j++)
72 printf(
"% 3.3g \t", A[i][j]);
◆ 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];
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Main function.
83 const int range2 =
range >> 1;
86 mat_size = atoi(argv[1]);
91 double **A = (
double **)
malloc(mat_size *
sizeof(
double *));
92 double **
L = (
double **)
malloc(mat_size *
sizeof(
double *));
93 double **U = (
double **)
malloc(mat_size *
sizeof(
double *));
94 for (
int i = 0; i < mat_size; i++)
97 A[i] = (
double *)
calloc(mat_size,
sizeof(
double));
98 L[i] = (
double *)
calloc(mat_size,
sizeof(
double));
99 U[i] = (
double *)
calloc(mat_size,
sizeof(
double));
100 for (
int j = 0; j < mat_size; j++)
102 A[i][j] = (
double)(rand() %
range - range2);
115 for (
int i = 0; i < mat_size; i++)
void display(double **A, int N)
Function to display square matrix.
Definition: lu_decompose.c:66
int lu_decomposition(double **A, double **L, double **U, int mat_size)
Perform LU decomposition on matrix.
Definition: lu_decompose.c:20
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition: malloc_dbg.h:18
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition: malloc_dbg.h:26
#define calloc(elemCount, elemSize)
This macro replace the standard calloc function with calloc_dbg.
Definition: malloc_dbg.h:22
Definition: prime_factoriziation.c:25