/* nag_zgeevx (f08npc) Example Program. * * Copyright 2011 Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include #include #include #include int main(void) { /* Scalars */ double abnrm, eps, rcnd, tol; Integer i, ihi, ilo, j, n, pda, pdvl, pdvr; Integer exit_status = 0; /* Arrays */ Complex *a = 0, *vl = 0, *vr = 0, *w = 0; double *rconde = 0, *rcondv = 0, *scale = 0; /* Nag Types */ NagError fail; Nag_OrderType order; #ifdef NAG_COLUMN_MAJOR #define A(I, J) a[(J-1)*pda + I - 1] #define VR(I, J) vr[(J)*pdvr + I] order = Nag_ColMajor; #else #define A(I, J) a[(I-1)*pda + J - 1] #define VR(I, J) vr[(I)*pdvr + J] order = Nag_RowMajor; #endif INIT_FAIL(fail); printf("nag_zgeevx (f08npc) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n]"); scanf("%ld%*[^\n]", &n); pda = n; pdvl = n; pdvr = n; /* Allocate memory */ if (!(a = NAG_ALLOC(n*n, Complex)) || !(vl = NAG_ALLOC(n*n, Complex)) || !(vr = NAG_ALLOC(n*n, Complex)) || !(w = NAG_ALLOC(n, Complex)) || !(rconde = NAG_ALLOC(n, double)) || !(rcondv = NAG_ALLOC(n, double)) || !(scale = NAG_ALLOC(n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Read the matrix A from data file */ for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) scanf(" ( %lf , %lf )", &A(i, j).re, &A(i, j).im); scanf("%*[^\n]"); /* Solve the eigenvalue problem using nag_zgeevx (f08npc). */ nag_zgeevx(order, Nag_BalanceBoth, Nag_LeftVecs, Nag_RightVecs, Nag_RCondBoth, n, a, pda, w, vl, pdvl, vr, pdvr, &ilo, &ihi, scale, &abnrm, rconde, rcondv, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_zgeevx (f08npc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Compute the machine precision */ eps = nag_machine_precision; tol = eps * abnrm; /* Normalize the eigenvectors */ for(j=0; j=0; i--) VR(i, j) = nag_complex_divide(VR(i, j), VR(0,j)); /* Print the eigenvalues/vectors, associated condition number and bounds. */ for (j = 0; j < n; ++j) { /* Print information on jth eigenvalue */ printf("\n\nEigenvalue %3ld%14s= ", j+1, ""); if (w[j].im == 0.) printf("%12.4e\n", w[j].re); else printf("(%11.4e, %11.4e)\n", w[j].re, w[j].im); rcnd = rconde[j]; printf("\nReciprocal condition number = %9.1e\n", rcnd); if (rcnd > 0.0) printf("Error bound = %9.1e\n", tol/rcnd); else printf("Error bound is infinite\n"); /* Print information on jth eigenvector */ printf("\nEigenvector %2ld\n", j+1); for (i = 0; i < n; ++i) printf("%30s(%11.4e, %11.4e)\n", "", VR(i, j).re, VR(i, j).im); rcnd = rcondv[j]; printf("\nReciprocal condition number = %9.1e\n", rcnd); if (rcnd > 0.0) printf("Error bound = %9.1e\n", tol/rcnd); else printf("Error bound is infinite\n"); } END: if (a) NAG_FREE(a); if (vl) NAG_FREE(vl); if (vr) NAG_FREE(vr); if (w) NAG_FREE(w); if (rconde) NAG_FREE(rconde); if (rcondv) NAG_FREE(rcondv); if (scale) NAG_FREE(scale); return exit_status; } #undef A #undef VR