/* nag_dsbgst (f08uec) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* 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 uplo_char[2]; double *ab=0, *bb=0, *d=0, *e=0, *x=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); Vprintf("nag_dsbgst (f08uec) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%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, double)) || !(bb = NAG_ALLOC(pdbb * n, double)) || !(d = NAG_ALLOC(d_len, double)) || !(e = NAG_ALLOC(e_len, double)) || !(x = NAG_ALLOC(n * n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Read whether Upper or Lower part of A is stored */ Vscanf(" ' %1s '%*[^\n] ", uplo_char); if (*(unsigned char *)uplo_char == 'L') uplo = Nag_Lower; else if (*(unsigned char *)uplo_char == 'U') uplo = Nag_Upper; else { Vprintf("Unrecognised character for Nag_UploType type\n"); exit_status = -1; goto END; } /* 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) Vscanf("%lf", &AB_UPPER(i,j)); } Vscanf("%*[^\n] "); } else { for (i = 1; i <= n; ++i) { for (j = MAX(1,i-ka); j <= i; ++j) Vscanf("%lf", &AB_LOWER(i,j)); } Vscanf("%*[^\n] "); } if (uplo == Nag_Upper) { for (i = 1; i <= n; ++i) { for (j = i; j <= MIN(i+kb,n); ++j) Vscanf("%lf", &BB_UPPER(i,j)); } Vscanf("%*[^\n] "); } else { for (i = 1; i <= n; ++i) { for (j = MAX(1,i-kb); j <= i; ++j) Vscanf("%lf", &BB_LOWER(i,j)); } Vscanf("%*[^\n] "); } /* Compute the split Cholesky factorization of B */ /* nag_dpbstf (f08ufc). * Computes a split Cholesky factorization of real symmetric * positive-definite band matrix A */ nag_dpbstf(order, uplo, n, kb, bb, pdbb, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_dpbstf (f08ufc).\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_dsbgst (f08uec). * Reduction of real symmetric-definite banded generalized * eigenproblem Ax~=~lambda~Bx to standard form * Cy~=~lambda~y, such that C has the same bandwidth as A */ nag_dsbgst(order, Nag_DoNotForm, uplo, n, ka, kb, ab, pdab, bb, pdbb, x, pdx, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_dsbgst (f08uec).\n%s\n", fail.message); exit_status = 1; goto END; } /* Reduce C to tridiagonal form T = (Q**T)*C*Q */ /* nag_dsbtrd (f08hec). * Orthogonal reduction of real symmetric band matrix to * symmetric tridiagonal form */ nag_dsbtrd(order, Nag_DoNotForm, uplo, n, ka, ab, pdab, d, e, x, pdx, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_dsbtrd (f08hec).\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) { Vprintf("Error from nag_dsterf (f08jfc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print eigenvalues */ Vprintf(" Eigenvalues\n"); for (i = 0; i < n; ++i) Vprintf(" %8.4lf",d[i]); Vprintf("\n"); END: 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; }