GnuplotFit data with gnuplot


The fit command can fit a user-defined function to a set of data points (x,y) or (x,y,z), using an implementation of the nonlinear least-squares (NLLS) Marquardt-Levenberg algorithm.

Any user-defined variable occurring in the function body may serve as a fit parameter, but the return type of the function must be real.


  • fit [xrange][yrange] function "datafile" using modifier via parameter_file


Fitting parameters a, b, c and any letter that had not been used previouslyUse letters to represent parameters that will be used to fit a function. E.g.: f(x) = a * exp(b * x) + c, g(x,y) = a*x**2 + b*y**2 + c*x*y
File parameters start.parInstead using uninitialised parameters (the Marquardt-Levenberg will automatically initialise for you a=b=c=...=1) you can put them in a file start.par and them call with in the parameter_file section. E.g.: fit f(x) 'data.dat' u 1:2 via 'start.par'. An example for the start.par file is shown below


Short introduction

fit is used to find a set of parameters that ’best’ fits your data to your user-defined function. The fit is judged on the basis of the sum of the squared differences or ’residuals’ (SSR) between the input data points and the function values, evaluated at the same places. This quantity is often called ’chisquare’ (i.e., the Greek letter chi, to the power of 2). The algorithm attempts to minimize SSR, or more precisely, WSSR, as the residuals are ’weighted’ by the input data errors (or 1.0) before being squared. (Ibidem)

The fit.log file

After each iteration step a detailed info is given about the fit's state both on the screen and on a so-called log-file fit.log. This file will never be erased but always appended so that the fit's history isn't lost.