GNUPlot Manual
GNUPlot Manual
GNUPlot Manual
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
22 FIT gnuplot 4.0 31<br />
current parameter values, (2) continue the fit, (3) execute a gnuplot command as specified by the<br />
environment variable FIT SCRIPT. The default for FIT SCRIPT is replot, so if you had previously<br />
plotted both the data and the fitting function in one graph, you can display the current state of the fit.<br />
Once fit has finished, the update command may be used to store final values in a file for subsequent<br />
use as a parameter file. See update (p. 158) for details.<br />
22.1 Adjustable parameters<br />
There are two ways that via can specify the parameters to be adjusted, either directly on the command<br />
line or indirectly, by referencing a parameter file. The two use different means to set initial values.<br />
Adjustable parameters can be specified by a comma-separated list of variable names after the via<br />
keyword. Any variable that is not already defined is created with an initial value of 1.0. However, the fit<br />
is more likely to converge rapidly if the variables have been previously declared with more appropriate<br />
starting values.<br />
In a parameter file, each parameter to be varied and a corresponding initial value are specified, one per<br />
line, in the form<br />
varname = value<br />
Comments, marked by ’#’, and blank lines are permissible. The special form<br />
varname = value # FIXED<br />
means that the variable is treated as a ’fixed parameter’, initialized by the parameter file, but not<br />
adjusted by fit. For clarity, it may be useful to designate variables as fixed parameters so that their<br />
values are reported by fit. The keyword # FIXED has to appear in exactly this form.<br />
22.2 Short introduction<br />
fit is used to find a set of parameters that ’best’ fits your data to your user-defined function. The fit is<br />
judged on the basis of the sum of the squared differences or ’residuals’ (SSR) between the input data<br />
points and the function values, evaluated at the same places. This quantity is often called ’chisquare’<br />
(i.e., the Greek letter chi, to the power of 2). The algorithm attempts to minimize SSR, or more precisely,<br />
WSSR, as the residuals are ’weighted’ by the input data errors (or 1.0) before being squared; see fit<br />
error estimates (p. 32) for details.<br />
That’s why it is called ’least-squares fitting’. Let’s look at an example to see what is meant by ’non-linear’,<br />
but first we had better go over some terms. Here it is convenient to use z as the dependent variable<br />
for user-defined functions of either one independent variable, z=f(x), or two independent variables,<br />
z=f(x,y). A parameter is a user-defined variable that fit will adjust, i.e., an unknown quantity in the<br />
function declaration. Linearity/non-linearity refers to the relationship of the dependent variable, z, to<br />
the parameters which fit is adjusting, not of z to the independent variables, x and/or y. (To be technical,<br />
the second {and higher} derivatives of the fitting function with respect to the parameters are zero for a<br />
linear least-squares problem).<br />
For linear least-squares (LLS), the user-defined function will be a sum of simple functions, not involving<br />
any parameters, each multiplied by one parameter. NLLS handles more complicated functions in which<br />
parameters can be used in a large number of ways. An example that illustrates the difference between<br />
linear and nonlinear least-squares is the Fourier series. One member may be written as<br />
z=a*sin(c*x) + b*cos(c*x).<br />
If a and b are the unknown parameters and c is constant, then estimating values of the parameters is a<br />
linear least-squares problem. However, if c is an unknown parameter, the problem is nonlinear.<br />
In the linear case, parameter values can be determined by comparatively simple linear algebra, in one<br />
direct step. However LLS is a special case which is also solved along with more general NLLS problems by<br />
the iterative procedure that gnuplot uses. fit attempts to find the minimum by doing a search. Each step<br />
(iteration) calculates WSSR with a new set of parameter values. The Marquardt-Levenberg algorithm<br />
selects the parameter values for the next iteration. The process continues until a preset criterion is