/* nag_real_cholesky_skyline (f01mcc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, k, k1, k2, lal, n, *row = 0; NagError fail; double *a = 0, *al = 0, *d = 0; 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_cholesky_skyline (f01mcc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld", &n); if (n >= 1) { if (!(row = NAG_ALLOC(n, Integer)) || !(d = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } lal = 0; for (i = 0; i < n; i++) { fscanf(fpin, "%ld", &row[i]); lal += row[i]; } if (!(a = NAG_ALLOC(lal, double)) || !(al = NAG_ALLOC(lal, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } k2 = 0; for (i = 0; i < n; ++i) { k1 = k2; k2 = k2+row[i]; for (k = k1; k < k2; k++) fscanf(fpin, "%lf", &a[k]); } /* nag_real_cholesky_skyline (f01mcc). * LDL^T factorization of real symmetric positive-definite * variable-bandwidth (skyline) matrix */ nag_real_cholesky_skyline(n, a, lal, row, al, d, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_real_cholesky_skyline (f01mcc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, " i d[i] Row i of unit lower triangle\n\n"); k2 = 0; for (i = 0; i < n; ++i) { k1 = k2; k2 = k2+row[i]; fprintf(fpout, " %3ld%8.3f", i, d[i]); for (k = k1; k < k2; k++) fprintf(fpout, "%8.3f", al[k]); fprintf(fpout, "\n"); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (row) NAG_FREE(row); if (a) NAG_FREE(a); if (al) NAG_FREE(al); if (d) NAG_FREE(d); return exit_status; }