Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
6 Views

Matrix Inversion LAPACKE_zsytri

hello everyone,

I'm testing the inversion of a symmetric matrix, in order to do that, I wrote this code:

Complex[,] c = (Complex[,])a.Clone(); //I need to use it later
Complex[,] d = (Complex[,])a.Clone(); //I need to use it later

int n = a.GetLength(0);
int lda = n;
int info = 1;

int[] ipiv = new int;

info = MKLWrapper.LAPACKE_zsytrf(LAPACK_ROW_MAJOR, UPLO_U, n, c, lda, ipiv);

info = MKLWrapper.LAPACKE_zsytri(LAPACK_ROW_MAJOR, UPLO_U, n, c, lda, ipiv);

ipiv = new int;

info = MKLWrapper.LAPACKE_zsytrf(LAPACK_ROW_MAJOR, UPLO_L, n, d, lda, ipiv);

info = MKLWrapper.LAPACKE_zsytri(LAPACK_ROW_MAJOR, UPLO_L, n, d, lda, ipiv);


for (int i = 1; i <= a.GetLength(0); i++)
{
	  for (int j = 1; j <= a.GetLength(1); j++)
  	{
		    if (i > j)
			      c[i, j] = d[i, j];
	  }
}

 

  

This code works, but I'm not sure this is the right way to obtain my aim.

Is there anyone that can help me?

Thank you very much

 

Gianluca

 

0 Kudos
2 Replies
Highlighted
Beginner
6 Views

 

The solution is easy! 

The inverted matrix of a symmetrical matrix is symmetrical too. So the right code is:

 

Complex[,] c = (Complex[,])a.Clone();

            int n = a.GetLength(0);
            int lda = n;
            int info = 1;

            int[] ipiv = new int;

            info = MKLWrapper.LAPACKE_zsytrf(LAPACK_ROW_MAJOR, UPLO_U, n, c, lda, ipiv);

            info = MKLWrapper.LAPACKE_zsytri(LAPACK_ROW_MAJOR, UPLO_U, n, c, lda, ipiv);


            for (int i = 1; i <= a.GetLength(0); i++)
            {
                for (int j = 1; j <= a.GetLength(1); j++)
                {
                    if (i > j)
                        c[i, j] = c[j, i];
                }
            }


            if (info == 0)
                return c;
            else
                return null;

 

0 Kudos
Highlighted
Employee
6 Views

Hi Gianluca G

You are right, you can use get the inversion like that.   Thank you for sharing. 

Thanks

Ying

0 Kudos