1 <?xml version="1.0" ?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <title>lmfit: a self-contained C library for Levenberg-Marquardt least-squares minimization and curve fitting</title> 6 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 7 <link rev="made" href="mailto:root@localhost" /> 8 </head> 9 10 <body> 11 12 13 14 15 16 <link rel="stylesheet" href="podstyle.css" type="text/css" /> 17 18 <h1 id="NAME">NAME</h1> 19 20 <p>lmcurve - Levenberg-Marquardt least-squares fit of a curve (t,y)</p> 21 22 <h1 id="SYNOPSIS">SYNOPSIS</h1> 23 24 <p><b>#include <lmcurve.h</b>></p> 25 26 <p><b>void lmcurve( const int</b> <i>n_par</i><b>, double *</b><i>par</i><b>, const int</b> <i>m_dat</i><b>, const<span style="white-space: nowrap;"> </span>double *</b><i>t</i><b>, const<span style="white-space: nowrap;"> </span>double *</b><i>y</i><b>, double (*</b><i>f</i><b>)( const double </b><i>ti</i><b>, const double *</b><i>par</i><b> ), const<span style="white-space: nowrap;"> </span>lm_control_struct *</b><i>control</i><b>, lm_status_struct *</b><i>status</i><b>);</b></p> 27 28 <p><b>void lmcurve_tyd( const int</b> <i>n_par</i><b>, double *</b><i>par</i><b>, const int</b> <i>m_dat</i><b>, const<span style="white-space: nowrap;"> </span>double *</b><i>t</i><b>, const<span style="white-space: nowrap;"> </span>double *</b><i>y</i><b>, const<span style="white-space: nowrap;"> </span>double *</b><i>dy</i><b>, double (*</b><i>f</i><b>)( const double </b><i>ti</i><b>, const double *</b><i>par</i><b> ), const<span style="white-space: nowrap;"> </span>lm_control_struct *</b><i>control</i><b>, lm_status_struct *</b><i>status</i><b>);</b></p> 29 30 <p><b>extern const lm_control_struct lm_control_double;</b></p> 31 32 <p><b>extern const lm_control_struct lm_control_float;</b></p> 33 34 <p><b>extern const char *lm_infmsg[];</b></p> 35 36 <p><b>extern const char *lm_shortmsg[];</b></p> 37 38 <h1 id="DESCRIPTION">DESCRIPTION</h1> 39 40 <p><b>lmcurve()</b> and <b>lmcurve_tyd()</b> wrap the more generic minimization function <b>lmmin()</b>, for use in curve fitting.</p> 41 42 <p><b>lmcurve()</b> determines a vector <i>par</i> that minimizes the sum of squared elements of a residue vector <i>r</i>[i] := <i>y</i>[i] - <i>f</i>(<i>t</i>[i];<i>par</i>). Typically, <b>lmcurve()</b> is used to approximate a data set <i>t</i>,<i>y</i> by a parametric function <i>f</i>(<i>ti</i>;<i>par</i>). On success, <i>par</i> represents a local minimum, not necessarily a global one; it may depend on its starting value.</p> 43 44 <p><b>lmcurve_tyd()</b> does the same for a data set <i>t</i>,<i>y</i>,<i>dy</i>, where <i>dy</i> represents the standard deviation of empirical data <i>y</i>. Residues are computed as <i>r</i>[i] := (<i>y</i>[i] - <i>f</i>(<i>t</i>[i];<i>par</i>))/<i>dy</i>[i]. Users must ensure that all <i>dy</i>[i] are positive.</p> 45 46 <p>Function arguments:</p> 47 48 <dl> 49 50 <dt id="n_par"><i>n_par</i></dt> 51 <dd> 52 53 <p>Number of free variables. Length of parameter vector <i>par</i>.</p> 54 55 </dd> 56 <dt id="par"><i>par</i></dt> 57 <dd> 58 59 <p>Parameter vector. On input, it must contain a reasonable guess. On output, it contains the solution found to minimize ||<i>r</i>||.</p> 60 61 </dd> 62 <dt id="m_dat"><i>m_dat</i></dt> 63 <dd> 64 65 <p>Number of data points. Length of vectors <i>t</i> and <i>y</i>. Must statisfy <i>n_par</i> <= <i>m_dat</i>.</p> 66 67 </dd> 68 <dt id="t"><i>t</i></dt> 69 <dd> 70 71 <p>Array of length <i>m_dat</i>. Contains the abcissae (time, or "x") for which function <i>f</i> will be evaluated.</p> 72 73 </dd> 74 <dt id="y"><i>y</i></dt> 75 <dd> 76 77 <p>Array of length <i>m_dat</i>. Contains the ordinate values that shall be fitted.</p> 78 79 </dd> 80 <dt id="dy"><i>dy</i></dt> 81 <dd> 82 83 <p>Only in <b>lmcurve_tyd()</b>. Array of length <i>m_dat</i>. Contains the standard deviations of the values <i>y</i>.</p> 84 85 </dd> 86 <dt id="f"><i>f</i></dt> 87 <dd> 88 89 <p>A user-supplied parametric function <i>f</i>(ti;<i>par</i>).</p> 90 91 </dd> 92 <dt id="control"><i>control</i></dt> 93 <dd> 94 95 <p>Parameter collection for tuning the fit procedure. In most cases, the default &<i>lm_control_double</i> is adequate. If <i>f</i> is only computed with single-precision accuracy, <i>&lm_control_float</i> should be used. Parameters are explained in <b>lmmin(3)</b>.</p> 96 97 </dd> 98 <dt id="status"><i>status</i></dt> 99 <dd> 100 101 <p>A record used to return information about the minimization process: For details, see <b>lmmin(3)</b>.</p> 102 103 </dd> 104 </dl> 105 106 <h1 id="EXAMPLE">EXAMPLE</h1> 107 108 <p>Fit a data set y(x) by a curve f(x;p):</p> 109 110 <pre><code> #include "lmcurve.h" 111 #include <stdio.h> 112 113 /* model function: a parabola */ 114 115 double f( double t, const double *p ) 116 { 117 return p[0] + p[1]*t + p[2]*t*t; 118 } 119 120 int main() 121 { 122 int n = 3; /* number of parameters in model function f */ 123 double par[3] = { 100, 0, -10 }; /* really bad starting value */ 124 125 /* data points: a slightly distorted standard parabola */ 126 int m = 9; 127 int i; 128 double t[9] = { -4., -3., -2., -1., 0., 1., 2., 3., 4. }; 129 double y[9] = { 16.6, 9.9, 4.4, 1.1, 0., 1.1, 4.2, 9.3, 16.4 }; 130 131 lm_control_struct control = lm_control_double; 132 lm_status_struct status; 133 control.verbosity = 7; 134 135 printf( "Fitting ...\n" ); 136 lmcurve( n, par, m, t, y, f, &control, &status ); 137 138 printf( "Results:\n" ); 139 printf( "status after %d function evaluations:\n %s\n", 140 status.nfev, lm_infmsg[status.outcome] ); 141 142 printf("obtained parameters:\n"); 143 for ( i = 0; i < n; ++i) 144 printf(" par[%i] = %12g\n", i, par[i]); 145 printf("obtained norm:\n %12g\n", status.fnorm ); 146 147 printf("fitting data as follows:\n"); 148 for ( i = 0; i < m; ++i) 149 printf( " t[%2d]=%4g y=%6g fit=%10g residue=%12g\n", 150 i, t[i], y[i], f(t[i],par), y[i] - f(t[i],par) ); 151 152 return 0; 153 }</code></pre> 154 155 <h1 id="COPYING">COPYING</h1> 156 157 <p>Copyright (C) 2009-2015 Joachim Wuttke, Forschungszentrum Juelich GmbH</p> 158 159 <p>Software: FreeBSD License</p> 160 161 <p>Documentation: Creative Commons Attribution Share Alike</p> 162 163 <h1 id="SEE-ALSO">SEE ALSO</h1> 164 165 166 167 <a href="http://apps.jcns.fz-juelich.de/man/lmmin.html"><b>lmmin</b>(3)</a> 168 169 <p>Homepage: http://apps.jcns.fz-juelich.de/lmfit</p> 170 171 <h1 id="BUGS">BUGS</h1> 172 173 <p>Please send bug reports and suggestions to the author <j.wuttke (a] fz-juelich.de>.</p> 174 175 176 </body> 177 178 </html> 179 180 181