/* nag_ztrsen (f08quc) 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 */ Complex *q=0, *t=0, *w=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_ztrsen (f08quc) 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, Complex)) || !(w = NAG_ALLOC(w_len, Complex)) || !(select = NAG_ALLOC(select_len, Nag_Boolean)) || !(t = NAG_ALLOC(n * n, Complex)) ) { 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] "); for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) Vscanf(" ( %lf , %lf ) ", &Q(i,j).re, &Q(i,j).im); } 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_ztrsen (f08quc). * Reorder Schur factorization of complex matrix, form * orthonormal basis of right invariant subspace for * selected eigenvalues, with estimates of sensitivities */ nag_ztrsen(order, Nag_DoBoth, Nag_UpdateSchur, select, n, t, pdt, q, pdq, w, &m, &s, &sep, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_ztrsen (f08quc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print reordered Schur form */ /* nag_gen_complx_mat_print_comp (x04dbc). * Print complex general matrix (comprehensive) */ nag_gen_complx_mat_print_comp(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, n, t, pdt, Nag_BracketForm, "%7.4f", "Reordered Schur form", Nag_IntegerLabels, 0, Nag_IntegerLabels, 0, 80, 0, 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print basis of invariant subspace */ /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ nag_gen_complx_mat_print_comp(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, m, q, pdq, Nag_BracketForm, "%7.4f", "Basis of invariant subspace", Nag_IntegerLabels, 0, Nag_IntegerLabels, 0, 80, 0, 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_complx_mat_print_comp (x04dbc).\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 (w) NAG_FREE(w); if (select) NAG_FREE(select); return exit_status; }