Heaviside Function Fit

Bonjour.

I'd like to fit the data with f(t) = Heaviside(t,T0)*(A(1-exp(-(t-T0)/Tth))*exp(-(t-T0)/Tel)+B(1-exp(-(t-T0)/Tel))*exp(-(t-T0)/Tdiff)).
Heaviside is defined as below. And I set all elements of the Epsilon wave 10^-6 to avoid the singular matrix error.
But the fit process didn't proceed any further iteration. In addition, there is another error message : ' fitting function returned NaN for at least one x value.'
Was I wrong for making the Epsilon wave ? Could you suggest other ways to fix this ?
Merci, in advance.

Function Heaviside(x, xo)
//+
Variable x, xo
return x < xo ? 0 : 1
//+
End

Function ReflectivityFit(w,t) : FitFunc
Wave w
Variable t

//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Equation:
//CurveFitDialog/ f(t) = Heaviside(t,T0)*(A(1-exp(-(t-T0)/Tth))*exp(-(t-T0)/Tel)+B(1-exp(-(t-T0)/Tel))*exp(-(t-T0)/Tdiff))
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ t
//CurveFitDialog/ Coefficients 6
//CurveFitDialog/ w[0] = T0
//CurveFitDialog/ w[1] = A
//CurveFitDialog/ w[2] = B
//CurveFitDialog/ w[3] = Tth
//CurveFitDialog/ w[4] = Tel
//CurveFitDialog/ w[5] = Tdiff

return Heaviside(t,w[0])*(w[1](1-exp(-(t-w[0])/w[3]))*exp(-(t-w[0])/w[4])+w[2](1-exp(-(t-w[0])/w[4]))*exp(-(t-w[0])/w[5]))
End
One possible reason for the error NaN for at least one value is that your starting guess isn't close enough. Try generating some data with the function, and then fitting it with the same function, to see if your function works.
mtaylor wrote:
One possible reason for the error NaN for at least one value is that your starting guess isn't close enough. Try generating some data with the function, and then fitting it with the same function, to see if your function works.


Thank you for replying. But, I already have checked validity of the starting guess and that it was similar graph to the the data I wanted to fit. Is there any other reason on this ?
Make sure your waves are double-precision. You can check them via Data->Browse waves and change them via Data->Redimension Waves.

If they are already double-precision, if possible, create a simplified Igor experiment that shows the problem and post it here so we can play with it.
Fitting the position of a Heavyside step function is very difficult- the value of chi-square is discontinuous, so the derivatives are difficult to compute.

The derivatives of chi-square with respect to the fit coefficients are computed by a numeric approximation. The epsilon wave is used to set the difference in a fit coefficient that is used in computing this numeric approximation. As long as epsilon for T0 is smaller than the interval between your data points, the value of chi-square doesn't change, and the derivative is zero. That results in a singular matrix error.

The only way that I have found to fit the position of a step function is to set the epsilon for the position (T0) to a value larger than the X spacing between your input data points.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Gencurvefit is a good option for when chi2 is not continuous, as it doesn't use derivatives.

This function works for me, the only thing I changed is adding two multiply mark between w[1] and (1-exp(-(t-w[0])/w[3])), w[2] and (1-exp(-(t-w[0]). So the function is:

return Heaviside(t,w[0])*(w[1]*(1-exp(-(t-w[0])/w[3]))*exp(-(t-w[0])/w[4])+w[2]*(1-exp(-(t-w[0])/w[4]))*exp(-(t-w[0])/w[5]))
End