/* nag_complex_lin_eqn_mult_rhs (f04adc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1A revised, (Oct 1990). * Mark 8 revised, 2004. */ #include #include #include #include #define A(I, J) a[(I) *tda + J] #define B(I, J) b[(I) *tdb + J] #define X(I, J) x[(I) *tdx + J] int main(void) { Complex *a = 0, *b = 0, *x = 0; Integer exit_status = 0, i, j, n, nrhs = 1, tda, tdb, tdx; NagError fail; INIT_FAIL(fail); printf( "nag_complex_lin_eqn_mult_rhs (f04adc) Example Program Results\n"); scanf("%*[^\n]"); /* Skip heading in data file */ scanf("%ld", &n); if (n >= 1) { if (!(a = NAG_ALLOC(n*n, Complex)) || !(b = NAG_ALLOC(n*1, Complex)) || !(x = NAG_ALLOC(n*1, Complex))) { printf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; tdb = 1; tdx = 1; } 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); for (i = 0; i < n; i++) for (j = 0; j < tdx; j++) scanf(" ( %lf, %lf ) ", &B(i, j).re, &B(i, j).im); /* nag_complex_lin_eqn_mult_rhs (f04adc). * Approximate solution of complex simultaneous linear * equations with multiple right-hand sides */ nag_complex_lin_eqn_mult_rhs(n, nrhs, a, tda, b, tdb, x, tdx, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_complex_lin_eqn_mult_rhs (f04adc).\n%s\n", fail.message); exit_status = 1; goto END; } else { printf("Solution\n"); for (i = 0; i < n; i++) printf("(%7.4f, %7.4f)\n", X(i, 0).re, X(i, 0).im); } END: NAG_FREE(a); NAG_FREE(b); NAG_FREE(x); return exit_status; }