
Conditional variables in fit functions

MostlyHarmless
Function TwoSegment(w,x) : FitFunc Wave w Variable x //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/ variable result //CurveFitDialog/ if (x < breakX) //CurveFitDialog/ result = a1 + b1*x //CurveFitDialog/ else //CurveFitDialog/ result = a2 + b2*x //CurveFitDialog/ endif //CurveFitDialog/ f(x) = result //CurveFitDialog/ End of Equation //CurveFitDialog/ Independent Variables 1 //CurveFitDialog/ x //CurveFitDialog/ Coefficients 5 //CurveFitDialog/ w[0] = a1 //CurveFitDialog/ w[1] = b1 //CurveFitDialog/ w[2] = a2 //CurveFitDialog/ w[3] = b2 //CurveFitDialog/ w[4] = breakX variable result if (x < w[4]) result = w[0] + w[1]*x else result = w[2] + w[3]*x endif return result End
In general, you need an epsilon wave with the epsilon for the break point set pretty large. If you are using Igor 7, you can read about the epsilon wave here:
DisplayHelpTopic "The Epsilon Wave"
Otherwise...
I would set the epsilon for w[4] to a substantial fraction of the distance between data points.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 14, 2016 at 11:00 am - Permalink
September 14, 2016 at 10:08 pm - Permalink