/* nag_hermitian_eigenvalues (f02awc) Example Program.
*
* Copyright 2014 Numerical Algorithms Group.
*
* Mark 2, 1991.
* Mark 8 revised, 2004.
*/
#include <nag.h>
#include <stdio.h>
#include <nag_stdlib.h>
#include <nagf02.h>
#define A(I, J) a[(I) *tda + J]
int main(void)
{
Complex *a = 0;
Integer exit_status = 0, i, j, n, tda;
NagError fail;
double *r = 0;
INIT_FAIL(fail);
printf(
"nag_hermitian_eigenvalues (f02awc) 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)))
{
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
tda = 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_eigenvalues (f02awc).
* All eigenvalues of complex Hermitian matrix
*/
nag_hermitian_eigenvalues(n, a, tda, r, &fail);
if (fail.code != NE_NOERROR)
{
printf("Error from nag_hermitian_eigenvalues (f02awc).\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("\n");
END:
NAG_FREE(r);
NAG_FREE(a);
return exit_status;
}