Standard preamble:
========================================================================
..
.... Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.
If the F register is turned on, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.
Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF
Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================
Title "lmmin 3"
way too many mistakes in technical documents.
\fBvoid lmmin( const int n_par, double *par, const int m_dat, const void *data, void *evaluate( const double *par, const int m_dat, const void *data, double *fvec, int *userbreak), const lm_control_struct *control, lm_status_struct *status );
\fBextern const lm_control_struct lm_control_double;
\fBextern const lm_control_struct lm_control_float;
\fBextern const char *lm_infmsg[];
\fBextern const char *lm_shortmsg[];
For applications in curve fitting, the wrapper function \f(BIlmcurve\|(3) offers a simplified \s-1API.\s0
The Levenberg-Marquardt minimization starts with a steepest-descent exploration of the parameter space, and achieves rapid convergence by crossing over into the Newton-Gauss method.
Function arguments:
.Vb 1 lm_control_struct control = lm_control_double; /* or _float */ .Ve
After this, parameters may be overwritten:
.Vb 2 control.patience = 500; /* allow more iterations */ control.verbosity = 15; /* for verbose monitoring */ .Ve
An application written this way is guaranteed to work even if new parameters are added to lm_control_struct.
Conversely, addition of parameters is not considered an \s-1API\s0 change; it may happen without increment of the major version number.
.Vb 2 #include "lmmin.h" #include <stdio.h> \& /* fit model: a plane p0 + p1*tx + p2*tz */ double f( double tx, double tz, const double *p ) { return p[0] + p[1]*tx + p[2]*tz; } \& /* data structure to transmit data arays and fit model */ typedef struct { double *tx, *tz; double *y; double (*f)( double tx, double tz, const double *p ); } data_struct; \& /* function evaluation, determination of residues */ void evaluate_surface( const double *par, int m_dat, const void *data, double *fvec, int *userbreak ) { /* for readability, explicit type conversion */ data_struct *D; D = (data_struct*)data; \& int i; for ( i = 0; i < m_dat; i++ ) fvec[i] = D->y[i] - D->f( D->tx[i], D->tz[i], par ); } \& int main() { /* parameter vector */ int n_par = 3; /* number of parameters in model function f */ double par[3] = { -1, 0, 1 }; /* arbitrary starting value */ \& /* data points */ int m_dat = 4; double tx[4] = { -1, -1, 1, 1 }; double tz[4] = { -1, 1, -1, 1 }; double y[4] = { 0, 1, 1, 2 }; \& data_struct data = { tx, tz, y, f }; \& /* auxiliary parameters */ lm_status_struct status; lm_control_struct control = lm_control_double; control.verbosity = 3; \& /* perform the fit */ printf( "Fitting:\en" ); lmmin( n_par, par, m_dat, (const void*) &data, evaluate_surface, &control, &status ); \& /* print results */ printf( "\enResults:\en" ); printf( "status after %d function evaluations:\en %s\en", status.nfev, lm_infmsg[status.outcome] ); \& printf("obtained parameters:\en"); int i; for ( i=0; i<n_par; ++i ) printf(" par[%i] = %12g\en", i, par[i]); printf("obtained norm:\en %12g\en", status.fnorm ); \& printf("fitting data as follows:\en"); double ff; for ( i=0; i<m_dat; ++i ){ ff = f(tx[i], tz[i], par); printf( " t[%2d]=%12g,%12g y=%12g fit=%12g residue=%12g\en", i, tx[i], tz[i], y[i], ff, y[i] - ff ); } \& return 0; } .Ve
Software: FreeBSD License
Documentation: Creative Commons Attribution Share Alike
Homepage: http://apps.jcns.fz-juelich.de/lmfit