/* nag_mv_ordinal_multidimscale (g03fcc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 6 revised, 2000. * Mark 7 revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #define NMAX 14 #define NNMAX NMAX*(NMAX-1)/2 #define X(I,J) x[(I-1)*tdx + (J-1)] #define XTMP(I) xtmp[(I)-1] #define YTMP(I) ytmp[(I)-1] int main(void) { Integer exit_status=0, i, j, n, ndim, nn, tdx=NMAX; NagError fail; Nag_ScaleCriterion type; char char_type[2]; double *d=0, *dfit=0, *e=0, stress, *x=0; INIT_FAIL(fail); Vprintf("nag_mv_ordinal_multidimscale (g03fcc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld",&n); Vscanf("%ld",&ndim); Vscanf("%s",char_type); if (ndim>=1 && n>ndim) { if ( !( d = NAG_ALLOC(n*(n-1)/2, double)) || !( dfit = NAG_ALLOC(4*(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 = 1; i <= nn; ++i) Vscanf("%lf",&d[i-1]); /* nag_mv_prin_coord_analysis (g03fac). * Principal co-ordinate analysis */ nag_mv_prin_coord_analysis(Nag_LargeEigVals, 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; } if (*char_type == 'T') type = Nag_Stress; else type = Nag_SStress; /* nag_mv_ordinal_multidimscale (g03fcc). * Multidimensional scaling */ nag_mv_ordinal_multidimscale(type, n, ndim, d, x, tdx, &stress, dfit, E04_DEFAULT, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_mv_ordinal_multidimscale (g03fcc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n STRESS = %13.4e\n\n",stress); Vprintf("Co-ordinates\n\n"); for (i = 1; i <= n; ++i) { for (j = 1; j <= ndim; ++j) Vprintf("%10.4f",X(i,j)); Vprintf("\n"); } END: if (d) NAG_FREE(d); if (dfit) NAG_FREE(dfit); if (e) NAG_FREE(e); if (x) NAG_FREE(x); return exit_status; }