Inverse Function

function Inverse(a)

Helper function that calculates the inverse of a matrix.

Calls the LAPACK routine GESV.

Arguments

Type IntentOptional AttributesName
real(kind=wp), intent(in), dimension(:,:):: a

A matrix, .

Return Value real(kind=wp), dimension(size(a,1),size(a,2))

On output contains .


Calls

proc~~inverse~~CallsGraph proc~inverse Inverse dgesv dgesv proc~inverse->dgesv

Called by

proc~~inverse~~CalledByGraph proc~inverse Inverse proc~init_ref_element init_ref_element proc~init_ref_element->proc~inverse interface~init_ref_element init_ref_element interface~init_ref_element->proc~init_ref_element interface~ref_element ref_element interface~ref_element->interface~init_ref_element proc~scal_schw_init scal_schw_init proc~scal_schw_init->interface~ref_element program~test test program~test->interface~ref_element interface~scal_schw_init scal_schw_init interface~scal_schw_init->proc~scal_schw_init

Contents

Source Code


Source Code

    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