40double minc(fn, x, dx, dx_lim, xlo, xhi, np, ns_max, p_flag) double (*fn)();
50 register long i, n_steps, pc;
51 register double f0, f1, _dx;
52 long flag, *constraint, at_upper, at_lower;
55 constraint =
tmalloc(
sizeof(
long) * np);
56 for (i = 0; i < np; i++)
57 constraint[i] = xlo[i] != xhi[i];
62 for (i = flag = 0; i < np; i++) {
63 if (fabs(_dx = dx[i]) < dx_lim[i]) {
70 x[i] = xlo[i] + 2 * (dx[i] = fabs(_dx) / 2);
74 x[i] = xhi[i] + 2 * (dx[i] = -fabs(_dx) / 2);
85 x[i] = xlo[i] + 2 * (dx[i] = fabs(_dx) / 2);
89 x[i] = xhi[i] + 2 * (dx[i] = -fabs(_dx) / 2);
96 if (n_steps++ == ns_max) {
98 dx[i] = _dx = 2 * _dx;
104 x[i] = xlo[i] + 2 * (dx[i] = fabs(_dx));
108 x[i] = xhi[i] + 2 * (dx[i] = -fabs(_dx));
117 if (pc++ == p_flag) {
118 printf(
"%.16le\n", f0);
119 for (i = 0; i < np; i++)
120 printf(
"%.16le\t%.16le\n", x[i], dx[i]);
123 }
while (flag != np);
double minc(double *fn, double *x, double *dx, double *dx_lim, double *xlo, double *xhi, long np, long ns_max, long p_flag)
Finds the minimum of a multi-parameter function with constraints.