Helper function that calculates the inverse of a matrix.
Calls the LAPACK routine GESV.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:,:) | :: | a | A matrix, . |
On output contains .
function Inverse ( a )
!! Helper function that calculates the inverse of a matrix.
!!
!! Calls the LAPACK routine GESV.
real(wp), dimension(:,:), intent(in) :: a
!! A matrix, \(A\).
real(wp), dimension(size(a,1),size(a,2)) :: Inverse
!! On output contains \(A^{-1}\).
real(wp), dimension(size(a,1),size(a,2)) :: acopy, rhs
integer(ip), dimension(size(a,1)) :: ipiv
integer(ip) :: i, n, info
acopy = a
n = size(a,1)
rhs = 0.0_wp
forall(i=1:n) rhs(i,i) = 1.0_wp
call dgesv ( n, n, acopy, n, ipiv, rhs, n, info )
if (info <0) then
print*,'Parameter ', i, ' in call to dgesv has illegal value'
stop
end if
if (info >0) then
print*, 'Matrix in call to dgesv is singular'
stop
end if
Inverse = rhs
return
end function Inverse