/* nag_zgebal (f08nvc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(void) { /* Scalars */ Integer i, ihi, ilo, j, m, n, pda, pdh, pdvr; Integer scale_len, tau_len, w_len; Integer exit_status=0; NagError fail; Nag_OrderType order; /* Arrays */ Complex *a=0, *h=0, *tau=0, *vl=0, *vr=0, *w=0; double *scale=0; Boolean *select=0; #ifdef NAG_COLUMN_MAJOR #define A(I,J) a[(J-1)*pda + I - 1] #define H(I,J) h[(J-1)*pdh + I - 1] #define VR(I,J) vr[(J-1)*pdvr + I - 1] order = Nag_ColMajor; #else #define A(I,J) a[(I-1)*pda + J - 1] #define H(I,J) h[(I-1)*pdh + J - 1] #define VR(I,J) vr[(I-1)*pdvr + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); Vprintf("f08nvc Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%*[^\n] ", &n); #ifdef NAG_COLUMN_MAJOR pda = n; pdh = n; pdvr = n; #else pda = n; pdh = n; pdvr = n; #endif scale_len = n; tau_len = n; w_len = n; /* Allocate memory */ if ( !(a = NAG_ALLOC(n * n, Complex)) || !(h = NAG_ALLOC(n * n, Complex)) || !(scale = NAG_ALLOC(scale_len, double)) || !(tau = NAG_ALLOC(tau_len, Complex)) || !(vl = NAG_ALLOC(1 * 1, Complex)) || !(vr = NAG_ALLOC(n * n, Complex)) || !(w = NAG_ALLOC(w_len, Complex)) || !(select = NAG_ALLOC(1, Boolean)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Read A from data file */ for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) Vscanf(" ( %lf , %lf )", &A(i,j).re, &A(i,j).im); } Vscanf("%*[^\n] "); /* Balance A */ f08nvc(order, Nag_DoBoth, n, a, pda, &ilo, &ihi, scale, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08nvc.\n%s\n", fail.message); exit_status = 1; goto END; } /* Reduce A to upper Hessenberg form H = (Q**H)*A*Q */ f08nsc(order, n, ilo, ihi, a, pda, tau, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08nsc.\n%s\n", fail.message); exit_status = 1; goto END; } /* Copy A to H and VR */ for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) { H(i,j).re = A(i,j).re; H(i,j).im = A(i,j).im; VR(i,j).re = A(i,j).re; VR(i,j).im = A(i,j).im; } } /* Form Q explicitly, storing the result in VR */ f08ntc(order, n, 1, n, vr, pdvr, tau, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08ntc.\n%s\n", fail.message); exit_status = 1; goto END; } /* Calculate the eigenvalues and Schur factorization of A */ f08psc(order, Nag_Schur, Nag_UpdateZ, n, ilo, ihi, h, pdh, w, vr, pdvr, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08psc.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf(" Eigenvalues\n"); for (i = 0; i < n; ++i) Vprintf(" (%7.4f,%7.4f)", w[i].re, w[i].im); Vprintf("\n"); /* Calculate the eigenvectors of A, storing the result in VR */ f08qxc(order, Nag_RightSide, Nag_BackTransform, select, n, h, pdh, vl, 1, vr, pdvr, n, &m, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08qxc.\n%s\n", fail.message); exit_status = 1; goto END; } f08nwc(order, Nag_DoBoth, Nag_RightSide, n, ilo, ihi, scale, m, vr, pdvr, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from f08nwc.\n%s\n", fail.message); exit_status = 1; goto END; } /* Print eigenvectors */ Vprintf("\n"); x04dbc(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, m, vr, pdvr, Nag_BracketForm, "%7.4f", "Contents of array VR", Nag_IntegerLabels, 0, Nag_IntegerLabels, 0, 80, 0, 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from x04dbc.\n%s\n", fail.message); exit_status = 1; goto END; } END: if (a) NAG_FREE(a); if (h) NAG_FREE(h); if (scale) NAG_FREE(scale); if (tau) NAG_FREE(tau); if (vl) NAG_FREE(vl); if (vr) NAG_FREE(vr); if (w) NAG_FREE(w); if (select) NAG_FREE(select); return exit_status; }