/* nag_real_gen_matrix_exp(f01ecc) Example Program. * * Copyright 2008, Numerical Algorithms Group. * * Mark 9, 2009. */ /* Pre-processor includes */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; char *outfile = 0; /*Integer scalar and array declarations */ Integer exit_status = 0; Integer i, j, n; Integer pda; NagError fail; /*Double scalar and array declarations */ double *a = 0; Nag_OrderType order; 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); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); fprintf(fpout, "%s\n", "nag_real_gen_matrix_exp (f01ecc) Example Program Results"); fprintf(fpout, "\n"); /* Skip heading in data file*/ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &n); #ifdef NAG_COLUMN_MAJOR pda = n; #define A(I, J) a[(J-1)*pda + I-1] order = Nag_ColMajor; #else pda = n; #define A(I, J) a[(I-1)*pda + J-1] order = Nag_RowMajor; #endif if (!(a = NAG_ALLOC(pda*n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Read A from data file*/ for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) fscanf(fpin, "%lf", &A(i, j)); } fscanf(fpin, "%*[^\n] "); /* Find exp( A )*/ /* * nag_real_gen_matrix_exp (f01ecc) * Real matrix exponential */ nag_real_gen_matrix_exp(order, n, a, pda, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_real_gen_matrix_exp (f01ecc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print solution*/ /* * nag_gen_real_mat_print (x04cac) * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, n, a, pda, "Exp(A)", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); return exit_status; }