/* nag_complex_lu (f03ahc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1A revised, (Oct 1990). * Mark 8 revised, 2004. */ #include #include #include #include #include #define A(I, J) a[(I) *tda + J] int main(void) { Complex *a = 0, det; Integer dete, exit_status = 0, i, j, n, *pivot = 0, tda; NagError fail; INIT_FAIL(fail); printf("nag_complex_lu (f03ahc) Example Program Results\n"); scanf("%*[^\n]"); /* Skip heading in data file */ scanf("%" NAG_IFMT "", &n); if (n >= 1) { if (!(pivot = NAG_ALLOC(n, Integer)) || !(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 < n; j++) scanf(" ( %lf, %lf ) ", &A(i, j).re, &A(i, j).im); /* nag_complex_lu (f03ahc). * LU factorization and determinant of complex matrix */ nag_complex_lu(n, a, tda, pivot, &det, &dete, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_complex_lu (f03ahc).\n%s\n", fail.message); exit_status = 1; goto END; } else { printf("Array a after factorization\n"); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) printf("(%7.3f, %7.3f) ", A(i, j).re, A(i, j).im); printf("\n"); } printf("\nArray pivot\n"); for (i = 0; i < n; i++) printf("%5" NAG_IFMT "", pivot[i]); printf("\n\ndet.re = %7.4f, det.im = %7.4f, dete = %2" NAG_IFMT ".\n", det.re, det.im, dete); det.re = ldexp(det.re, (int) dete); det.im = ldexp(det.im, (int) dete); printf("\nValue of determinant = (%7.4f, %7.4f)\n", det.re, det.im); } END: if (pivot) NAG_FREE(pivot); if (a) NAG_FREE(a); return exit_status; }