DGEEVX returning incorrect eigenvalues

Post here if you have a question about LAPACK performance

DGEEVX returning incorrect eigenvalues

I tried to use DGEEV to obtain correct eigenvalues for a 3*3 matrix but the wrong values were returned. I am new to this forum and lapack so I looked through the forum and saw that sometimes balancing the matrix can lead the computation to work incorrectly so i used DGEEVX. I tried all of the options for BALANC systematically, and none of them seemed to return the correct eigenvalues. My c++ code is featured below:
#include <iostream>
#include <cstdlib>
using namespace std;
extern "C" void dgeevx_(char * balanc, char * jobvl, char * jobvr, char *sense, int * n, double * a, int * lda, double * wr, double * wi, double * vl, int * ldvl,double *vr, int *ldvr, int * ilo, int * ihi, double * scale, double * abnrm, double * rconde, double *rcondv, double * work, int * lwork, int * iwork, int * info);
int main()
{
char balanc = 'N';
char jobvl = 'v';
char jobvr = 'v';
char sense = 'B';
int n = 3;
int lda = 3;
int ldvl = 3;
int ldvr = 3;
double a[lda][n] = {{2,1,-1},{0,2,0},{0,1,1}};
double wr[n];
double wi[n];
double vl[ldvl][n];
double vr[ldvr][n];
int ilo;
int ihi;
double scale[n];
double abnrm;
double rconde[n];
double rcondv[n];
int lwork = n*(n+6);
double work[lwork];
int iwork[2*n-2];
int info;
dgeevx_(&balanc,&jobvl,&jobvr,&sense, &n, &a[lda][n], &lda, &wr[n], &wi[n], &vl[ldvl][n], &ldvl, &vr[ldvr][n], &ldvr, &ilo, &ihi, &scale[n], &abnrm, &rconde[n], &rcondv[n], &work[lwork], &lwork, &iwork[2*n-2], &info);
cout<< "the eigenvalues are ";
cout<< "real....";
cout<<'\n';
for (int a=0;a<n;a++)
{
cout <<wr[a] <<" ";
}
cout <<'\n';
cout <<"Imaginary...";
cout <<'\n';
for (int b=0; b<n; b++)
{cout <<wi[b] <<" ";
}
return 0;
}

Thank you for reading this! If this question is answered somewhere else you can refer me to that answer.
Upper triangularly,
H a r
0 r y
0 0 0 (Harry)
I'm using LAPACK 3.0 if it makes a difference in evaluating bugs.
Last edited by c++matrixmadness on Thu Jun 16, 2016 3:21 pm, edited 1 time in total.