linalg  1.4.3
A linear algebra library that provides a user-friendly interface to several BLAS and LAPACK routines.
linalg_solve::solve_least_squares_full Interface Reference

Solves the overdetermined or underdetermined system (A*X = B) of M equations of N unknowns, but uses a full orthogonal factorization of the system. More...

Private Member Functions

subroutine solve_least_squares_mtx_pvt (a, b, ipvt, arnk, work, olwork, err)
 Solves the overdetermined or underdetermined system (A*X = B) of M equations of N unknowns using a complete orthogonal factorization of matrix A. More...
 
subroutine solve_least_squares_vec_pvt (a, b, ipvt, arnk, work, olwork, err)
 Solves the overdetermined or underdetermined system (A*X = B) of M equations of N unknowns using a complete orthogonal factorization of matrix A. More...
 

Detailed Description

Solves the overdetermined or underdetermined system (A*X = B) of M equations of N unknowns, but uses a full orthogonal factorization of the system.

Usage
The following example illustrates the least squares solution of an overdetermined system of linear equations.
program example
use iso_fortran_env, only : real64, int32
implicit none
! Local Variables
real(real64) :: a(3,2), b(3)
integer(int32) :: i
! Build the 3-by-2 matrix A
! | 2 1 |
! A = |-3 1 |
! |-1 1 |
a = reshape([2.0d0, -3.0d0, -1.0d0, 1.0d0, 1.0d0, 1.0d0], [3, 2])
! Build the right-hand-side vector B.
! |-1 |
! b = |-2 |
! | 1 |
b = [-1.0d0, -2.0d0, 1.0d0]
! The solution is:
! x = [0.13158, -0.57895]**T
! Compute the solution via a least-squares approach. The results overwrite
! the first 2 elements in b.
! Display the results
print '(A)', "Least Squares Solution: X = "
print '(F9.5)', (b(i), i = 1, size(a, 2))
end program
The above program produces the following output.
Least Squares Solution: X =
0.13158
-0.57895

Definition at line 404 of file linalg_solve.f90.

Member Function/Subroutine Documentation

◆ solve_least_squares_mtx_pvt()

subroutine linalg_solve::solve_least_squares_full::solve_least_squares_mtx_pvt ( real(real64), dimension(:,:), intent(inout)  a,
real(real64), dimension(:,:), intent(inout)  b,
integer(int32), dimension(:), intent(inout), optional, target  ipvt,
integer(int32), intent(out), optional  arnk,
real(real64), dimension(:), intent(out), optional, target  work,
integer(int32), intent(out), optional  olwork,
class(errors), intent(inout), optional, target  err 
)
private

Solves the overdetermined or underdetermined system (A*X = B) of M equations of N unknowns using a complete orthogonal factorization of matrix A.

Parameters
[in,out]aOn input, the M-by-N matrix A. On output, the matrix is overwritten by the details of its complete orthogonal factorization.
[in,out]bIf M >= N, the M-by-NRHS matrix B. On output, the first N rows contain the N-by-NRHS solution matrix X. If M < N, an N-by-NRHS matrix with the first M rows containing the matrix B. On output, the N-by-NRHS solution matrix X.
[out]ipvtAn optional input that on input, an N-element array that if IPVT(I) .ne. 0, the I-th column of A is permuted to the front of A * P; if IPVT(I) = 0, the I-th column of A is a free column. On output, if IPVT(I) = K, then the I-th column of A * P was the K-th column of A. If not supplied, memory is allocated internally, and IPVT is set to all zeros such that all columns are treated as free.
[out]arnkAn optional output, that if provided, will return the rank of a.
[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]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.
Notes
This routine utilizes the LAPACK routine DGELSY.

Definition at line 2184 of file linalg_solve.f90.

◆ solve_least_squares_vec_pvt()

subroutine linalg_solve::solve_least_squares_full::solve_least_squares_vec_pvt ( real(real64), dimension(:,:), intent(inout)  a,
real(real64), dimension(:), intent(inout)  b,
integer(int32), dimension(:), intent(inout), optional, target  ipvt,
integer(int32), intent(out), optional  arnk,
real(real64), dimension(:), intent(out), optional, target  work,
integer(int32), intent(out), optional  olwork,
class(errors), intent(inout), optional, target  err 
)
private

Solves the overdetermined or underdetermined system (A*X = B) of M equations of N unknowns using a complete orthogonal factorization of matrix A.

Parameters
[in,out]aOn input, the M-by-N matrix A. On output, the matrix is overwritten by the details of its complete orthogonal factorization.
[in,out]bIf M >= N, the M-element array B. On output, the first N elements contain the N-element solution array X. If M < N, an N-element array with the first M elements containing the array B. On output, the N-element solution array X.
[out]ipvtAn optional input that on input, an N-element array that if IPVT(I) .ne. 0, the I-th column of A is permuted to the front of A * P; if IPVT(I) = 0, the I-th column of A is a free column. On output, if IPVT(I) = K, then the I-th column of A * P was the K-th column of A. If not supplied, memory is allocated internally, and IPVT is set to all zeros such that all columns are treated as free.
[out]arnkAn optional output, that if provided, will return the rank of a.
[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]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.
Notes
This routine utilizes the LAPACK routine DGELSY.

Definition at line 2328 of file linalg_solve.f90.


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