7 void misfit(
double *p,
double *x,
int m,
int n,
void *data)
10 x[0] = 100 * pow(p[1] - pow(p[0], 2), 2) + pow(1 - p[0], 2);
11 x[1] = 100 * pow(p[1] - pow(p[0], 2), 2) + pow(1 - p[0], 2);
12 x[2] = 100 * pow(p[1] - pow(p[0], 2), 2) + pow(1 - p[0], 2);
17 const int nparams = 2;
19 const int maxiter = 100;
20 double p[nparams], lb[nparams], ub[nparams];
23 double opts[LM_OPTS_SZ], info[LM_INFO_SZ];
29 opts[4] = LM_DIFF_DELTA;
31 for (
int i = 0; i < nparams; ++i)
38 for (
int i = 0; i < n; i++)
41 double ret = dlevmar_bc_dif(
misfit, p, x, nparams, n, lb, ub, maxiter,
42 opts, info, NULL, NULL, NULL);
43 cout <<
"Levenberg-Marquardt returned " << ret <<
" in " << info[5]
44 <<
"iter, reason " << info[6] << endl;
47 for (
int i = 0; i < nparams; ++i)
50 cout << endl <<
" Minimization info:" << endl;
51 for (
int i = 0; i < LM_INFO_SZ; ++i)
52 cout << info[i] <<
" ";
void misfit(double *p, double *x, int m, int n, void *data)