/* nag_mv_discrim_distance_mat (g03eac) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * */ #include #include #include #include #define NMAX 10 #define MMAX 10 int main(void) { double d[NMAX*(NMAX-1)/2], s[MMAX], x[NMAX][MMAX]; Integer isx[MMAX]; Integer i, j, m, n; Integer tdx=MMAX; char char_scale[2]; char char_update[2]; char char_dist[2]; Nag_MatUpdate update; Nag_DistanceType dist; Nag_VarScaleType scale; Vprintf("g03eac Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld",&n); Vscanf("%ld",&m); if (n <= NMAX && m <= MMAX) { Vscanf("%s",char_update); Vscanf("%s",char_dist); Vscanf("%s",char_scale); for (j = 0; j < n; ++j) { for (i = 0; i < m; ++i) Vscanf("%lf",&x[j][i]); } for (i = 0; i < m; ++i) Vscanf("%ld",&isx[i]); for (i = 0; i < m; ++i) Vscanf("%lf",&s[i]); /* Compute the distance matrix */ if (*char_update == 'U') update = Nag_MatUp; else if (*char_update == 'I') update = Nag_NoMatUp; if (*char_dist == 'A') dist = Nag_DistAbs; else if (*char_dist == 'E') dist = Nag_DistEuclid; else if (*char_dist == 'S') dist = Nag_DistSquared; if (*char_scale == 'S') scale = Nag_VarScaleStd; else if (*char_scale == 'R') scale = Nag_VarScaleRange; else if (*char_scale == 'G') scale = Nag_VarScaleUser; else if (*char_scale == 'U') scale = Nag_NoVarScale; g03eac(update, dist, scale, n, m, &x[0][0], tdx, isx, s, d, NAGERR_DEFAULT); /* Print the distance matrix */ Vprintf("\n"); Vprintf(" Distance Matrix "); Vprintf("\n"); Vprintf("\n"); Vprintf(" %s\n"," 1 2 3 4"); Vprintf("\n"); for (i = 2; i <= n; ++i) { Vprintf("%2ld ",i); for (j=(i-1)*(i-2)/2+1; j<=i*(i - 1)/2; ++j) Vprintf("%5.2f ",d[j-1]); Vprintf("\n"); } return EXIT_SUCCESS; } else { Vprintf("Incorrect input value of n or m.\n"); return EXIT_FAILURE; } }