/* nag_matop_real_symm_matrix_exp (f01edc) Example Program.
*
* Copyright 2023 Numerical Algorithms Group.
*
* Mark 29.0, 2023.
*/
/* Pre-processor includes */
#include <math.h>
#include <nag.h>
#include <stdio.h>
#include <string.h>
int main(void) {
/*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);
printf("%s\n",
"nag_matop_real_symm_matrix_exp (f01edc) Example Program Results");
printf("\n");
scanf("%*[^\n] ");
scanf("%" NAG_IFMT "%*[^\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))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
scanf("%9s%*[^\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++)
scanf("%lf ", &A(i, j));
}
scanf("%*[^\n] ");
} else {
matrix = Nag_LowerMatrix;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++)
scanf("%lf ", &A(i, j));
}
scanf("%*[^\n] ");
}
/*
* nag_matop_real_symm_matrix_exp (f01edc)
* Real symmetric matrix exponential
*/
nag_matop_real_symm_matrix_exp(order, uploc, n, a, pda, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_matop_real_symm_matrix_exp (f01edc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/*
* nag_file_print_matrix_real_gen (x04cac)
* Print real general matrix (easy-to-use)
*/
fflush(stdout);
nag_file_print_matrix_real_gen(order, matrix, Nag_NonUnitDiag, n, n, a, pda,
"Symmetric Exp(A)", 0, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_file_print_matrix_real_gen (x04cac).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
END:
NAG_FREE(a);
return exit_status;
}