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

NAG CL Interface Introduction
Example description
/* nag_roots_lambertw_complex (c05bbc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.0, 2024.
 */

#include <math.h>
#include <nag.h>
#include <stdio.h>

int main(void) {
  /* Scalars */
  Complex w, z;
  double resid;
  Integer branch;
  Integer exit_status = 0;
  char offset[10];
  Nag_Boolean offsetenum;
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_roots_lambertw_complex (c05bbc) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "%*[^\n] ", &branch);
  scanf("%9s%*[^\n] ", offset);

  /*
   * nag_enum_name_to_value (x04nac).
   * Converts NAG enum member name to value
   */
  offsetenum = (Nag_Boolean)nag_enum_name_to_value(offset);

  printf("\n");
  printf("branch = %" NAG_IFMT "\n", branch);
  printf("offset = %s\n", offset);
  printf("\n               z                              w(z)"
         "                    resid\n\n");
  while (scanf(" (%lf,%lf)%*[^\n] ", &z.re, &z.im) != EOF)
  {
    /*
     * nag_roots_lambertw_complex (c05bbc)
     * Values of Lambert's W function, W(z)
     */
    nag_roots_lambertw_complex(branch, offsetenum, z, &w, &resid, &fail);
    if (fail.code == NE_NOERROR || fail.code == NW_REAL ||
        fail.code == NW_TOO_MANY_ITER) {
      printf("(%14.5e,%14.5e) (%14.5e,%14.5e) %14.5e\n", z.re, z.im, w.re, w.im,
             resid);
    } else {
      printf("Error from nag_roots_lambertw_complex (c05bbc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
  }

END:
  return exit_status;
}