/* nag_complex_cholesky (f01bnc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. * Mark 8 revised, 2004. */ #include #include #include #include #include #define COMPLEX(A) A.re, A.im #define A(I, J) a[(I) *tda + J] int main(void) { Complex *a = 0; Integer exit_status = 0, i, j, n, tda; NagError fail; double *p = 0; INIT_FAIL(fail); printf("nag_complex_cholesky (f01bnc) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n]"); scanf("%ld", &n); if (n >= 1) { if (!(p = NAG_ALLOC(n, double)) || !(a = NAG_ALLOC(n*n, Complex))) { printf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; } else { printf("Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; ++i) for (j = 0; j <= i; ++j) scanf(" ( %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) { printf("Error from nag_complex_cholesky (f01bnc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\n Upper triangle of Complex matrix U by rows\n"); for (i = 0; i < n; ++i) { printf("\n"); printf(" (%7.4f,%9.4f)\n", 1.0/p[i], 0.0); for (j = i+1; j < n; ++j) printf(" (%7.4f,%9.4f)\n", COMPLEX(A(i, j))); } END: NAG_FREE(p); NAG_FREE(a); return exit_status; }