/* nag_dtrsna (f08qlc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include #include int main(void) { /* 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); Vprintf("nag_dtrsna (f08qlc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%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)) ) { Vprintf("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) Vscanf("%lf", &T(i,j)); } Vscanf("%*[^\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) { Vprintf("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) { Vprintf("Error from nag_dtrsna (f08qlc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print condition numbers of eigenvalues and right eigenvectors */ Vprintf("\nS\n"); for (i = 0; i < n; ++i) Vprintf("%11.1e", s[i]); Vprintf("\n\nSep\n"); for (i = 0; i < n; ++i) Vprintf("%11.1e", sep[i]); Vprintf("\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) { Vprintf("Error from nag_dge_norm (f16rac).\n%s\n", fail.message); exit_status = 1; goto END; } /* nag_machine_precision (x02ajc). * The machine precision */ eps = X02AJC; Vprintf("\nApproximate error estimates for eigenvalues" "of T (machine dependent)\n"); for (i = 0; i < m; ++i) Vprintf("%11.1e", eps*tnorm/s[i]); Vprintf("\n\nApproximate error estimates for right eigenvectors" "of T (machine dependent)\n"); for (i = 0; i < m; ++i) Vprintf("%11.1e", eps*tnorm/sep[i]); Vprintf("\n"); END: 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; }