/* nag_hermitian_eigensystem (f02axc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include #include #include #include #define A(I, J) a[(I) *tda + J] #define V(I, J) v[(I) *tdv + J] int main(void) { Complex *a = 0, *v = 0; Integer exit_status = 0, i, j, n, tda, tdv; NagError fail; double *r = 0; INIT_FAIL(fail); printf( "nag_hermitian_eigensystem (f02axc) Example Program Results\n"); scanf("%*[^\n]"); /* Skip heading in data file */ scanf("%ld", &n); if (n >= 1) { if (!(r = NAG_ALLOC(n, double)) || !(a = NAG_ALLOC((n)*(n), Complex)) || !(v = NAG_ALLOC((n)*(n), Complex))) { printf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; tdv = n; } else { printf("Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf(" ( %lf, %lf ) ", &A(i, j).re, &A(i, j).im); /* nag_hermitian_eigensystem (f02axc). * All eigenvalues and eigenvectors of complex Hermitian * matrix */ nag_hermitian_eigensystem(n, a, tda, r, v, tdv, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_hermitian_eigensystem (f02axc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("Eigenvalues\n"); for (i = 0; i < n; i++) printf("%9.4f", r[i]); printf("\nEigenvectors\n"); for (i = 0; i < n; i++) for (j = 0; j < n; j++) printf("(%7.3f %7.3f )%s", V(i, j).re, V(i, j).im, (j%4 == 3 || j == n-1)?"\n":" "); END: if (r) NAG_FREE(r); if (a) NAG_FREE(a); if (v) NAG_FREE(v); return exit_status; }