Foortran Toolkit

Fortran toolkit
Borja Petit


Download toolkit

Back to index

inverse

function inverse(m,method) result(im)
  implicit none
  real(kind=8)     , intent(in)            :: m(:,:)
  character(len=*) , intent(in) , optional :: method
  real(kind=8)                             :: im(size(m,1),size(m,1))

This function returns the inverse of a square matrix m. The input matrix is not modified. The optional argument method selects the algorithm:

Note that ‘qr’ and ‘svd’ treat a nearly singular matrix as rank-deficient, so for very ill-conditioned matrices (e.g. a Hilbert matrix of order 8) they return a pseudo-inverse and m*im is not the identity.

With method = ‘gj’, if m is not square, or if it is (numerically) singular, the function prints an error message (see error) and returns a matrix of zeros.

Internal dependencies: error