/* rank_vertices.c This is a program to test the rank_vertices() function (a part of nelder-mead). It generates all vectors of length n with entries coming from the set {0,1,2,...,n-1}. Then it lets n vary from 3 to N, where N is #defined below. For each generated vector, it runs the given rank_vertices() function. If the result of rank_vertices() is incorrect, it prints a diagnostic, otherwise no putput is generated. Rouben Rostamian November 2003 */ #include #define N 5 /* ---- Replace the following BROKEN function with a good one ---- */ static void rank_vertices(double *v, size_t n, size_t *ia, size_t *iy, size_t *iz) { size_t i; *ia = *iy = *iz = 0; for (i=1; i < n; i++){ if (v[i] >= v[*iz]){ *iy = *iz; *iz = i; } if (v[i] < v[*ia]) *ia = i; else if (v[i] >= v[*iy]) *iy = i; } } void print_row(double *a, size_t n) { size_t i; for (i=0; i "); printf("ia = %u, iy = %u, iz = %u\n", ia, iy, iz); return; } if (!(a[ia] <= a[iy] && a[iy] <= a[iz])) { printf("vector: "); print_row(a, n); printf("ia = %u, iy = %u, iz = %u\n", ia, iy, iz); printf("a[%u] <= a[%u] && a[%u] <= a[%u] failed!\n", ia, iy, iy, iz); return; } } int main(void) { double a[N+1]; size_t ia, iy, iz; size_t i, n; for (n=3; n<=N; n++) { for (i=0; i