Here is a example of complex matrix inversion code by using MKL.
#include
#include
#define MKL_Complex16 std::complex<double>
#include "mkl.h"
using namespace std;
void inverse(complex<double>* A, int N)
{
int *IPIV = new int[N+1];
int LWORK = N*N;
complex<double> *WORK = new complex<double>[LWORK];
int INFO;
zgetrf_(&N,&N,A,&N,IPIV,&INFO);
zgetri_(&N,A,&N,IPIV,WORK,&LWORK,&INFO);
delete IPIV;
delete WORK;
}
int main()
{
int n=2;
complex<double> * A = new complex<double> [n*n];
A[0]=complex<double>(1.,2.);
A[1]=complex<double>(3.,4.);
A[2]=complex<double>(5.,6.);
A[3]=complex<double>(7.,8.);
inverse(A,n);
for(int i=0;i<4;i++)
cout<
return 0;
}
#include
#define MKL_Complex16 std::complex<double>
#include "mkl.h"
using namespace std;
void inverse(complex<double>* A, int N)
{
int *IPIV = new int[N+1];
int LWORK = N*N;
complex<double> *WORK = new complex<double>[LWORK];
int INFO;
zgetrf_(&N,&N,A,&N,IPIV,&INFO);
zgetri_(&N,A,&N,IPIV,WORK,&LWORK,&INFO);
delete IPIV;
delete WORK;
}
int main()
{
int n=2;
complex<double> * A = new complex<double> [n*n];
A[0]=complex<double>(1.,2.);
A[1]=complex<double>(3.,4.);
A[2]=complex<double>(5.,6.);
A[3]=complex<double>(7.,8.);
inverse(A,n);
for(int i=0;i<4;i++)
cout<
return 0;
}
Output is:
(-0.5,0.4375)
(0.25,-0.1875)
(0.375,-0.3125)
(-0.125,0.0625)
(0.25,-0.1875)
(0.375,-0.3125)
(-0.125,0.0625)
For comparing same code in numpy :
In [1]: from numpy.linalg import inv
In [2]: x=np.array([[1+2j,3+4j],[5+6j,7+8j]], dtype=complex)
In [3]: inv(x)
Out[3]:
array([[-0.500+0.4375j, 0.250-0.1875j],
[ 0.375-0.3125j, -0.125+0.0625j]])
In [2]: x=np.array([[1+2j,3+4j],[5+6j,7+8j]], dtype=complex)
In [3]: inv(x)
Out[3]:
array([[-0.500+0.4375j, 0.250-0.1875j],
[ 0.375-0.3125j, -0.125+0.0625j]])
Comments
Post a Comment