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

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

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.
Notes
This 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
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.
Solves a system of LU-factored equations.
Provides a set of common linear algebra routines.
Definition: linalg_core.f90:15
The program generates the following output.
LU Solution: X =
0.3333
-0.6667
0.0000

Definition at line 555 of file linalg_core.f90.


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