ALFI
Advanced Library for Function Interpolation
|
Functions | |
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer> | |
Container< Number > | lup_solve (Container< Container< Number > > &&A, Container< Number > &&B, Number epsilon=std::numeric_limits< Number >::epsilon()) |
Solves a system of linear equations using LUP decomposition. | |
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer> | |
Container< Number > | tridiag_solve_unstable (const Container< Number > &lower, Container< Number > &&diag, const Container< Number > &upper, Container< Number > &&right) |
Solves a tridiagonal system of linear equations. | |
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer> | |
Container< Number > | tridiag_solve (Container< Number > &&lower, Container< Number > &&diag, Container< Number > &&upper, Container< Number > &&right) |
Solves a tridiagonal system of linear equations. | |
Container< Number > alfi::util::linalg::lup_solve | ( | Container< Container< Number > > && | A, |
Container< Number > && | B, | ||
Number | epsilon = std::numeric_limits<Number>::epsilon() ) |
Solves a system of linear equations using LUP decomposition.
This function solves the system of linear equations \(AX = B\), where \(A\) is a square matrix, by performing LUP decomposition and forward-backward substitution.
The input matrix \(A\) is decomposed into lower \(L\) and upper \(U\) triangular matrices, such that \(PA = LU\), transforming the equation into \(PLUX = B\) or \(LUX = PB\).
The solution is found in two stages:
If the pivot element in a given column is too small (less than the specified \(epsilon\)), the function returns an empty container, indicating that the matrix is degenerate, and prints the corresponding message to std::cerr
.
The input matrix \(A\) and vector \(B\) are modified in place.
A | the matrix (2D container of size \(n \times n\)) |
B | the right-hand side vector (1D container of size \(n\)) |
epsilon | a small threshold value to detect degeneracy (default is machine epsilon) |
Container< Number > alfi::util::linalg::tridiag_solve_unstable | ( | const Container< Number > & | lower, |
Container< Number > && | diag, | ||
const Container< Number > & | upper, | ||
Container< Number > && | right ) |
Solves a tridiagonal system of linear equations.
This function solves a system of linear equations \(AX = B\), where \(A\) is a tridiagonal matrix. The input vectors are modified in place.
Unlike tridiag_solve, this algorithm is generally unstable.
The sufficient conditions for this algorithm to be stable are (see this article: https://stsynkov.math.ncsu.edu/book_sample_material/Sections_5.4-5.5.pdf):
The first element of lower
and the last element of upper
are ignored.
lower | the subdiagonal elements of the tridiagonal matrix (first element is ignored) |
diag | the diagonal elements of the tridiagonal matrix |
upper | the superdiagonal elements of the tridiagonal matrix (last element is ignored) |
right | the right-hand side vector of the system |
Container< Number > alfi::util::linalg::tridiag_solve | ( | Container< Number > && | lower, |
Container< Number > && | diag, | ||
Container< Number > && | upper, | ||
Container< Number > && | right ) |
Solves a tridiagonal system of linear equations.
This function solves a system of linear equations \(AX = B\), where \(A\) is a tridiagonal matrix. The input vectors are modified in place.
Unlike tridiag_solve_unstable, this algorithm is stable.
The first element of lower
and the last element of upper
are ignored.
lower | the subdiagonal elements of the tridiagonal matrix (first element is ignored) |
diag | the diagonal elements of the tridiagonal matrix |
upper | the superdiagonal elements of the tridiagonal matrix (last element is ignored) |
right | the right-hand side vector of the system |