Gaussian ODR fit fails with singular matrix error

When I try to fit a Gaussian distribution I get a singular matrix error:

// works:
make /o  xdata = p + 1
make /o  ydata = exp(-(xdata - 60)^2 / 50)
CurveFit /Q/W=2 gauss ydata /X=xdata /D  

// doesn't work:
CurveFit /Q/W=2 /ODR=2  gauss ydata /X=xdata /D
// fails with singular matrix or other numeric error


I can fix this error by adding or subtracting 1 (why?):

// works:
ydata = exp(-(xdata - 60)^2 / 50) + 1
CurveFit /Q/W=2 /ODR=2  gauss ydata /X=xdata /D  

// works:
ydata = exp(-(xdata - 60)^2 / 50) - 1
CurveFit /Q/W=2 /ODR=2  gauss ydata /X=xdata /D  


I can fit a matrix of ones with a line, but not a gauss:
// works:
ydata = 0
CurveFit /Q/W=2 /ODR=2  line ydata /X=xdata /D  

// doesn't work:
ydata = 0
CurveFit /Q/W=2 /ODR=2  gauss ydata /X=xdata /D  


Could the problem be due to the larger number of fit parameters in the gauss case?

My real problem involves a custom function with 4 parameters, but 3 are held constant. It did not matter whether I hold them at zero or one.
I can do your fit if I add a bit of noise to the Y data:

•ydata += gnoise(0.001)
•CurveFit /DBUG=0/W=2 /ODR=2 gauss ydata /X=xdata /D
Fit converged properly
fit_ydata= W_coef[0]+W_coef[1]*exp(-((x-W_coef[2])/W_coef[3])^2)
W_coef={-0.00011879,1.0004,59.999,7.0702}
V_chisq= 0.000126786;V_npnts= 128;V_numNaNs= 0;V_numINFs= 0;
V_startRow= 0;V_endRow= 127;
W_sigma={0.0001,0.000423,0.00241,0.00355}
Coefficient values ± one standard deviation
y0 =-0.00011879 ± 0.0001
A =1.0004 ± 0.000423
x0 =59.999 ± 0.00241
width =7.0702 ± 0.00355

There is an undocumented debug mode for ODR fitting that spits out a bunch of stuff to the computer console (I run it under a debugger that has a console window, it would be quite difficult for you to use this mode). In that mode I see output messages from the ODRPack95 package. If you don't add noise to the computation it complains about bad derivatives at the solution. No doubt, because the solution is perfect, the derivatives are all zero, which is bad for iterative fitting.

So just one of those things- fitting doesn't work well with perfect data!

I line fit doesn't fit your data well, so the derivatives aren't zero. I can't tell if this is related to your real fit function without seeing more.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com