/* nag_ztrsna (f08qyc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #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; Complex *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("f08qyc 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, Complex)) || !(vl = NAG_ALLOC(n * n, Complex)) || !(vr = NAG_ALLOC(n * n, Complex)) || !(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 , %lf ) ", &T(i,j).re, &T(i,j).im); } Vscanf("%*[^\n] "); /* Calculate right and left eigrnvectors of T */ f08qxc(order, Nag_BothSides, Nag_ComputeAll, select, n, t, pdt, vl, pdvl, vr, pdvr, n, &m, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08qxc.\n%s\n", fail.message); exit_status = 1; goto END; } /* Estimate condition numbers for all the eigenvalues and */ /* right eigenvectors of T */ f08qyc(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 f08qyc.\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) */ f16uac(order, Nag_OneNorm, n, n, t, pdt, &tnorm, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f16uac.\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; }