/* nag_dsterf (f08jfc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include 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_dsterf (f08jfc) Example Program Results\n\n"); /* Skip heading in data file */ scanf("%*[^\n] "); scanf("%ld%*[^\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_dsterf (f08jfc). * All eigenvalues of real symmetric tridiagonal matrix, * root-free variant of QL or QR */ nag_dsterf(n, d, e, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_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.4lf", d[i]); printf("\n"); END: NAG_FREE(d); NAG_FREE(e); return exit_status; }