Commits (2)
......@@ -40,3 +40,5 @@ demo/*1
Changes in lmfit-6.4, release 22nov17:
Changes in lmfit-7.0, released 27feb18:
- Automake support removed
- API changed:
- compute f-y only when needed
- Man page built under CMake
Changes in lmfit-6.4, released 22nov17:
- First version with CMake
- First version with fittest
- Probably last version with automake support
Changes in lmfit-6.3, release 3nov17:
Changes in lmfit-6.3, released 3nov17:
- two small corrections in core algorithm:
- 0.5 had become .55 at some point in the past
......@@ -7,8 +7,8 @@ set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(lmfit_SOVERSION 6) # API version
set(lmfit_VERSION ${lmfit_SOVERSION}.4) # lib version
set(lmfit_SOVERSION 7) # API version
set(lmfit_VERSION ${lmfit_SOVERSION}.0) # lib version
# --- Declare project-wide user flags, and set default values ---
option(FITTEST "Build with FitTest" OFF)
......@@ -19,6 +19,7 @@ set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -pedantic -Wall -Wno-sign-compare -
if (${FITTEST})
find_package(FitTest REQUIRED)
......@@ -46,16 +46,16 @@ void lmmin(
* Parameters:
* n is the number of variables (INPUT, positive integer).
* n_par is the number of variables (INPUT, positive integer).
* x is the solution vector (INPUT/OUTPUT, array of length n).
* par is the solution vector (INPUT/OUTPUT, array of length n).
* On input it must be set to an estimated solution.
* On output it yields the final estimate of the solution.
* m is the number of functions to be minimized (INPUT, positive integer).
* m_dat is the number of functions to be minimized (INPUT, positive integer).
* It must fulfill m>=n.
* y contains data points to be fitted.
* y contains data to be fitted. Use a null pointer if there are no data.
* data is a pointer that is ignored by lmmin; it is however forwarded
* to the user-supplied functions evaluate and printout.
function(one_page pname section)
OUTPUT "${pname}.${section}"
COMMAND pod2man -s ${section} -c "lmfit manual"
DEPENDS ${pname}.pod
OUTPUT ${pname}.html
COMMAND pod2html --title="lmfit manual" --noindex
> ${CMAKE_CURRENT_BINARY_DIR}/${pname}.html
DEPENDS ${pname}.pod
FILES ${CMAKE_CURRENT_BINARY_DIR}/${pname}.${section}
man ALL
DEPENDS lmmin.3 lmfit.7
html ALL
DEPENDS lmmin.html lmfit.html
one_page(lmmin 3)
one_page(lmfit 7)
=begin html
<link rel="stylesheet" href="podstyle.css" type="text/css" />
=end html
=head1 NAME
lmcurve - Levenberg-Marquardt least-squares fit of a curve (t,y)
B<#include <lmcurve.h>>
B<void lmcurve( const int> I<n_par>B<, double *>I<par>B<, const int> I<m_dat>B<,
constS< >double *>I<t>B<, constS< >double *>I<y>B<,
double (*>I<f>B<)( const double >I<ti>B<, const double *>I<par>B< ),
constS< >lm_control_struct *>I<control>B<,
lm_status_struct *>I<status>B<);>
B<void lmcurve_tyd(
const int> I<n_par>B<, double *>I<par>B<, const int> I<m_dat>B<,
constS< >double *>I<t>B<, constS< >double *>I<y>B<, constS< >double *>I<dy>B<,
double (*>I<f>B<)( const double >I<ti>B<, const double *>I<par>B< ),
constS< >lm_control_struct *>I<control>B<,
lm_status_struct *>I<status>B<);>
B<extern const lm_control_struct lm_control_double;>
B<extern const lm_control_struct lm_control_float;>
B<extern const char *lm_infmsg[];>
B<extern const char *lm_shortmsg[];>
B<lmcurve()> and B<lmcurve_tyd()> wrap the more generic minimization function B<lmmin()>, for use in curve fitting.
B<lmcurve()> determines a vector I<par> that minimizes the sum of squared elements of a residue vector I<r>[i] := I<y>[i] - I<f>(I<t>[i];I<par>). Typically, B<lmcurve()> is used to approximate a data set I<t>,I<y> by a parametric function I<f>(I<ti>;I<par>). On success, I<par> represents a local minimum, not necessarily a global one; it may depend on its starting value.
B<lmcurve_tyd()> does the same for a data set I<t>,I<y>,I<dy>, where I<dy> represents the standard deviation of empirical data I<y>. Residues are computed as I<r>[i] := (I<y>[i] - I<f>(I<t>[i];I<par>))/I<dy>[i]. Users must ensure that all I<dy>[i] are positive.
Function arguments:
=item I<n_par>
Number of free variables.
Length of parameter vector I<par>.
=item I<par>
Parameter vector.
On input, it must contain a reasonable guess.
On output, it contains the solution found to minimize ||I<r>||.
=item I<m_dat>
Number of data points.
Length of vectors I<t> and I<y>.
Must statisfy I<n_par> <= I<m_dat>.
=item I<t>
Array of length I<m_dat>.
Contains the abcissae (time, or "x") for which function I<f> will be evaluated.
=item I<y>
Array of length I<m_dat>.
Contains the ordinate values that shall be fitted.
=item I<dy>
Only in B<lmcurve_tyd()>.
Array of length I<m_dat>.
Contains the standard deviations of the values I<y>.
=item I<f>
A user-supplied parametric function I<f>(ti;I<par>).
=item I<control>
Parameter collection for tuning the fit procedure.
In most cases, the default &I<lm_control_double> is adequate.
If I<f> is only computed with single-precision accuracy,
I<&lm_control_float> should be used.
Parameters are explained in B<lmmin(3)>.
=item I<status>
A record used to return information about the minimization process:
For details, see B<lmmin(3)>.
=head1 EXAMPLE
Fit a data set y(x) by a curve f(x;p):
#include "lmcurve.h"
#include <stdio.h>
/* model function: a parabola */
double f( double t, const double *p )
return p[0] + p[1]*t + p[2]*t*t;
int main()
int n = 3; /* number of parameters in model function f */
double par[3] = { 100, 0, -10 }; /* really bad starting value */
/* data points: a slightly distorted standard parabola */
int m = 9;
int i;
double t[9] = { -4., -3., -2., -1., 0., 1., 2., 3., 4. };
double y[9] = { 16.6, 9.9, 4.4, 1.1, 0., 1.1, 4.2, 9.3, 16.4 };
lm_control_struct control = lm_control_double;
lm_status_struct status;
control.verbosity = 7;
printf( "Fitting ...\n" );
lmcurve( n, par, m, t, y, f, &control, &status );
printf( "Results:\n" );
printf( "status after %d function evaluations:\n %s\n",
status.nfev, lm_infmsg[status.outcome] );
printf("obtained parameters:\n");
for ( i = 0; i < n; ++i)
printf(" par[%i] = %12g\n", i, par[i]);
printf("obtained norm:\n %12g\n", status.fnorm );
printf("fitting data as follows:\n");
for ( i = 0; i < m; ++i)
printf( " t[%2d]=%4g y=%6g fit=%10g residue=%12g\n",
i, t[i], y[i], f(t[i],par), y[i] - f(t[i],par) );
return 0;
=head1 COPYING
Copyright (C) 2009-2015 Joachim Wuttke, Forschungszentrum Juelich GmbH
Software: FreeBSD License
Documentation: Creative Commons Attribution Share Alike
=head1 SEE ALSO
=begin html
<a href="http://apps.jcns.fz-juelich.de/man/lmmin.html"><b>lmmin</b>(3)</a>
=end html
=begin man
=end man
Homepage: http://apps.jcns.fz-juelich.de/lmfit
=head1 BUGS
Please send bug reports and suggestions to the author <j.wuttke@fz-juelich.de>.