GNU Scientific Library determinant of complex array help

Click For Summary

Discussion Overview

The discussion revolves around finding the determinant of a complex 6x6 array using the GNU Scientific Library (GSL) in C. Participants explore issues related to data types, function compatibility, and potential solutions for working with complex numbers in GSL.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes their attempt to compute the determinant using a double complex array and encounters a compilation error related to incompatible pointer types.
  • Several participants suggest that to use GSL functions with complex numbers, conversion to GSL's complex types is necessary.
  • Another participant argues that the inefficiency of converting types is negligible compared to the computational complexity of calculating a determinant.
  • There is a suggestion to allocate a GSL matrix and fill it using loops to ensure compatibility with the expected data types.
  • A later reply indicates that looping through components to convert the matrix seems to resolve the compilation issue.
  • One participant mentions an alternative approach using LAPACK, which can work with ordinary Fortran arrays.

Areas of Agreement / Disagreement

Participants generally agree that the data type of the input matrix is the source of the problem and that conversion to the appropriate type is necessary. However, there is no consensus on the best approach to handle the conversion or whether the inefficiency of such conversions is a significant concern.

Contextual Notes

Participants express uncertainty about the reasons for the initial failure to compile and the implications of using different data types. The discussion includes various suggestions and corrections without resolving the underlying issues of type compatibility.

Who May Find This Useful

Readers interested in programming with the GNU Scientific Library, particularly those dealing with complex numbers in C, may find the insights and troubleshooting approaches shared in this discussion helpful.

tosburn3
Messages
6
Reaction score
0
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 *’
 
Last edited:
Technology news on Phys.org
Welcome to PF, tosburn3! :smile:

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 like Serena said:
Welcome to PF, tosburn3! :smile:

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).
 
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?
 
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 *’
 
I like Serena said:
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.
 
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.
 
I like Serena said:
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.
 
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!
 
  • #10
Good! :wink:
 
  • #11
Alternatively you could use LAPACK, which will work on an ordinary Fortran array.
 

Similar threads

  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K