/* nag_zhbgst (f08usc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer i, j, k1, k2, ka, kb, n, pdab, pdbb, pdx, d_len, e_len; Integer exit_status = 0; NagError fail; Nag_UploType uplo; Nag_OrderType order; /* Arrays */ char nag_enum_arg[40]; Complex *ab = 0, *bb = 0, *x = 0; double *d = 0, *e = 0; #ifdef NAG_COLUMN_MAJOR #define AB_UPPER(I, J) ab[(J-1)*pdab + k1 + I - J - 1] #define AB_LOWER(I, J) ab[(J-1)*pdab + I - J] #define BB_UPPER(I, J) bb[(J-1)*pdbb + k2 + I - J - 1] #define BB_LOWER(I, J) bb[(J-1)*pdbb + I - J] order = Nag_ColMajor; #else #define AB_UPPER(I, J) ab[(I-1)*pdab + J - I] #define AB_LOWER(I, J) ab[(I-1)*pdab + k1 + J - I - 1] #define BB_UPPER(I, J) bb[(I-1)*pdbb + J - I] #define BB_LOWER(I, J) bb[(I-1)*pdbb + k2 + J - I - 1] order = Nag_RowMajor; #endif 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_zhbgst (f08usc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%ld%ld%*[^\n] ", &n, &ka, &kb); pdab = ka + 1; pdbb = kb + 1; pdx = n; d_len = n; e_len = n-1; /* Allocate memory */ if (!(ab = NAG_ALLOC(pdab * n, Complex)) || !(bb = NAG_ALLOC(pdbb * n, Complex)) || !(d = NAG_ALLOC(d_len, double)) || !(e = NAG_ALLOC(e_len, double)) || !(x = NAG_ALLOC(n * n, Complex))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Read whether Upper or Lower part of A is stored */ fscanf(fpin, "%s%*[^\n] ", nag_enum_arg); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ uplo = (Nag_UploType) nag_enum_name_to_value(nag_enum_arg); /* Read A and B from data file */ k1 = ka + 1; k2 = kb + 1; if (uplo == Nag_Upper) { for (i = 1; i <= n; ++i) { for (j = i; j <= MIN(i+ka, n); ++j) { fscanf(fpin, " ( %lf , %lf ) ", &AB_UPPER(i, j).re, &AB_UPPER(i, j).im); } } fscanf(fpin, "%*[^\n] "); } else { for (i = 1; i <= n; ++i) { for (j = MAX(1, i-ka); j <= i; ++j) { fscanf(fpin, " ( %lf , %lf ) ", &AB_LOWER(i, j).re, &AB_LOWER(i, j).im); } } fscanf(fpin, "%*[^\n] "); } if (uplo == Nag_Upper) { for (i = 1; i <= n; ++i) { for (j = i; j <= MIN(i+kb, n); ++j) { fscanf(fpin, " ( %lf, %lf ) ", &BB_UPPER(i, j).re, &BB_UPPER(i, j).im); } } fscanf(fpin, "%*[^\n] "); } else { for (i = 1; i <= n; ++i) { for (j = MAX(1, i-kb); j <= i; ++j) { fscanf(fpin, " ( %lf, %lf ) ", &BB_LOWER(i, j).re, &BB_LOWER(i, j).im); } } fscanf(fpin, "%*[^\n] "); } /* Compute the split Cholesky factorization of B */ /* nag_zpbstf (f08utc). * Computes a split Cholesky factorization of complex * Hermitian positive-definite band matrix A */ nag_zpbstf(order, uplo, n, kb, bb, pdbb, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_zpbstf (f08utc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Reduce the problem to standard form C*y = lambda*y, */ /* storing the result in A */ /* nag_zhbgst (f08usc). * Reduction of complex Hermitian-definite banded * generalized eigenproblem Ax~=~lambda~Bx to standard form * Cy~=~lambda~y, such that C has the same bandwidth as A */ nag_zhbgst(order, Nag_DoNotForm, uplo, n, ka, kb, ab, pdab, bb, pdbb, x, pdx, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_zhbgst (f08usc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Reduce C to tridiagonal form T = (Q**T)*C*Q */ /* nag_zhbtrd (f08hsc). * Unitary reduction of complex Hermitian band matrix to * real symmetric tridiagonal form */ nag_zhbtrd(order, Nag_DoNotForm, uplo, n, ka, ab, pdab, d, e, x, pdx, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_zhbtrd (f08hsc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Calculate the eigenvalues of T (same as C) */ /* nag_dsterf (f08jfc). * All eigenvalues of real symmetric tridiagonal matrix, * root-free variant of QL or QR */ nag_dsterf(n, d, e, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dsterf (f08jfc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print eigenvalues */ fprintf(fpout, " Eigenvalues\n"); for (i = 0; i < n; ++i) fprintf(fpout, " %8.4lf", d[i]); fprintf(fpout, "\n"); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (ab) NAG_FREE(ab); if (bb) NAG_FREE(bb); if (d) NAG_FREE(d); if (e) NAG_FREE(e); if (x) NAG_FREE(x); return exit_status; }