/* nag_lapackeig_dsterf (f08jfc) Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
*
* Mark 30.3, 2024.
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Scalars */
Integer i, n, d_len, e_len;
Integer exit_status = 0;
NagError fail;
/* Arrays */
double *d = 0, *e = 0;
INIT_FAIL(fail);
printf("nag_lapackeig_dsterf (f08jfc) Example Program Results\n\n");
/* Skip heading in data file */
scanf("%*[^\n] ");
scanf("%" NAG_IFMT "%*[^\n] ", &n);
d_len = n;
e_len = n - 1;
/* Allocate memory */
if (!(d = NAG_ALLOC(d_len, double)) || !(e = NAG_ALLOC(e_len, double))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
/* Read T from data file */
for (i = 0; i < d_len; ++i)
scanf("%lf", &d[i]);
for (i = 0; i < e_len; ++i)
scanf("%lf", &e[i]);
/* Calculate all the eigenvalues of T */
/* nag_lapackeig_dsterf (f08jfc).
* All eigenvalues of real symmetric tridiagonal matrix,
* root-free variant of QL or QR
*/
nag_lapackeig_dsterf(n, d, e, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_lapackeig_dsterf (f08jfc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
/* Print eigenvalues */
printf(" Eigenvalues\n");
for (i = 0; i < n; ++i)
printf(" %7.4f", d[i]);
printf("\n");
END:
NAG_FREE(d);
NAG_FREE(e);
return exit_status;
}