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

Computes the Moore-Penrose pseudo-inverse of a M-by-N matrix using the singular value decomposition of the matrix. More...

Public Member Functions

 mtx_pinverse_dbl
 
 mtx_pinverse_cmplx
 

Detailed Description

Computes the Moore-Penrose pseudo-inverse of a M-by-N matrix using the singular value decomposition of the matrix.

Syntax
subroutine mtx_pinverse(real(real64) a(:,:), real(real64) ainv(:,:), optional real(real64) tol, optional real(real64) work(:), optional integer(int32) olwork, optional class(errors) err)
subroutine mtx_pinverse(complex(real64) a(:,:), complex(real64) ainv(:,:), optional real(real64) tol, optional complex(real64) work(:), optional integer(int32) olwork, optional real(real64) rwork(:), optional class(errors) err)
Parameters
[in,out]aOn input, the M-by-N matrix to invert. The matrix is overwritten on output.
[out]ainvThe N-by-M matrix where the pseudo-inverse of a will be written.
[in]tolAn optional input, that if supplied, overrides the default tolerance on singular values such that singular values less than this tolerance are forced to have a reciprocal of zero, as opposed to 1/S(I). The default tolerance is: MAX(M, N) * EPS * MAX(S). If the supplied value is less than a value that causes an overflow, the tolerance reverts back to its default value, and the operation continues; however, a warning message is issued.
[out]workAn optional input, that if provided, prevents any local memory allocation. If not provided, the memory required is allocated within. If provided, the length of the array must be at least olwork.
[out]olworkAn optional output used to determine workspace size. If supplied, the routine determines the optimal size for work, and returns without performing any actual calculations.
[out]rworkAn optional input, that if provided, prevents any local memory allocation for real-valued workspaces. If not provided, the memory required is allocated within. If provided, the length of the array must be at least 6 * MIN(M, N).
[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 any of the input arrays are not sized appropriately.
  • LA_OUT_OF_MEMORY_ERROR: Occurs if local memory must be allocated, and there is insufficient memory available.
  • LA_CONVERGENCE_ERROR: Occurs as a warning if the QR iteration process could not converge to a zero value.
See Also
Usage
The following example illustrates how to compute the Moore-Penrose pseudo-inverse of a matrix.
program example
use iso_fortran_env, only : int32, real64
use linalg
implicit none
! Variables
real(real64) :: a(3,2), ai(2,3), ao(3,2), c(2,2)
integer(int32) :: i
! Create the 3-by-2 matrix A
! | 1 0 |
! A = | 0 1 |
! | 0 1 |
a = reshape([1.0d0, 0.0d0, 0.0d0, 0.0d0, 1.0d0, 1.0d0], [3, 2])
ao = a ! Just making a copy for later as mtx_pinverse will destroy the
! contents of the original matrix
! The Moore-Penrose pseudo-inverse of this matrix is:
! | 1 0 0 |
! A**-1 = | |
! | 0 1/2 1/2 |
call mtx_pinverse(a, ai)
! Notice, A**-1 * A is an identity matrix.
c = matmul(ai, ao)
! Display the inverse
print '(A)', "Inverse:"
do i = 1, size(ai, 1)
print *, ai(i,:)
end do
! Display the result of inv(A) * A
print '(A)', "A**-1 * A:"
do i = 1, size(c, 1)
print *, c(i,:)
end do
end program
Performs sparse matrix multiplication C = A * B.
Definition linalg.f90:5382
Computes the Moore-Penrose pseudo-inverse of a M-by-N matrix using the singular value decomposition o...
Definition linalg.f90:3157
Provides a set of common linear algebra routines.
Definition linalg.f90:145
The above program produces the following output.
Inverse:
1.0000000000000000 0.0000000000000000 0.0000000000000000
0.0000000000000000 0.49999999999999978 0.49999999999999989
A**-1 * A:
1.0000000000000000 0.0000000000000000
0.0000000000000000 0.99999999999999967

Definition at line 3157 of file linalg.f90.


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