/* nag_mv_prin_coord_analysis (g03fac) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 7 revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #define XTMP(I) xtmp[(I)-1] #define YTMP(I) ytmp[(I)-1] #define X(I,J) x[(I)*tdx + J] int main(void) { Integer exit_status=0, i, j, n, ndim, nn, tdx; NagError fail; Nag_Eigenvalues roots; char char_roots[2]; double *d=0, *e=0, *x=0; INIT_FAIL(fail); Vprintf("nag_mv_prin_coord_analysis (g03fac) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld",&n); Vscanf("%ld",&ndim); Vscanf("%s",char_roots); if (ndim>=1 && n>ndim) { if ( !( d = NAG_ALLOC(n*(n-1)/2, double)) || !( e = NAG_ALLOC(n, double)) || !( x = NAG_ALLOC(n*n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdx = n; } else { Vprintf("Invalid ndim or n.\n"); exit_status = 1; return exit_status; } nn = n * (n - 1) / 2; for (i = 0; i < nn; ++i) Vscanf("%lf",&d[i]); if (*char_roots == 'L') roots = Nag_LargeEigVals; else roots = Nag_AllEigVals; /* nag_mv_prin_coord_analysis (g03fac). * Principal co-ordinate analysis */ nag_mv_prin_coord_analysis(roots, n, d, ndim, x, tdx, e, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_mv_prin_coord_analysis (g03fac).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\nScaled Eigenvalues\n\n"); if (*char_roots == 'L') { for (i = 0; i < ndim; ++i) Vprintf("%10.4f",e[i]); } else { for (i = 0; i < n; ++i) Vprintf("%10.4f",e[i]); Vprintf("\n"); } Vprintf("\nCo-ordinates\n\n"); for (i = 0; i < n; ++i) { for (j = 0; j < ndim; ++j) Vprintf("%10.4f",X(i,j)); Vprintf("\n"); } END: if (d) NAG_FREE(d); if (e) NAG_FREE(e); if (x) NAG_FREE(x); return exit_status; }