Error in lagack cgesv when matrix is ​​not singular

This is my first post. I usually ask my classmates for help, but they have a lot of work to do right now, and I'm too desperate to figure it out on my own. I'm working on a project for a school, and I've come to the point where I need to solve a system of linear equations with complex numbers. I decided to call the lapack routine "cgesv" from C ++. I am using a complex C ++ library to work with complex numbers.

The problem is that when I call the subroutine, I get the error code "2". From lapack documentation:

      INFO is INTEGER
      = 0:  successful exit
      < 0:  if INFO = -i, the i-th argument had an illegal value
      > 0:  if INFO = i, U(i,i) is exactly zero.  The factorization
            has been completed, but the factor U is exactly
            singular, so the solution could not be computed.

      

Therefore, the element U (2, 2) must be equal to zero, but it is not. This is how I declare the function:

void cgesv_ (int * N, int * NRHS, std :: complex * A, int * lda, int * ipiv, std :: complex * B, int * ldb, int * INFO);

This is how I use it:

    int *IPIV = new int[NA];
    int INFO, NRHS = 1;
    std::complex<double> *aMatrix = new std::complex<double>[NA*NA];

    for(int i=0; i<NA; i++){
            for(int j=0; j<NA; j++){
                    aMatrix[j*NA+i] = A[i][j]; 
            }
    }

    cgesv_( &NA, &NRHS, aMatrix, &NA, IPIV, B, &NB, &INFO );

      

And this is what the matrix looks like:

(1, -160.85) (0.0.000306796) (0, -0) (0, -0) (0, -0)

<0.02 (0.012), (0, 0, 30) (0, -0) (0.0.000306796) (1, -0.000613592) (0.0.000306796) (0, -0)

(0, -0) (0, -0) (0.0.000306796) (1, -40.213) (0.0.000306796)

(0, -0) (0, -0) (0, -0) (0.0.000306796) (1, -160.85)

I had to split matrix columns otherwise it would not format correctly.

My first suspicion was that complexity was not being handled correctly, but I have used lapack functions with complex numbers before.

Any ideas?

+3


source to share


1 answer


I realized what was wrong. The subroutine doesn't work if I use complex types. This is really weird because this type has worked in all the other LAPACK routines I've tried so far, even the complex matrix inverse, which is similar.



+1


source







All Articles