/* nag_real_symm_matrix_exp (f01edc) Example Program. * * Copyright 2009, Numerical Algorithms Group. * * Mark 9, 2009. */ /* Pre-processor includes */ #include #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, pda; Nag_MatrixType matrix; Nag_UploType uploc; /*Double scalar and array declarations */ double *a = 0; /*Character scalar and array declarations */ char uplo[10]; Nag_OrderType order; NagError fail; 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_symm_matrix_exp (f01edc) Example Program Results"); fprintf(fpout, "\n"); 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(n*n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } fscanf(fpin, "%s%*[^\n] ", uplo); /* * nag_enum_name_to_value (x04nac). * Converts NAG enum member name to value */ uploc = (Nag_UploType) nag_enum_name_to_value(uplo); if (uploc == Nag_Upper) { matrix = Nag_UpperMatrix; for (i = 1; i <= n; i++) { for (j = i; j <= n; j++) fscanf(fpin, "%lf ", &A(i, j)); } fscanf(fpin, "%*[^\n] "); } else { matrix = Nag_LowerMatrix; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) fscanf(fpin, "%lf ", &A(i, j)); } fscanf(fpin, "%*[^\n] "); } /* * nag_real_symm_matrix_exp (f01edc) * Real symmetric matrix exponential */ nag_real_symm_matrix_exp(order, uploc, n, a, pda, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_real_symm_matrix_exp (f01edc).\n%s\n", fail.message); exit_status = 1; goto END; } /* * nag_gen_real_mat_print (x04cac) * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, matrix, Nag_NonUnitDiag, n, n, a, pda, "Symmetric 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; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); return exit_status; }