Go to the documentation of this file.
9 for (sum=0.0,i=0;i<ndim+1;i++) \
10 sum += *(pnts + i*ndim +j); \
16 short i,
j,
k, isml = 0, inxt, ibig, ndim;
17 double y[16], ptry[16], psum[16], ytry, ysave, sum, rtol;
20 int32_t itermax = auxdata->
niter;
23 ndim = auxdata->
nfunc;
29 for (
i = 0;
i < ndim + 1;
i++) {
30 for (
j = 0;
j < ndim;
j++) ptry[
j] = pnts[
i * ndim +
j];
31 y[
i] = (*func)(auxdata, ptry);
34 for (
k = 0;
k < itermax;
k++) {
39 if (
y[0] >
y[1]) ibig = 0;
44 for (
i = 2;
i < ndim + 1;
i++) {
48 }
else if (
y[
i] <
y[isml]) {
50 }
else if (
y[
i] >
y[inxt] &&
y[
i] <
y[ibig]) inxt =
i;
53 rtol = 2.0 *
fabs(
y[ibig] -
y[isml]) /
58 if (rtol <
tol)
break;
60 ytry =
reflect(pnts,
y, psum, ndim, auxdata,
func, ibig, -1.0);
62 if (ytry <=
y[isml]) {
63 ytry =
reflect(pnts,
y, psum, ndim, auxdata,
func, ibig, 2.0);
65 else if (ytry >=
y[inxt]) {
67 ytry =
reflect(pnts,
y, psum, ndim, auxdata,
func, ibig, 0.5);
69 for (
i = 0;
i < ndim + 1;
i++) {
71 for (
j = 0;
j < ndim;
j++)
72 pnts[
i * ndim +
j] = psum[
j] =
73 0.5 * (pnts[
i * ndim +
j] + pnts[isml * ndim +
j]);
87 double reflect(
double *pnts,
double y[],
double psum[],
short ndim,
89 short ibig,
float fac) {
93 double ytry, ptry[16];
95 fac1 = (1.0 -
fac) / ndim;
99 for (
j = 0;
j < ndim;
j++) ptry[
j] = psum[
j] * fac1 - pnts[ibig * ndim +
j] * fac2;
101 ytry = (*func)(auxdata, ptry);
103 if (ytry <
y[ibig]) {
105 for (
j = 0;
j < ndim;
j++) {
106 psum[
j] += ptry[
j] - pnts[ibig * ndim +
j];
107 pnts[ibig * ndim +
j] = ptry[
j];
double reflect(double *pnts, double y[], double psum[], short ndim, FITSTRUCT *auxdata, double(*func)(FITSTRUCT *, double[]), short ibig, float fac)
short amoeba(double *pnts, FITSTRUCT *auxdata, double(*func)(FITSTRUCT *, double[]), float tol)
subroutine func(x, conec, n, bconecno, bn, units, u, inno, i, outno, o, Input, Targ, p, sqerr)