Andrew Finlay - 2016-04-26

Hello,

I'm trying to write code to automatically fit binned simulation data with a Gaussian function, but I'm getting a "Singular matrix in Invert_RtR" error when performing the fit.

I'm currently using gnuplot version 5.0.3 on Windows 8. Code and data are attached below.

Any help / guidance would be much appreciated.

Thanks.

gnuplot code:

reset
unset key
set xlabel "Time of Flight"
set ylabel "Counts"
A = 218.0
Mean = 3561.978563
StdDev = 0.008026
f(x) = A*exp(-(x-Mean)**2/(2*StdDev**2)) 
set fit errorvariables
fit [3561.851:3562.008] f(x) "histoTest.txt" u 1:2:3 yerror via A,Mean,StdDev 
plot "histoTest.txt" u 1:2:3 w yerrorbars, f(x)

Contents of my data file (please note, the error values are the square root of the counts, but when this would be 0, I chose a value of 0.0001 to try to avoid issues):

# ToF   Count   Error
3561.851    1   1.000000
3561.855    0   0.000100
3561.859    0   0.000100
3561.863    0   0.000100
3561.867    0   0.000100
3561.871    0   0.000100
3561.875    0   0.000100
3561.878    0   0.000100
3561.882    0   0.000100
3561.886    0   0.000100
3561.890    1   1.000000
3561.894    2   1.414214
3561.898    0   0.000100
3561.902    2   1.414214
3561.906    3   1.732051
3561.910    2   1.414214
3561.914    2   1.414214
3561.918    3   1.732051
3561.922    6   2.449490
3561.926    6   2.449490
3561.930    4   2.000000
3561.933    10  3.162278
3561.937    8   2.828427
3561.941    13  3.605551
3561.945    10  3.162278
3561.949    11  3.316625
3561.953    26  5.099020
3561.957    24  4.898979
3561.961    41  6.403124
3561.965    55  7.416198
3561.969    58  7.615773
3561.973    110 10.488088
3561.977    218 14.764823
3561.981    170 13.038405
3561.984    49  7.000000
3561.988    17  4.123106
3561.992    3   1.732051
3561.996    1   1.000000
3562.000    3   1.732051
3562.004    3   1.732051
3562.008    0   0.000100