/* nag_dtrsna (f08qlc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer i, j, m, n, pdt, pdvl, pdvr; Integer select_len, s_len; Integer exit_status = 0; double eps, tnorm; NagError fail; Nag_OrderType order; /* Arrays */ double *s = 0, *sep = 0, *t = 0, *vl = 0, *vr = 0; Nag_Boolean *select = 0; #ifdef NAG_COLUMN_MAJOR #define T(I, J) t[(J-1)*pdt + I - 1] order = Nag_ColMajor; #else #define T(I, J) t[(I-1)*pdt + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_dtrsna (f08qlc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &n); #ifdef NAG_COLUMN_MAJOR pdt = n; pdvl = n; pdvr = n; #else pdt = n; pdvl = n; pdvr = n; #endif select_len = 1; s_len = n; /* Allocate memory */ if (!(t = NAG_ALLOC(n * n, double)) || !(vl = NAG_ALLOC(n * n, double)) || !(vr = NAG_ALLOC(n * n, double)) || !(s = NAG_ALLOC(s_len, double)) || !(sep = NAG_ALLOC(s_len, double)) || !(select = NAG_ALLOC(select_len, Nag_Boolean))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Read T from data file */ for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &T(i, j)); } fscanf(fpin, "%*[^\n] "); /* Calculate right and left eigrnvectors of T */ /* nag_dtrevc (f08qkc). * Left and right eigenvectors of real upper * quasi-triangular matrix */ nag_dtrevc(order, Nag_BothSides, Nag_ComputeAll, select, n, t, pdt, vl, pdvl, vr, pdvr, n, &m, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dtrevc (f08qkc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Estimate condition numbers for all the eigenvalues and */ /* right eigenvectors of T */ /* nag_dtrsna (f08qlc). * Estimates of sensitivities of selected eigenvalues and * eigenvectors of real upper quasi-triangular matrix */ nag_dtrsna(order, Nag_DoBoth, Nag_ComputeAll, select, n, t, pdt, vl, pdvl, vr, pdvr, s, sep, n, &m, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dtrsna (f08qlc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print condition numbers of eigenvalues and right eigenvectors */ fprintf(fpout, "\nS\n"); for (i = 0; i < n; ++i) fprintf(fpout, "%11.1e", s[i]); fprintf(fpout, "\n\nSep\n"); for (i = 0; i < n; ++i) fprintf(fpout, "%11.1e", sep[i]); fprintf(fpout, "\n"); /* Calculate approximate error estimates (using the 1-norm) */ /* nag_dge_norm (f16rac). * 1-norm, infinity-norm, Frobenius norm, largest absolute * element, real general matrix */ nag_dge_norm(order, Nag_OneNorm, n, n, t, pdt, &tnorm, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dge_norm (f16rac).\n%s\n", fail.message); exit_status = 1; goto END; } /* nag_machine_precision (x02ajc). * The machine precision */ eps = nag_machine_precision; fprintf(fpout, "\nApproximate error estimates for eigenvalues" "of T (machine dependent)\n"); for (i = 0; i < m; ++i) fprintf(fpout, "%11.1e", eps*tnorm/s[i]); fprintf(fpout, "\n\nApproximate error estimates for right eigenvectors" "of T (machine dependent)\n"); for (i = 0; i < m; ++i) fprintf(fpout, "%11.1e", eps*tnorm/sep[i]); fprintf(fpout, "\n"); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (t) NAG_FREE(t); if (s) NAG_FREE(s); if (sep) NAG_FREE(sep); if (vl) NAG_FREE(vl); if (vr) NAG_FREE(vr); if (select) NAG_FREE(select); return exit_status; }