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

NAG CL Interface Introduction
Example description
/* nag_matop_real_gen_matrix_cond_log (f01jjc) 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;
  Integer pda;
  double condla;
  /* Arrays */
  double *a = 0;
  /* Nag Types */
  Nag_OrderType order = Nag_ColMajor;
  NagError fail;

  INIT_FAIL(fail);

  /* Output preamble */
  printf("nag_matop_real_gen_matrix_cond_log (f01jjc) ");
  printf("Example Program Results\n\n");

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

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

  pda = n;
  if (!(a = NAG_ALLOC(pda * n, double))) {
    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", &A(i, j));
  scanf("%*[^\n] ");

  /* Find log(A) and the condition number using
   * nag_matop_real_gen_matrix_cond_log (f01jjc)
   * Condition number for real matrix logarithm
   */
  nag_matop_real_gen_matrix_cond_log(n, a, pda, &condla, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_matop_real_gen_matrix_cond_log (f01jjc)\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* Print matrix log(A) using nag_file_print_matrix_real_gen (x04cac)
   * Print real general matrix (easy-to-use)
   */
  fflush(stdout);
  nag_file_print_matrix_real_gen(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n,
                                 n, a, pda, "log(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 = 2;
  }

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

END:
  NAG_FREE(a);

  return exit_status;
}