/* 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; 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("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, 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 */ f08qkc(order, Nag_BothSides, Nag_ComputeAll, select, n, t, pdt, vl, pdvl, vr, pdvr, n, &m, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08qkc.\n%s\n", fail.message); exit_status = 1; goto END; } /* Estimate condition numbers for all the eigenvalues and */ /* right eigenvectors of T */ f08qlc(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 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) */ f16rac(order, Nag_OneNorm, n, n, t, pdt, &tnorm, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f16rac.\n%s\n", fail.message); exit_status = 1; goto END; } 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; }