The final section of this chapter will demonstrate the use of an arbitrary fit function. The fit process is not different from the example described above, just the theory function is entered as KUPLOT type of expression. Assuming your theory function should be
the corresponding command to define this theory function in the fit sublevel of KUPLOT would look like this
func fx,3,p[1]*exp(-p[2]*r[0])*sin(r[0]+p[3])
The parameter 'fx' stands for a user defined function. The next parameter is the number of fit parameters to be used for that function. As last parameter, the function itself is given. The variable r[0] stands for xi similar to the command 'func' (see section 7.1). The fit parameters are represented by variables p[i]. Since the nature of the fit function is unknown, there is no calculation of default starting values. They have to be supplied by the user via the command 'par'. Note that KUPLOT is calculating the expression once after the 'func' command is given to perform a syntax check. If no proper starting values for p[i] have been defined this calculation might fail, e.g. by a division by zero. After the function is successfully defined, the fit process proceeds as described in the previous sections. The definition of a 2D theory function works exactly the same way, use r[1] for the values of yi. The dimension of the user defined theory function (1D or 2D) is given by the data set used for the fit.
The derivatives needed for the least square refinement are calculated numerically in contrast to the usage of analytical derivatives used for the build in theory functions. In extreme cases the calculation of these derivatives and subsequently the fit itself might fail. In those cases it might be necessary to renormalize the observed values or to use a specialized fit package after all.