Gnuplot has a curve fitting feature which is very useful for fitting data to a function of a general form.
Detailed information is available in this link. A simple example is given below:
The file test.data contains the folowing data:
1 .9 2 3.5 3 9.1 4 15 5 26 7 50 8 63 9 80 10 105It is apparent that the second column is square of the first column, with some arbitrary small values added.
Fit is accomplished by entering the following two commands. The first command defines the form of the function to be fitted, with parameters a, b, and c. The second command starts the fitting procedure.
gnuplot> f(x) = a*x**2 + b*x + c gnuplot> fit f(x) 'test.data' via a,b,c Iteration 0 WSSR : 398.87 delta(WSSR)/WSSR : 0 delta(WSSR) : 0 limit for stopping : 1e-05 lambda : 30.0586 initial set of free parameter values a = 1 b = 1 c = 1 / Iteration 1 WSSR : 81.2488 delta(WSSR)/WSSR : -3.90924 delta(WSSR) : -317.621 limit for stopping : 1e-05 lambda : 3.00586 resultant parameter values a = 0.895945 b = 0.948368 c = 0.982844 / Iteration 2 WSSR : 24.3883 delta(WSSR)/WSSR : -2.33146 delta(WSSR) : -56.8604 limit for stopping : 1e-05 lambda : 0.300586 resultant parameter values a = 1.0243 b = -0.133726 c = 0.579628 / Iteration 3 WSSR : 19.5484 delta(WSSR)/WSSR : -0.247585 delta(WSSR) : -4.83989 limit for stopping : 1e-05 lambda : 0.0300586 resultant parameter values a = 1.09005 b = -0.735675 c = 0.899112 / Iteration 4 WSSR : 19.5445 delta(WSSR)/WSSR : -0.00020073 delta(WSSR) : -0.00392317 limit for stopping : 1e-05 lambda : 0.00300586 resultant parameter values a = 1.09273 b = -0.767855 c = 0.973634 / Iteration 5 WSSR : 19.5445 delta(WSSR)/WSSR : -4.72269e-10 delta(WSSR) : -9.23027e-09 limit for stopping : 1e-05 lambda : 0.000300586 resultant parameter values a = 1.09273 b = -0.767902 c = 0.97375 After 5 iterations the fit converged. final sum of squares of residuals : 19.5445 rel. change during last iteration : -4.72269e-10 degrees of freedom (FIT_NDF) : 6 rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.80483 variance of residuals (reduced chisquare) = WSSR/ndf : 3.25742 Final set of parameters Asymptotic Standard Error ======================= ========================== a = 1.09273 +/- 0.08446 (7.729%) b = -0.767902 +/- 0.9546 (124.3%) c = 0.97375 +/- 2.192 (225.1%) correlation matrix of the fit parameters: a b c a 1.000 b -0.978 1.000 c 0.825 -0.910 1.000The fitting program generates output which shows how the final set of parameters are determined.
The command below is used to generate a plot which contains the original data points as well as the fitted curve:
p "test.data", 1.09273*x*x -0.767902*x + 0.97375