NAG Library Manual, Mark 30.2
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_matop_complex_gen_matrix_cond_pow (f01kec) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.2, 2024.
 */
#include <nag.h>

#define A(I, J) a[J * pda + I]

int main(void) {

  /* Scalars */
  Integer exit_status = 0;
  Integer i, j, n, pda;
  double p, condpa;
  /* Arrays */
  Complex *a = 0;
  /* Nag Types */
  Nag_OrderType order = Nag_ColMajor;
  NagError fail;

  INIT_FAIL(fail);

  /* Output preamble */
  printf("nag_matop_complex_gen_matrix_cond_pow (f01kec) ");
  printf("Example Program Results\n\n");
  fflush(stdout);

  /* Skip heading in data file */
  scanf("%*[^\n] ");

  /* Read in the problem size and the required power */
  scanf("%" NAG_IFMT "", &n);
  scanf("%lf", &p);
  scanf("%*[^\n]");

  pda = n;
  if (!(a = NAG_ALLOC(pda * n, Complex))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* Read in the matrix A from data file */
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      scanf(" ( %lf , %lf ) ", &A(i, j).re, &A(i, j).im);
  scanf("%*[^\n] ");

  /* Find the matrix pth power and condition number using
   * nag_matop_complex_gen_matrix_cond_pow (f01kec)
   * Condition number complex matrix power
   */
  nag_matop_complex_gen_matrix_cond_pow(n, a, pda, p, &condpa, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_matop_complex_gen_matrix_cond_pow (f01kec)\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* Print matrix A^p using nag_file_print_matrix_complex_gen (x04dac)
   * Print complex general matrix (easy-to-use)
   */
  nag_file_print_matrix_complex_gen(order, Nag_GeneralMatrix, Nag_NonUnitDiag,
                                    n, n, a, pda, "A^p", NULL, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_complex_gen (x04dac)\n%s\n",
           fail.message);
    exit_status = 2;
    goto END;
  }

  /* Print relative condition number estimate */
  printf("Estimated relative condition number is: %7.2f\n", condpa);

END:
  NAG_FREE(a);
  return exit_status;
}