LMCURVE(3)
π lmcurve(3) β the lmfit manual, but make it make sense π
okay bestie, so this is the lmcurve(3) page from the lmfit manual. it's giving "curve fitting but make it a whole personality". buckle up π
β¨ NAME β¨
lmcurve β Levenberg-Marquardt least-squares fit of a curve (t,y) π¦
like. that's the whole vibe. you hand it data, it hands you parameters. periodt.
β¨ SYNOPSIS β¨
#include <lmcurve.h>
void lmcurve( const int n_par, double *par, const int m_dat,
const double *t, const double *y,
double (*f)( const double ti, const double *par ),
const lm_control_struct *control,
lm_status_struct *status);
void lmcurve_tyd(
const int n_par, double *par, const int m_dat,
const double *t, const double *y, const double *dy,
double (*f)( const double ti, const double *par ),
const lm_control_struct *control,
lm_status_struct *status);
extern const lm_control_struct lm_control_double;
extern const lm_control_struct lm_control_float;
extern const char *lm_infmsg[];
extern const char *lm_shortmsg[];
like yes, that's a lot of arguments. no cap. but we move π
β¨ DESCRIPTION β¨
so lmcurve() and lmcurve_tyd() are basically the glow-up wrappers around the way more generic minimization function lmmin(). they exist purely so curve fitting doesn't make you lose your mind. obsessed with them actually.
lmcurve() figures out a vector par that minimizes the sum of squared elements of a residue vector, and the residue is defined as:
r[i] := y[i] - f(t[i];par)
typically you'd use lmcurve() to approximate a data set t,y by a parametric function f(ti;par). and here's the tea β β on success, par represents a local minimum, not necessarily a global one. it may literally depend on its starting value. so your starting guess matters, bestie, choose wisely π
lmcurve_tyd() does the exact same thing but for a data set t,y,dy, where dy is the standard deviation of the empirical data y. residues get computed as:
r[i] := (y[i] - f(t[i];par))/dy[i]
β οΈ users must ensure that all dy[i] are positive. that's on you, not on us. do not skip the vibe check on your standard deviations π
πΈ Function arguments (the whole cast) πΈ
n_parβ number of free variables. it's the length of the parameter vectorpar. that's it, that's the job π«Άparβ the parameter vector. on input, it must contain a reasonable guess (emphasis on reasonable, bestie). on output, it contains the solution found to minimize||r||. main character energy fr fr.m_datβ number of data points. length of vectorstandy. must statisfyn_par <= m_dat. (yes, the original really does say "statisfy", we're keeping it, it's iconic π )tβ array of lengthm_dat. contains the abcissae (time, or "x") for which functionfwill be evaluated.yβ array of lengthm_dat. contains the ordinate values that shall be fitted. the ones you're trying to match, yk?dyβ only inlmcurve_tyd(). array of lengthm_dat. contains the standard deviations of the valuesy.fβ a user-supplied parametric functionf(ti;par). you write this one, it's your moment β¨controlβ parameter collection for tuning the fit procedure. in most cases, the default&lm_control_doubleis adequate. iffis only computed with single-precision accuracy,&lm_control_floatshould be used instead. parameters are explained over inlmmin(3).statusβ a record used to return information about the minimization process. for details, seelmmin(3). it's the receipts π
β¨ EXAMPLE β¨
okay so say you wanna fit a data set y(x) by a curve f(x;p). here's the whole thing, character for character, no edits:
#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;
}
not the comment /* really bad starting value */ β we love a self-aware starting value. the algorithm said "we'll fix it" and honestly? it did π
β¨ COPYING β¨
Copyright (C) 2009-2015 Joachim Wuttke, Forschungszentrum Juelich GmbH
Software: FreeBSD License
Documentation: Creative Commons Attribution Share Alike
like, respect the license bestie, it's literally right there π«Ά
β¨ SEE ALSO β¨
Homepage: https://jugit.fz-juelich.de/mlz/lmfit
go read lmmin(3) if you want the deep lore. iykyk π
β¨ BUGS β¨
Please send bug reports and suggestions to the author <j.wuttke@fz-juelich.de>.
not me asking you to actually email the author. but like, do it, they wanna hear from you π
and that's the page!! this was perl v5.42.0, dated 2026-01-16, from builddir::bui...::man::lmcurve(3) β mwah, slay, go fit some curves bestie π
β¨π
π¦ where this page comes from
- fedora 44: lmfit-devel 10.0-2.fc44 Β· LicenseRef-Callaway-BSD AND LicenseRef-Callaway-CC-BY
- fedora 44: lmfit-devel 10.0-2.fc44 Β· LicenseRef-Callaway-BSD AND LicenseRef-Callaway-CC-BY
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms