LMCURVE(3)

πŸ“¦
version 10.0 Β· 2 versions
, in fedora 44

πŸ’– 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 vector par. 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 vectors t and y. must statisfy n_par <= m_dat. (yes, the original really does say "statisfy", we're keeping it, it's iconic πŸ’…)
  • t β€” array of length m_dat. contains the abcissae (time, or "x") for which function f will be evaluated.
  • y β€” array of length m_dat. contains the ordinate values that shall be fitted. the ones you're trying to match, yk?
  • dy β€” only in lmcurve_tyd(). array of length m_dat. contains the standard deviations of the values y.
  • f β€” a user-supplied parametric function f(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_double is adequate. if f is only computed with single-precision accuracy, &lm_control_float should be used instead. parameters are explained over in lmmin(3).
  • status β€” a record used to return information about the minimization process. for details, see lmmin(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