-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
! Matrix pseudo-inversion example: function, subroutine, and operator interfaces | ||
program example_pseudoinverse | ||
use stdlib_linalg, only: pinv, pseudoinvert, operator(.pinv.), linalg_state_type | ||
implicit none(type,external) | ||
|
||
real :: A(15,5), Am1(5,15) | ||
type(linalg_state_type) :: state | ||
integer :: i, j | ||
real, parameter :: tol = sqrt(epsilon(0.0)) | ||
|
||
! Generate random matrix A (15x15) | ||
call random_number(A) | ||
|
||
! Pseudo-inverse: Function interfcae | ||
Am1 = pinv(A, err=state) | ||
print *, 'Max error (function) : ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
! User threshold | ||
Am1 = pinv(A, rtol=0.001, err=state) | ||
print *, 'Max error (rtol=0.001): ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
! Pseudo-inverse: Subroutine interface | ||
call pseudoinvert(A, Am1, err=state) | ||
|
||
print *, 'Max error (subroutine): ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
! Operator interface | ||
Am1 = .pinv.A | ||
|
||
print *, 'Max error (operator) : ', maxval(abs(A-matmul(A, matmul(Am1,A)))) | ||
|
||
end program example_pseudoinverse |