/* nag_matop_real_gen_matrix_frcht_pow (f01jfc) Example Program.
*
* Copyright 2021 Numerical Algorithms Group.
*
* Mark 27.3, 2021.
*/
#include <nag.h>
#define A(I, J) a[J * pda + I]
#define E(I, J) e[J * pde + I]
int main(void) {
/* Scalars */
Integer exit_status = 0;
Integer i, j, n;
Integer pda, pde;
double p;
/* Arrays */
double *a = 0;
double *e = 0;
/* Nag Types */
Nag_OrderType order = Nag_ColMajor;
NagError fail;
INIT_FAIL(fail);
/* Output preamble */
printf("nag_matop_real_gen_matrix_frcht_pow (f01jfc) ");
printf("Example Program Results\n\n");
fflush(stdout);
/* Skip heading in data file */
scanf("%*[^\n] ");
/* Read in the problem size and required power */
scanf("%" NAG_IFMT "", &n);
scanf("%lf", &p);
scanf("%*[^\n]");
pda = n;
if (!(a = NAG_ALLOC(pda * n, double))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
pde = n;
if (!(e = NAG_ALLOC(pde * n, double))) {
printf("Allocation failure\n");
exit_status = -2;
goto END;
}
/* Read in the matrix A from data file */
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
scanf("%lf", &A(i, j));
scanf("%*[^\n] ");
/* Read in the matrix E from data file */
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
scanf("%lf", &E(i, j));
scanf("%*[^\n] ");
/* Find A^p and L(A,E) using
* nag_matop_real_gen_matrix_frcht_pow (f01jfc)
* Frechet derivative of real matrix power
*/
nag_matop_real_gen_matrix_frcht_pow(n, a, pda, e, pde, p, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_matop_real_gen_matrix_frcht_pow (f01jfc)\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Print matrix A^p using nag_file_print_matrix_real_gen (x04cac)
* Print real general matrix (easy-to-use)
*/
nag_file_print_matrix_real_gen(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n,
n, a, pda, "A^p", 0, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_file_print_matrix_real_gen (x04cac)\n%s\n",
fail.message);
exit_status = 2;
}
/* Print matrix L(A,E) using nag_file_print_matrix_real_gen (x04cac)
* Print real general matrix (easy-to-use)
*/
nag_file_print_matrix_real_gen(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n,
n, e, pde, "L(A,E)", 0, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_file_print_matrix_real_gen (x04cac)\n%s\n",
fail.message);
exit_status = 3;
}
END:
NAG_FREE(a);
NAG_FREE(e);
return exit_status;
}