help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] Invert a complex matrix ?


From: Mathieu Lenoble
Subject: [Help-gsl] Invert a complex matrix ?
Date: Tue, 30 Mar 2004 12:10:23 +0900

Hi,

I have a problem to find how invert a complex matrix! I read the How To of
the GSL and i followed some programs found on the web but it doesn't still
working !!
So, to invert my complex matrix i use the gsl_linalg_complex_LU_decomp(...)
following by gsl_linalg_complex_LU_invert(....) functions.

I give the code that i used :

"
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <math.h>

#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_complex.h>
#include <gsl/gsl_complex_math.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_cblas.h>

main(int argc, char *argv[]) {
int i,j,s;
gsl_permutation *p=gsl_permutation_alloc(2);
gsl_matrix_complex *es=gsl_matrix_complex_alloc(2,2);
gsl_matrix_complex *esinv=gsl_matrix_complex_alloc(2,2);

gsl_matrix_complex_set(es,0,0,gsl_complex_rect(0.5,1.0));
gsl_matrix_complex_set(es,0,1,gsl_complex_rect(1.0,-1.0));
gsl_matrix_complex_set(es,1,0,gsl_complex_rect(1.5,0.8));
gsl_matrix_complex_set(es,1,1,gsl_complex_rect(-0.5,1.4));

gsl_linalg_complex_LU_decomp(es,p,&s);
gsl_linalg_complex_LU_invert(es,p,esinv);

for(i=0;i<2;i++){
    for(j=0;j<2;j++){

printf("\nesinv(%d,%d)=%g+%g*j",i,j,GSL_REAL(gsl_matrix_complex_get(esinv,i,
j)),GSL_IMAG(gsl_matrix_complex_get(esinv,i,j)));
    }
}
printf("\n");

}
"
and here is the results that i obtained :

esinv(0,0)=5.20715e-141+1.06685e-194*j
esinv(0,1)=1.17094e-321+0*j
esinv(1,0)=2.10994e305+2.06841e149*j
esinv(1,1)=1+0*j

which are not the good results !!! (I checked with matlab)

I made exactly the same algorithm but for real matrix (using
gsl_linalg_LU_decomp(...) and gsl_linalg_LU_invert(...) ) and its works
perfectly, so i made probably something wrong for the complex matrix but i
really dont what is it !!

Thank you very much to help me on this !!

Mathieu.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]