/* nag_ztgsen (f08yuc) Example Program. * * Copyright 2011 Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include #include #include #include #include int main(void) { /* Scalars */ double abs_a, abs_b, pl, pr, small; Complex eig; Integer i, ijob, j, m, n, pds, pdt, pdq, pdz; Integer exit_status = 0; /* Arrays */ Complex *alpha = 0, *beta = 0, *q = 0, *s = 0, *t = 0, *z = 0; double dif[2]; char nag_enum_arg[40]; /* Nag Types */ NagError fail; Nag_OrderType order; Nag_Boolean wantq, wantz; Nag_Boolean *select = 0; #ifdef NAG_COLUMN_MAJOR #define Q(I, J) q[(J-1)*pdq + I - 1] #define Z(I, J) z[(J-1)*pdz + I - 1] #define S(I, J) s[(J-1)*pds + I - 1] #define T(I, J) t[(J-1)*pdt + I - 1] order = Nag_ColMajor; #else #define Q(I, J) q[(I-1)*pdq + J - 1] #define Z(I, J) z[(I-1)*pdz + J - 1] #define S(I, J) s[(I-1)*pds + J - 1] #define T(I, J) t[(I-1)*pdt + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); printf("nag_ztgsen (f08yuc) Example Program Results\n\n"); /* Skip heading in data file */ scanf("%*[^\n]"); scanf("%ld%ld%*[^\n]", &n, &ijob); if (n < 0 || ijob<0 || ijob>5) { printf("Invalid n or ijob\n"); exit_status = 1; goto END; } scanf(" %s%*[^\n]", nag_enum_arg); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ wantq = (Nag_Boolean) nag_enum_name_to_value(nag_enum_arg); scanf(" %s%*[^\n]", nag_enum_arg); wantz = (Nag_Boolean) nag_enum_name_to_value(nag_enum_arg); pds = n; pdt = n; pdq = (wantq?n:1); pdz = (wantz?n:1); /* Allocate memory */ if (!(s = NAG_ALLOC(n*n, Complex)) || !(t = NAG_ALLOC(n*n, Complex)) || !(alpha = NAG_ALLOC(n, Complex)) || !(beta = NAG_ALLOC(n, Complex)) || !(select = NAG_ALLOC(n, Nag_Boolean)) || !(q = NAG_ALLOC(pdq*pdq, Complex)) || !(z = NAG_ALLOC(pdz*pdz, Complex))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ for (i = 0; i < n; ++i) { scanf("%s", nag_enum_arg); select[i] = (Nag_Boolean) nag_enum_name_to_value(nag_enum_arg); } scanf("%*[^\n]"); /* Read S, T, Q, Z and the logical array select from data file */ for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) scanf(" ( %lf , %lf )", &S(i, j).re, &S(i, j).im); scanf("%*[^\n]"); for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) scanf(" ( %lf , %lf )", &T(i, j).re, &T(i, j).im); scanf("%*[^\n]"); if (wantq) { for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) scanf(" ( %lf , %lf )", &Q(i, j).re, &Q(i, j).im); scanf("%*[^\n]"); } if (wantz) { for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) scanf(" ( %lf , %lf )", &Z(i, j).re, &Z(i, j).im); scanf("%*[^\n]"); } /* Reorder the Schur factors S and T and update the matrices Q and Z. */ nag_ztgsen(order, ijob, wantq, wantz, select, n, s, pds, t, pdt, alpha, beta, q, pdq, z, pdz, &m, &pl, &pr, dif, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_ztgsen (f08yuc).\n%s\n", fail.message); exit_status = 1; goto END; } /* nag_real_safe_small_number (x02amc). */ small = nag_real_safe_small_number; /* Print the eigenvalues */ printf("Selected Eigenvalues\n"); for (j = 0; j < m; ++j) { printf("%2ld ", j+1); abs_a = nag_complex_abs(alpha[j]); abs_b = nag_complex_abs(beta[j]); if (abs_a*small >= abs_b) printf(" infinite or undetermined, alpha = (%11.4e, %11.4e), " "|beta| = %11.4e\n", alpha[j].re, alpha[j].im, abs_b); else eig = nag_complex_divide(alpha[j],beta[j]); printf(" (%11.4e, %11.4e)\n", eig.re, eig.im); } /* Print deflating subspaces */ if (ijob==1 || ijob==4 || ijob == 5) { printf("\n"); printf("For the selected eigenvalues,\nthe reciprocals of projection " "norms onto the deflating subspaces are\n"); printf(" for left subspace, pl = %11.2e\n for right subspace, pr = " "%11.2e\n\n", pl, pr); } if (ijob>1) { printf(" upper bound on Difu = %11.2e\n", dif[0]); printf(" upper bound on Difl = %11.2e\n", dif[1]); if (ijob==2 || ijob==4) { printf("\nUpper bounds on Difl, Difu are based on the Frobenius norm\n"); } if (ijob==3 || ijob==5) { printf("\nUpper bounds on Difl, Difu are based on the one norm.\n"); } } END: if (s) NAG_FREE(s); if (t) NAG_FREE(t); if (alpha) NAG_FREE(alpha); if (beta) NAG_FREE(beta); if (select) NAG_FREE(select); if (q) NAG_FREE(q); if (z) NAG_FREE(z); return exit_status; }