Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Matrix Inversion LAPACKE_zsytri

Gianluca_G_
Beginner
272 Views

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
Gianluca_G_
Beginner
272 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
Ying_H_Intel
Employee
272 Views

Hi Gianluca G

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

Thanks

Ying

0 Kudos
Reply