/* nag_real_eigensystem_sel (f02ecc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 8 revised, 2004. * */ #include #include #include #include #include #define MMAX 3 #define A(I, J) a[(I) *tda + J] #define V(I, J) v[(I) *tdv + J] int main(int argc, char *argv[]) { FILE *fpin, *fpout; Complex *v = 0, *w = 0; Integer exit_status = 0, i, j, m, mest = MMAX, n, tda, tdv; double *a = 0, wl, wu; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_real_eigensystem_sel (f02ecc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); mest = MMAX; fscanf(fpin, "%ld%lf%lf%*[^\n]", &n, &wl, &wu); if (n >= 0) { if (!(a = NAG_ALLOC(n*n, double)) || !(w = NAG_ALLOC(n, Complex)) || !(v = NAG_ALLOC(n*mest, Complex))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } tda = n; tdv = mest; } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } /* Read a from data file */ for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) fscanf(fpin, "%lf", &A(i, j)); fscanf(fpin, "%*[^\n]"); /* Compute selected eigenvalues and eigenvectors of A */ /* nag_real_eigensystem_sel (f02ecc). * Computes selected eigenvalues and eigenvectors of a real * general matrix */ nag_real_eigensystem_sel(Nag_Select_Modulus, n, a, tda, wl, wu, mest, &m, w, v, tdv, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_real_eigensystem_sel (f02ecc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n\nEigenvalues\n"); for (i = 0; i < m; ++i) fprintf(fpout, "(%7.4f, %7.4f) ", w[i].re, w[i].im); fprintf(fpout, "\n"); fprintf(fpout, " Eigenvectors\n "); for (i = 1; i <= m; i++) fprintf(fpout, "%15ld%s", i, i%m == 0?"\n":""); for (i = 0; i < n; i++) { fprintf(fpout, "%ld ", i + 1); for (j = 0; j < m; j++) fprintf(fpout, "(%8.4f, %8.4f)%s", V(i, j).re, V(i, j).im, (j + 1) % m == 0?"\n":" "); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); if (w) NAG_FREE(w); if (v) NAG_FREE(v); return exit_status; }