A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d1/dbe/lu__decomposition_8h.html below:

TheAlgorithms/C++: numerical_methods/lu_decomposition.h File Reference

Loading...

Searching...

No Matches

Functions associated with LU Decomposition of a square matrix. More...

#include <iostream>
#include <valarray>
#include <vector>

Go to the source code of this file.

template<typename T> using  matrix = std::vector<std::valarray<T>>

Functions associated with LU Decomposition of a square matrix.

Definition in file lu_decomposition.h.

◆ matrix

template<typename T>

using matrix = std::vector<std::valarray<T>>

Define matrix type as a std::vector of std::valarray

Definition at line 19 of file lu_decomposition.h.

◆ 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

Definition at line 90 of file lu_decomposition.h.

90 {

93

95 return 0;

96

98 for (size_t i = 0; i < A.size(); i++) {

99 result

*= L[i][i] * U[i][i];

100 }

102}

uint64_t result(uint64_t n)

int lu_decomposition(const matrix< T > &A, matrix< double > *L, matrix< double > *U)

std::vector< std::valarray< T > > matrix

◆ 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

Definition at line 29 of file lu_decomposition.h.

29 {

30 int row, col, j;

32

34

35 std::cerr << "Not a square matrix!\n";

36 return -1;

37 }

38

39

40 for

(row = 0; row <

mat_size

; row++) {

41

42#ifdef _OPENMP

43#pragma omp for

44#endif

45 for

(col = row; col <

mat_size

; col++) {

46

47 double lu_sum = 0.;

48 for (j = 0; j < row; j++) {

49 lu_sum += L[0][row][j] * U[0][j][col];

50 }

51

52

53 U[0][row][col] = A[row][col] - lu_sum;

54 }

55

56

57#ifdef _OPENMP

58#pragma omp for

59#endif

60 for

(col = row; col <

mat_size

; col++) {

61 if (row == col) {

62 L[0][row][col] = 1.;

63 continue;

64 }

65

66

67 double lu_sum = 0.;

68 for (j = 0; j < row; j++) {

69 lu_sum += L[0][col][j] * U[0][j][row];

70 }

71

72

73 L[0][col][row] = (A[col][row] - lu_sum) / U[0][row][row];

74 }

75 }

76

77 return 0;

78}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4