/* nag_dtrsen (f08qgc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(void) { /* Scalars */ Integer i, j, m, n, pdq, pdt, select_len, w_len; Integer exit_status=0; double s, sep; NagError fail; Nag_OrderType order; /* Arrays */ double *q=0, *t=0, *wi=0, *wr=0; char sel_char[2]; Nag_Boolean *select=0; #ifdef NAG_COLUMN_MAJOR #define T(I,J) t[(J-1)*pdt + I - 1] #define Q(I,J) q[(J-1)*pdq + I - 1] order = Nag_ColMajor; #else #define T(I,J) t[(I-1)*pdt + J - 1] #define Q(I,J) q[(I-1)*pdq + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); Vprintf("nag_dtrsen (f08qgc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%*[^\n] ", &n); #ifdef NAG_COLUMN_MAJOR pdq = n; pdt = n; #else pdq = n; pdt = n; #endif w_len =n; select_len = n; /* Allocate memory */ if ( !(q = NAG_ALLOC(n * n, double)) || !(wi = NAG_ALLOC(w_len, double)) || !(wr = NAG_ALLOC(w_len, double)) || !(select = NAG_ALLOC(select_len, Nag_Boolean)) || !(t = NAG_ALLOC(n * n, double)) ) { 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] "); for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) Vscanf("%lf", &Q(i,j)); } Vscanf("%*[^\n] "); for (i = 0; i < n; ++i) { Vscanf(" %1s ", sel_char); if (*(unsigned char *)sel_char == 'F') select[i] = Nag_FALSE; else select[i] = Nag_TRUE; } Vscanf("%*[^\n] "); /* Reorder the Schur factorization T */ /* nag_dtrsen (f08qgc). * Reorder Schur factorization of real matrix, form * orthonormal basis of right invariant subspace for * selected eigenvalues, with estimates of sensitivities */ nag_dtrsen(order, Nag_DoBoth, Nag_UpdateSchur, select, n, t, pdt, q, pdq, wr, wi, &m, &s, &sep, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_dtrsen (f08qgc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print reordered Schur form */ /* nag_gen_real_mat_print (x04cac). * Print real general matrix (easy-to-use) */ nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, n, t, pdt, "Reordered Schur form", 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print basis of invariant subspace */ /* nag_gen_real_mat_print (x04cac), see above. */ nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, m, q, pdq, "Basis of invariant subspace", 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print condition number estimates */ Vprintf("\n Condition number estimate of the selected cluster of" " eigenvalues = %10.2e\n",1.0/s); Vprintf("\n Condition number estimate of the specified invariant" " subspace = %10.2e\n",1.0/sep); END: if (q) NAG_FREE(q); if (t) NAG_FREE(t); if (wi) NAG_FREE(wi); if (wr) NAG_FREE(wr); if (select) NAG_FREE(select); return exit_status; }