diff --git a/src/forinv.f90 b/src/forinv.f90 index 29868bf..e3abf78 100644 --- a/src/forinv.f90 +++ b/src/forinv.f90 @@ -1,6 +1,6 @@ module forinv - !This module provides functions and subroutines for pseudoinverse calculations. + !! This module provides functions and subroutines for inverse and pseudo-inverse calculations. use kinds use forsvd, only: svd @@ -12,7 +12,7 @@ module forinv public :: pinv !=============================================================================== - interface pinv + interface inv procedure :: pinv_rel end interface !=============================================================================== diff --git a/test/test1.f90 b/test/test1.f90 index befb182..c9b5bf5 100644 --- a/test/test1.f90 +++ b/test/test1.f90 @@ -1,10 +1,10 @@ program test1 - ! This Fortran test code demonstrates the usage of the pinv function to calculate the matrix inverse& + ! This Fortran test code demonstrates the usage of the inv function to calculate the matrix inverse& ! and verifies the results by comparing them with expected values obtained from MATLAB. use kinds ! Import the module 'kinds' for precision types - use forinv, only: pinv ! Import only the 'pinv' function from the 'forinv' module + use forinv, only: inv ! Import only the 'inv' function from the 'forinv' module implicit none @@ -22,7 +22,7 @@ program test1 !=============================================================================== - ! Define expected matrix AinvM=pinv(A) from MATLAB results + ! Define expected matrix AinvM=inv(A) from MATLAB results AinvM(1,1) = -11.8748418966254_rk ; AinvM(1,2) = -1.88508351433968_rk; AinvM(1,3) = 1.37910840173057_rk ; AinvM(1,4) = 13.3647936345720_rk AinvM(2,1) = -0.232262684677810_rk; AinvM(2,2) = -1.81026044323168_rk; AinvM(2,3) = 1.12793815267075_rk ; AinvM(2,4) = 1.84558847033752_rk AinvM(3,1) = 11.2481704396877_rk ; AinvM(3,2) = 2.87726069020400_rk ; AinvM(3,3) = -1.70926059704099_rk; AinvM(3,4) = -12.6490061903496_rk @@ -30,8 +30,8 @@ program test1 !=============================================================================== - ! Calculate the matrix inverse of A using the 'pinv' function - Ainv = pinv(A) + ! Calculate the matrix inverse of A using the 'inv' function + Ainv = inv(A) !=============================================================================== diff --git a/test/test2.f90 b/test/test2.f90 index c53795c..65a189b 100644 --- a/test/test2.f90 +++ b/test/test2.f90 @@ -1,7 +1,7 @@ program test2 use kinds ! Import the module 'kinds' for precision types - use forinv, only: pinv ! Import only the 'pinv' function from the 'forinv' module + use forinv, only: inv ! Import only the 'inv' function from the 'forinv' module implicit none @@ -14,8 +14,8 @@ program test2 allocate(A(m,n),Ainv1(n,m),Ainv2(n,m)) ! Allocate memory for matrix A call random_number(A) ! Fill matrix A with random numbers between 0 and 1 - Ainv1 = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function - Ainv2 = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function + Ainv1 = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function + Ainv2 = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function rel_err = norm2(Ainv1 - Ainv2)/norm2(Ainv1) diff --git a/test/test3.f90 b/test/test3.f90 index c2bce25..4e68d3a 100644 --- a/test/test3.f90 +++ b/test/test3.f90 @@ -1,10 +1,10 @@ program test3 - ! This Fortran test code demonstrates the usage of the pinv function to calculate the matrix inverse + ! This Fortran test code demonstrates the usage of the inv function to calculate the matrix inverse ! of a randomly generated matrix. use kinds ! Import the module 'kinds' for precision types - use forinv, only: pinv ! Import only the 'pinv' function from the 'forinv' module + use forinv, only: inv ! Import only the 'inv' function from the 'forinv' module use fortime implicit none @@ -20,13 +20,13 @@ program test3 call timer_start(w) - Ainv = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function + Ainv = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function call timer_stop(w,message=' Elapsed time (2000*200 , gesvd):') call timer_start(w) - Ainv = pinv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'pinv' function and the getrf method + Ainv = inv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'inv' function and the getrf method call timer_stop(w,message=' Elapsed time (2000*200 , getrf):') @@ -40,13 +40,13 @@ program test3 call timer_start(w) - Ainv = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function + Ainv = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function call timer_stop(w,message=' Elapsed time (2000*1800, gesvd):') call timer_start(w) - Ainv = pinv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'pinv' function and the getrf method + Ainv = inv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'inv' function and the getrf method call timer_stop(w,message=' Elapsed time (2000*1800, getrf):')