linalg 1.8.2
A linear algebra library that provides a user-friendly interface to several BLAS and LAPACK routines.
Loading...
Searching...
No Matches
linalg::lu_factor Interface Reference

Computes the LU factorization of an M-by-N matrix. More...

Public Member Functions

 lu_factor_dbl
 
 lu_factor_cmplx
 
 csr_lu_factor
 

Detailed Description

Computes the LU factorization of an M-by-N matrix.

Syntax
subroutine lu_factor(real(real64) a(:,:), integer(int32) ipvt(:), optional class(errors))
subroutine lu_factor(complex(real64) a(:,:), integer(int32) ipvt(:), optional class(errors))
Parameters
[in,out]aOn input, the M-by-N matrix on which to operate. On output, the LU factored matrix in the form [L\U] where the unit diagonal elements of L are not stored.
[out]ipvtAn MIN(M, N)-element array used to track row-pivot operations. The array stored pivot information such that row I is interchanged with row IPVT(I).
[in,out]errAn optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.
  • LA_ARRAY_SIZE_ERROR: Occurs if ipvt is not sized appropriately.
  • LA_SINGULAR_MATRIX_ERROR: Occurs as a warning if a is found to be singular.
Syntax (Sparse Matrices)
subroutine lu_factor(class(csr_matrix) a, type(msr_matrix) lu, integer(int32) ju(:), optional real(real64) droptol, optional class(errors) err)
Parameters
[in]aThe M-by-N sparse matrix to factor.
[out]luThe factored matrix, stored in MSR format. The diagonal is stored inverted.
[out]juAn M-element array used to track the starting row index of the U matrix.
[in]droptolAn optional threshold value used to determine when to drop small terms as part of the factorization of matrix A. The default value is set to the square root of machine precision (~1e-8).
[in,out]errAn optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.
  • LA_ARRAY_SIZE_ERROR: Occurs if ju is not sized correctly.
  • LA_OUT_OF_MEMORY_ERROR: Occurs if there is an issue with internal memory allocations.
  • LA_MATRIX_FORMAT_ERROR: Occurs if a is improperly formatted.
  • LA_SINGULAR_MATRIX_ERROR: Occurs if a is singular.
Notes
The dense routine utilizes the LAPACK routine DGETRF.
See Also
Usage
To solve a system of 3 equations of 3 unknowns using LU factorization, the following code will suffice.
program example
use iso_fortran_env
use linalg
implicit none
! Local Variables
real(real64) :: a(3,3), b(3)
integer(int32) :: i, pvt(3)
! Build the 3-by-3 matrix A.
! | 1 2 3 |
! A = | 4 5 6 |
! | 7 8 0 |
a = reshape( &
[1.0d0, 4.0d0, 7.0d0, 2.0d0, 5.0d0, 8.0d0, 3.0d0, 6.0d0, 0.0d0], &
[3, 3])
! Build the right-hand-side vector B.
! | -1 |
! b = | -2 |
! | -3 |
b = [-1.0d0, -2.0d0, -3.0d0]
! The solution is:
! | 1/3 |
! x = | -2/3 |
! | 0 |
! Compute the LU factorization
call lu_factor(a, pvt)
! Compute the solution. The results overwrite b.
call solve_lu(a, pvt, b)
! Display the results.
print '(A)', "LU Solution: X = "
print '(F8.4)', (b(i), i = 1, size(b))
end program
Computes the LU factorization of an M-by-N matrix.
Definition linalg.f90:844
Solves a system of LU-factored equations.
Definition linalg.f90:2421
Provides a set of common linear algebra routines.
Definition linalg.f90:145
The program generates the following output.
LU Solution: X =
0.3333
-0.6667
0.0000

Definition at line 844 of file linalg.f90.


The documentation for this interface was generated from the following file: