# LAPACK dgeev: parameter had illegal value

• Angelos K
In summary, LAPACK dgeev reports an error when a parameter has an illegal value. This means that the input given for that specific parameter is not valid and the function cannot proceed with the computation. It is important to ensure that all input values are within the acceptable range to avoid this error.
Angelos K
Mod note: I revised the code below slightly, changing the loop control variable i to either j or k. The reason for this is that the browser mistakes the letter i in brackets for the BBCode italics tag, which causes some array expressions to partially disappear.

Hello,

I am trying for the first time to use LAPACK from C to diagonalize a matrix and I am stuck.

I try to modify this example http://rcabreral.blogspot.co.uk/2010/05/eigenvalues-clapack.html from zgeev to degeev. I have looked at the DGEEV input parameters, but it seems I don't understand the well enough.

Below is my code. Running it produces:
** On entry to DGEEV parameter number 9 had an illegal value

EDIT: The error occurs in the call of degeev spanning lines 48 to (including) 53.
#include<stdio.h>
#include<math.h>

#include<complex.h>
#include <stdlib.h>

//...................
void dgeTranspose( double *Transposed, double *M ,int n)
{

int i,j;
for(i=0;i<n;i++)

for(j=0;j<n;j++) Transposed[i+n*j] = M[i*n+j];
}

//...................
// MatrixComplexEigensystem: computes the eigenvectors and eigenValues of input matrix A
// The eigenvectors are stored in columns
//..................
void MatrixComplexEigensystem( double *eigenvectorsVR, double *eigenvaluesW, double *A, int N)
{

int i;

double *AT = (double *) malloc( N*N*sizeof(double ) );

dgeTranspose( AT, A , N);

char JOBVL ='N'; // Compute Right eigenvectors

char JOBVR ='V'; // Do not compute Left eigenvectors

double VL[1];

int LDVL = 1;
int LDVR = N;

int LWORK = 4*N;

double *WORK = (double *)malloc( LWORK*sizeof(double));

double *RWORK = (double *)malloc( 2*N*sizeof(double));

int INFO;

dgeev_( &JOBVL, &JOBVR, &N, AT , &N , eigenvaluesW ,

VL, &LDVL,
eigenvectorsVR, &LDVR,
WORK,
&LWORK, RWORK, &INFO );

dgeTranspose( AT, eigenvectorsVR , N);

for(j=0;j<N*N;j++) eigenvectorsVR[j]=AT[j];

free(WORK);
free(RWORK);
free(AT);
}int main()
{
int i,j;
const int N = 3; double A[] = { 1.+I , 2. , 3 , 4. , 5.+I , 6. , 7., 8., 9. + I};

double eigenVectors[N*N];
double eigenValues[N]; MatrixComplexEigensystem( eigenVectors, eigenValues, A, N);

printf("\nEigenvectors\n");

for(k=0;k<N;k++){
for(j=0;j<N;j++) printf("%e", eigenVectors[k*N + j]);

printf("\n");
}

printf("\nEigenvalues \n");
for(j=0;i<N;j++) printf("%e", eigenValues[j] );printf("\n------------------------------------------------------------\n");
return 0;}
Any help much appreciated!

Last edited by a moderator:
Thanks. This code appears to work.

#include<stdio.h>
#include<math.h>

#include <stdlib.h>

//...................
void dgeTranspose( double *Transposed, double *M ,int n)
{

int i,j;
for(i=0;i<n;i++)

for(j=0;j<n;j++) Transposed[i+n*j] = M[i*n+j];
}

//...................
// MatrixComplexEigensystem: computes the eigenvectors and eigenValues of input matrix A
// The eigenvectors are stored in columns
//..................
void MatrixComplexEigensystem( double *eigenvectorsVR, double *eigenvaluesW, double *A, int N)
{

int i;

double *AT = (double *) malloc( N*N*sizeof(double ) );

dgeTranspose( AT, A , N);

char JOBVL ='N'; // Compute Right eigenvectors

char JOBVR ='V'; // Do not compute Left eigenvectors

double VL[1];

int LDVL = 1;
int LDVR = N;

int LWORK = 4*N;

double *WORK = (double *)malloc( LWORK*sizeof(double));

double *RWORK = (double *)malloc( 2*N*sizeof(double));

int INFO;
printf("\nping2\n");
double *eigenvaluesWR =eigenvaluesW;
double *eigenvaluesWI = eigenvaluesW + N;
dgeev_( &JOBVL, &JOBVR, &N, AT , &N,
eigenvaluesWR, eigenvaluesWI,
VL, &LDVL,
eigenvectorsVR, &LDVR,
WORK,
&LWORK, &INFO );
printf("\nping1\n");
dgeTranspose( AT, eigenvectorsVR , N);

for(j=0;i<N*N;j++) eigenvectorsVR[j]=AT[j];

free(WORK);
free(RWORK);
free(AT);
}int main()
{
int i,j;
const int N = 3; double A[] = { 1. , 0. , 0. , 0. , 1., 0. , 0., 0., 1.};

double eigenVectors[N*N];
double eigenValues[2*N]; MatrixComplexEigensystem( eigenVectors, eigenValues, A, N);

printf("\nEigenvectors\n");

for(i=0;i<N;i++){
for(j=0;j<N;j++) printf("%e ", eigenVectors[i*N + j]);

printf("\n");
}

printf("\nEigenvalues \n");
for(j=0;i<N;j++) printf("%e ", eigenValues[j] );printf("\n------------------------------------------------------------\n");
return 0;}​

Last edited by a moderator:
Did this work? Note that your code as it appear here is not the same as what you pasted in. Anywhere you have [ i ] (without spaces), the browser strips out, thinking that you want the text that follows it to be in italics. That's why I modified your code in post #1.

As far as I know, there's not a workaround, other than to not use i as an index in arrays.

Angelos K
Mark44 said:
Did this work? Note that your code as it appear here is not the same as what you pasted in. Anywhere you have [ i ] (without spaces), the browser strips out, thinking that you want the text that follows it to be in italics. That's why I modified your code in post #1.

As far as I know, there's not a workaround, other than to not use i as an index in arrays.

Thank you. It appears to work, but I have only tested trivial cases.

I saw your warning earlier, but understood it just now (blush). It seems I am not able to modify my post anymore. So I should replace [ i ] by [k] evereywhere and then make the corresponding logical adjustments, right?

What trubled me most - and I am a newbie - is that I understand the documentation here
http://www.netlib.org/lapack/explore-html/d9/d28/dgeev_8f.html
as asking for an integer N. while the code (the prototype and my version) uses &N.

It turns out that this is needed for translating the Fortran routines to C.
http://www.physics.orst.edu/~rubin/nacphy/lapack/cprogp.html

Last edited by a moderator:
Angelos K said:
Thank you. It appears to work, but I have only tested trivial cases.

I saw your warning earlier, but understood it just now (blush). It seems I am not able to modify my post anymore. So I should replace [ i ] by [k] evereywhere and then make the corresponding logical adjustments, right?
Or you could replace [ i ] by [ii] - that should work. Keep in mind that is only for code that you post here, and it is an artifact of the browser thinking that you are entering BBCode markup, which changes how text is rendered.

There is a limited-time window for members to change their posts, but we mentors don't have that limit, so I edited your post.
Angelos K said:
What trubled me most - and I am a newbie - is that I understand the documentation here
http://www.netlib.org/lapack/explore-html/d9/d28/dgeev_8f.html
as asking for an integer N. while the code (the prototype and my version) uses &N.

It turns out that this is needed for translating the Fortran routines to C.
You shouldn't have to do that, at least not for any parameters that are marked [in] in the documentation. A major difference between Fortran and C is how parameters are passed. In Fortran, they are passed by reference, but in C, they are passed by value. A Fortran subroutine or function is free to modify any of its parameters. In C, this can only be simulated by passing the address of (a pointer to) the thing whose value is to be changed.

In the DGEEV subroutine, the N parameter is marked as [in], which says that DGEEV is going to treat it as read-only. The parameters you need to watch out for (and for which addresses are needed) are the ones marked in the documentation with [in,out] or [out], such as A, WR, WI, VL, VR, and a couple of others. The error you showed in post #1 pertained to VL.

Any parameter that is marked [in] you shouldn't need to supply an address.
Angelos K said:
http://www.physics.orst.edu/~rubin/nacphy/lapack/cprogp.html

Angelos K
Thank you very much for the clarification about [in] parameters! As you resolved all problems: Should I mark this thread as solved, and if so, how?

Last edited:
Typically we don't do anything special, such as marking a thread "solved."

## What is LAPACK dgeev?

LAPACK dgeev is a subroutine in the LAPACK library that is used to compute the eigenvalues and eigenvectors of a general matrix.

## What does "parameter had illegal value" mean?

This error message means that one or more of the input parameters provided to the dgeev subroutine is invalid or outside of the acceptable range. This could be due to a mistake in the input or a bug in the code.

## How can I fix the "parameter had illegal value" error?

You will need to carefully check your code and make sure that all input parameters are valid and within the acceptable range. You may also need to consult the documentation for the dgeev subroutine to ensure that you are using the correct parameters.

## Can this error be caused by a bug in the LAPACK library?

It is possible, but unlikely. The LAPACK library is a well-tested and widely used software package, so errors in the library itself are rare. However, if you suspect that the error may be caused by a bug in the library, you can report it to the developers for further investigation.

## Is there any way to prevent the "parameter had illegal value" error?

Yes, you can prevent this error by carefully checking your code and ensuring that all input parameters are valid and within the acceptable range. You can also consult the documentation for the dgeev subroutine to ensure that you are using the correct parameters.

• Programming and Computer Science
Replies
5
Views
1K
• Programming and Computer Science
Replies
4
Views
1K
• Programming and Computer Science
Replies
2
Views
1K
• Programming and Computer Science
Replies
6
Views
2K
• Programming and Computer Science
Replies
18
Views
6K
• Programming and Computer Science
Replies
6
Views
3K
• Programming and Computer Science
Replies
6
Views
3K
• Programming and Computer Science
Replies
2
Views
2K
• Programming and Computer Science
Replies
4
Views
2K
• Programming and Computer Science
Replies
1
Views
1K