- Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include "lapacke.h"
/* Auxiliary routines prototypes */
extern void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda );
/* Parameters */
#define N 3
#define LDA N
/* Main program */
int main() {
/* Locals */
lapack_int n = N, lda = LDA, info;
/* Local arrays */
double w[N];
double a[LDA*N] = {
3,2,4,
2,0,2,
4,2,3
};
/* Executable statements */
printf( "LAPACKE_dsyev (row-major, high-level) Example Program Results\n" );
/* Solve eigenproblem */
info = LAPACKE_dsyev( LAPACK_ROW_MAJOR, 'V', 'U', n, a, lda, w );
/* Check for convergence */
if( info > 0 ) {
printf( "The algorithm failed to compute eigenvalues.\n" );
exit( 1 );
}
print_matrix( "Eigenvalues", 1, n, w, 1 );
print_matrix( "Eigenvectors (stored columnwise)", n, n, a, lda );
exit( 0 );
} /* End of LAPACKE_dsyev Example */
/* Auxiliary routine: printing a matrix */
void print_matrix( char* desc, lapack_int m, lapack_int n, double* a, lapack_int lda ) {
lapack_int i, j;
printf( "\n %s\n", desc );
for( i = 0; i < m; i++ ) {
for( j = 0; j < n; j++ ) printf( " %6.2f", a[i*lda+j] );
printf( "\n" );
}
}
i also have another code for doing the same:
- Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include "lapacke.h"
/* Parameters */
/* Main program */
int main() {
char jobz='N',uplo='U';
int i;
double w[3];
lapack_int lda=3,n=3,info=8;
double a[9] = {
3,2,4,
2,0,2,
4,2,3
};
info=LAPACKE_dsyev(LAPACK_ROW_MAJOR,jobz,uplo, n ,&a[0], lda , &w[0]);
if( info > 0 ) {
printf( "The algorithm failed to compute eigenvalues.\n" );
exit( 1 );
}
for(i=0;i<9;i++)
{
printf("%f\n",w[i]);
}
exit( 0 );
} /* End of LAPACKE_dsyev Example */
but i am getting code 1:
Eigenvalues
-1.00 -1.00 8.00
Eigenvectors (stored columnwise)
-0.49 -0.56 0.67
-0.47 0.82 0.33
0.73 0.15 0.67
and code 2 :
-1.000000
-1.000000
8.000000
8399042787434929076379500977075822760523682999640557766090814118267425172824413287923039437671358267392.000000
0.000000
0.000000
0.000000
0.000000
0.000000
the eign values are okay ,
but the eign vectors are the problem here because :
http://math.oregonstate.edu/home/progra ... eigen.html
for k=-1: <1,-2,0> and <4,2,-5> for k=8: <2,1,2>
Where am i going wrong in both code 1 and code 2??
Any help/hint will be appreciated.

