Page 1 of 1

how to use dgetri_ routine to compute inverse of a matrix

PostPosted: Thu Oct 27, 2005 10:58 pm
by zimmerman
Can anyone help me ?
When I use this routine , I cann't get the right inverse of a matrix. If matrix is a uptriangular matrix ,the answer is right ,but when matrix is general, the answer is not correct.
How to use it ? How to set the ipiv .
Can anyone help me? Thank you!

Can anyone give me an example on how to use this routine?
Thankyou!

PostPosted: Fri Oct 28, 2005 12:15 am
by Julien Langou
Before calling DGETRI you first need to call DGETRF.

In C, the calling sequence looks like :
Code: Select all
      dgetrf_( &n, &n, a, &lda, ipiv, &info );
      if (info==0)
           dgetri_( &n, a, &lda, ipiv, work, &lwork, &info );


DGETRF will perform the LU factorization of A and take care of ipiv for you.
This piece of code works for any nonsingular matrix.

Julien

PS: Your observation is correct. If you have a upper triangular matrix: there is no pivoting, the U factor is the matrix itself and the L factor is the identity. So basically you do not need DGETRF. DGETRF on A upper triangular returns A unchanged. (Regarding the pivot in IPIV, you are a bit more lucky....)

Thank you

PostPosted: Fri Oct 28, 2005 1:53 am
by zimmerman
Julien:
Thank you very much. With your help , I have got the right answer.