GNU Scientific Library determinant of complex array help


by tosburn3
Tags: array, complex, determinant, library, scientific
tosburn3
tosburn3 is offline
#1
Mar15-12, 05:26 PM
P: 6
So I suck at programming, but I need to find the determinant of a complex 6x6 array using GSL in C (not GSL complex, complex.h complex). Here is what has failed so far starting with a 6x6 double complex array named mymatrix:

gsl_matrix_complex_view m = gsl_matrix_complex_view_array(mymatrix, 6, 6);
int s;
gsl_permutation *p = gsl_permutation_alloc(6);
gsl_linalg_complex_LU_decomp(&m.matrix, p, &s);
gsl_complex det2 = gsl_linalg_complex_LU_det(&m.matrix, s);
double complex det1 = GSL_REAL(det2)+I*GSL_IMAG(det2);

I refuse to convert my entire program to GSL's complex stuff if you think that would fix it. Here is the error message when compiling in gcc:

lorenz_odd_1.c: In function ‘det’:
lorenz_odd_1.c:122:1: warning: passing argument 1 of ‘gsl_matrix_complex_view_array’ from incompatible pointer type
/usr/local/include/gsl/gsl_matrix_complex_double.h:128:1: note: expected ‘double *’ but argument is of type ‘__complex__ double *’
Phys.Org News Partner Science news on Phys.org
SensaBubble: It's a bubble, but not as we know it (w/ video)
The hemihelix: Scientists discover a new shape using rubber bands (w/ video)
Microbes provide insights into evolution of human language
I like Serena
I like Serena is offline
#2
Mar15-12, 06:23 PM
HW Helper
I like Serena's Avatar
P: 6,189
Welcome to PF, tosburn3!

To make any function of GSL work with complex numbers, you need to convert your complex numbers to GSL complex stuff.

Yeah... so I'm suggesting that one.
Sorry.
tosburn3
tosburn3 is offline
#3
Mar15-12, 06:54 PM
P: 6
Quote Quote by I like Serena View Post
Welcome to PF, tosburn3!

To make any function of GSL work with complex numbers, you need to convert your complex numbers to GSL complex stuff.

Yeah... so I'm suggesting that one.
Sorry.
I don't care if I have to use GSL crap as intermediate steps. I just want to start with a regular complex array and end with a regular complex number. It was my understanding that:

gsl_matrix_complex_view m = gsl_matrix_complex_view_array(mymatrix, 6, 6);

Will take "mymatrix" and make a gsl_matrix_complex called "m", and then at the end I convert back to a regular complex number (quite inefficiently I might add).

I like Serena
I like Serena is offline
#4
Mar15-12, 06:59 PM
HW Helper
I like Serena's Avatar
P: 6,189

GNU Scientific Library determinant of complex array help


It does not matter if it's inefficient.
In terms of performance, calculating a determinant is so much more computationally difficult, that a conversion of complex numbers matters not at all.
It's only a little more code.

But... what is your problem then?
tosburn3
tosburn3 is offline
#5
Mar15-12, 07:08 PM
P: 6
FWIW here is the error message when compiling with gcc (updated original post for recent version):

lorenz_odd_1.c: In function ‘det’:
lorenz_odd_1.c:122:1: warning: passing argument 1 of ‘gsl_matrix_complex_view_array’ from incompatible pointer type
/usr/local/include/gsl/gsl_matrix_complex_double.h:128:1: note: expected ‘double *’ but argument is of type ‘__complex__ double *’
tosburn3
tosburn3 is offline
#6
Mar15-12, 07:20 PM
P: 6
Quote Quote by I like Serena View Post
It does not matter if it's inefficient.
In terms of performance, calculating a determinant is so much more computationally difficult, that a conversion of complex numbers matters not at all.
It's only a little more code.

But... what is your problem then?
Also, the inefficiency was actually that I computed the determinant once for the real part then again for the imaginary part, which would in fact take a lot longer.
I like Serena
I like Serena is offline
#7
Mar15-12, 07:21 PM
HW Helper
I like Serena's Avatar
P: 6,189
Oh okay, so your "mymatrix" is of the wrong type, apparently something like "double complex*".
How did you define "mymatrix"?

Anyway, I strongly recommend that you convert your mymatrix to the type gsl_matrix_complex_view_array() expects.
Just allocate the gsl matrix and fill it with 2 for-loops.
It really does not pay to try to make any shortcuts here.

Generally any shortcuts work against you.
If not now, then later.
tosburn3
tosburn3 is offline
#8
Mar15-12, 07:24 PM
P: 6
Quote Quote by I like Serena View Post
Oh okay, so your "mymatrix" is of the wrong type, apparently something like "double complex*".
How did you define "mymatrix"?

Anyway, I strongly recommend that you convert your mymatrix to the type gsl_matrix_complex_view_array() expects.
Just allocate the gsl matrix and fill it with 2 for-loops.
It really does not pay to try to make any shortcuts here.

Generally any shortcuts work against you.
If not now, then later.
mymatrix is in fact a double complex. I will try that.
tosburn3
tosburn3 is offline
#9
Mar15-12, 07:59 PM
P: 6
While I'm still not sure why the other way didn't work, looping through each component seems to work. At least it compiles...

Thanks!
I like Serena
I like Serena is offline
#10
Mar15-12, 08:16 PM
HW Helper
I like Serena's Avatar
P: 6,189
Good!
AlephZero
AlephZero is offline
#11
Mar15-12, 10:05 PM
Engineering
Sci Advisor
HW Helper
Thanks
P: 6,388
Alternatively you could use LAPACK, which will work on an ordinary Fortran array.


Register to reply

Related Discussions
Determinant of a Complex Matrix General Math 2
Need help using GNU scientific library Programming & Computer Science 15
GSL(GNU Scientific Library) Programming & Computer Science 3
Fortran, complex array with rank one Programming & Computer Science 7
C++ complex array Programming & Computer Science 3