
Let's suppose that the file 'Mydata.txt' contains the following data points:
Let's see then the three necessary steps to fit those data points to a straight line.#x sx y sy 0.0 0.030 5.9 1.00 0.9 0.030 5.4 0.74 1.8 0.040 4.4 0.50 2.6 0.035 4.6 0.35 3.3 0.070 3.5 0.22 4.4 0.110 3.7 0.22 5.2 0.130 2.8 0.12 6.1 0.220 2.8 0.12 6.5 0.740 2.4 0.10 7.4 1.000 1.5 0.04
1. Load the Data from file with the command:
[x,sx,y,sy] = FitLoad('MyData.txt');
2. Fit the data with a straight line typing the command:
FS = FitLinear(x,[],y,sy);
A plot with theoretical curve fitted to the experimental data and the difference plot is shown.
![]()
The following brief report of the fitting results is printed also
Fitting Function: a*x+b Parameters: a = -6.15241e-01 +- 6.12600e-02 b = 6.11891e+00 +- 4.21700e-01 Degrees of Freedom = 8 Reduced ChiSquare = 4.39755 Correlation Matrix: a 1.00 b -0.99 1.00The returning new fields of the FS structure are respectively:
FS.p vector of parameters
FS.sp vector of parameters' uncertainties
FS.CC cross correlation matrix
FS.Xn_p reduced chi square
3. Produce PDF report file with the command:
FitPDFReport(FS,'FitExampleLinear');
After a resonable time a file "FitExampleLinear.pdf" with the graphical and numerical result of the fit is created.
4. considering the uncertainties sx on the horizontal axis by typing the command:
FS = FitLinear(x,sx,y,sy);
We obtain the following result
![]()
Fitting Function: y(x)=a*x+b Parameters: a = -4.62830e-01 +- 5.74027e-02 b = 5.39445e+00 +- 2.93244e-01 Degrees of Freedom = 8 Reduced ChiSquare = 1.35096
Predefined Fitting procedures
FitExp y(x)=a*exp(b*x)+c
FitDoubleExp y(x)=a1*exp(b1*x)+a2*exp(b2*x)+c
FitGauss y(x)= exp( -0.5*(x-mu).^2/sigma^2 )/(sqrt(2*pi)*sigma)+y0
FitLinear y(x)= a*x +b
FitLorentian y(x)= A/(x0+(x-m).^2)+y0
FitQuadratic y(x) = a*x.^2+b*x +c
FitLoad Load data from an ascii file into columns vectors
FitSave save data into an ascii file
Home Page