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::solve_triangular_system Interface Reference

Solves a triangular system of equations. More...

Public Member Functions

 solve_tri_mtx
 
 solve_tri_mtx_cmplx
 
 solve_tri_vec
 
 solve_tri_vec_cmplx
 

Detailed Description

Solves a triangular system of equations.

Syntax 1
Solves one of the matrix equations: \( op(A) X = \alpha B \), or \( X op(A) = \alpha B \), where \( A \) is a triangular matrix.
subroutine solve_triangular_system(logical lside, logical upper, logical trans, logical nounit, real(real64) alpha, real(real64) a(:,:), real(real64) b(:,:), optional class(errors) err)
subroutine solve_triangular_system(logical lside, logical upper, logical trans, logical nounit, complex(real64) alpha, complex(real64) a(:,:), complex(real64) b(:,:), optional class(errors) err)
Parameters
[in]lsideSet to true to solve \( op(A) X = \alpha B \); else, set to false to solve \( X op(A) = \alpha B \).
[in]upperSet to true if A is an upper triangular matrix; else, set to false if A is a lower triangular matrix.
[in]transSet to true if \( op(A) = A^T \) ( \( op(A) = A^H \) in the complex case); else, set to false if \( op(A) = A \).
[in]nounitSet to true if A is not a unit-diagonal matrix (ones on every diagonal element); else, set to false if A is a unit-diagonal matrix.
[in]alphaThe scalar multiplier to B.
[in]aIf lside is true, the M-by-M triangular matrix on which to operate; else, if lside is false, the N-by-N triangular matrix on which to operate.
[in,out]bOn input, the M-by-N right-hand-side. On output, the M-by-N solution.
[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 a is not square, or if the sizes of a and b are not compatible.
Notes
This routine is based upon the BLAS routine DTRSM (ZTRSM in the complex case).
Syntax 2
Solves the system of equations: \( op(A) X = B \), where \( A \) is a triangular matrix.
subroutine solve_triangular_system(logical upper, logical trans, logical nounit, real(real64) a(:,:), real(real64) x(:), optional class(errors) err)
subroutine solve_triangular_system(logical upper, logical trans, logical nounit, complex(real64) a(:,:), complex(real64) x(:), optional class(errors) err)
Parameters
[in]upperSet to true if A is an upper triangular matrix; else, set to false if A is a lower triangular matrix.
[in]transSet to true if \( op(A) = A^T \) ( \( op(A) = A^H \) in the complex case); else, set to false if \( op(A) = A \).
[in]nounitSet to true if A is not a unit-diagonal matrix (ones on every diagonal element); else, set to false if A is a unit-diagonal matrix.
[in]aThe N-by-N triangular matrix.
[in,out]xOn input, the N-element right-hand-side array. On output, the N-element solution array.
[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 a is not square, or if the sizes of a and b are not compatible.
Notes
This routine is based upon the BLAS routine DTRSV (ZTRSV in the complex case).
Usage
The following example illustrates the solution of two triangular systems to solve a system of LU factored equations.
program example
use iso_fortran_env, only : real64, int32
use linalg
implicit none
! Variables
real(real64) :: a(3,3), b(3), u(3,3), p(3,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)
! Extract the L and U matrices. A is overwritten with L.
call form_lu(a, pvt, u, p)
! Solve the lower triangular system L * Y = P * B for Y, but first compute
! P * B, and store the results in B
b = matmul(p, b)
! Now, compute the solution to the lower triangular system. Store the
! result in B. Remember, L is unit diagonal (ones on its diagonal)
call solve_triangular_system(.false., .false., .false., a, b)
! Solve the upper triangular system U * X = Y for X.
call solve_triangular_system(.true., .false., .true., u, b)
! Display the results.
print '(A)', "LU Solution: X = "
print '(F8.4)', (b(i), i = 1, size(b))
end program
Extracts the L and U matrices from the condensed [L\U] storage format used by the lu_factor.
Definition linalg.f90:967
Computes the LU factorization of an M-by-N matrix.
Definition linalg.f90:844
Performs sparse matrix multiplication C = A * B.
Definition linalg.f90:5382
Solves a triangular system of equations.
Definition linalg.f90:2316
Provides a set of common linear algebra routines.
Definition linalg.f90:145
The above program produces the following output.
LU Solution: X =
0.3333
-0.6667
0.0000

Definition at line 2316 of file linalg.f90.


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