Community
cancel
Showing results for
Did you mean:
Beginner
61 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

2 Replies
Beginner
61 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;```

Employee
61 Views

Hi Gianluca G

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

Thanks

Ying