/* nag_complex_cholesky (f01bnc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. * Mark 8 revised, 2004. */ #include #include #include #include #include #include #define COMPLEX(A) A.re, A.im #define A(I, J) a[(I) *tda + J] int main(int argc, char *argv[]) { FILE *fpin, *fpout; Complex *a = 0; Integer exit_status = 0, i, j, n, tda; NagError fail; double *p = 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_complex_cholesky (f01bnc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld", &n); if (n >= 1) { if (!(p = NAG_ALLOC(n, double)) || !(a = NAG_ALLOC(n*n, Complex))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } tda = n; } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; ++i) for (j = 0; j <= i; ++j) fscanf(fpin, " ( %lf, %lf ) ", COMPLEX(&A(i, j))); /* nag_complex_cholesky (f01bnc). * UU^H factorization of complex Hermitian positive-definite * matrix */ nag_complex_cholesky(n, a, tda, p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_complex_cholesky (f01bnc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n Upper triangle of Complex matrix U by rows\n"); for (i = 0; i < n; ++i) { fprintf(fpout, "\n"); fprintf(fpout, " (%7.4f,%9.4f)\n", 1.0/p[i], 0.0); for (j = i+1; j < n; ++j) fprintf(fpout, " (%7.4f,%9.4f)\n", COMPLEX(A(i, j))); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (p) NAG_FREE(p); if (a) NAG_FREE(a); return exit_status; }