Your attempt seems fine to me. The error is clear, have you tried sorting the data before passing to the Interpolator ? You can use std::sort or TMath::Sort
The problem is that in same case the interpolate points are NaN. This happens because you are using this spline for fitting. This will not work with a gradient method like Minuit because you cannot differentiate on the interpolate points (your fitting parameters).
Why are you fitting the graph with the interpolated function ? What are you trying to achieve ?
I understand the problem now @moneta and appreciate your explanation.
I am using a spline because it will require fewer parameters than a polynomial expansion to fit the curves that I am working with. The number of parameters has to be practical number since I intend to make them available to others.
Is there a simple work-around? The advantage of the Root interpolator is that I can choose various different splines (akima, cubic etc) where as with TSpline3, I am limited to one type.
What you can do in this case is to use a Minimizer algorithm for fitting that does not use the derivatives. For example using Simplex or simulated annealing from GSL
You need to add just this line before fitting:
You might also need to set bounds on the function parameter (i.e. the input data points) that they stay in the correct order, for example that x1 is guaranteed to be always less than x2.
Thanks @moneta Your suggestions seems to have allowed to code to compile without errors, but I can’t full yunderstand why I still get the messages: “Warning in ROOT::Math::GSLInterpolator::Eval: input domain error” and some other similar fits “ERROR: x values must be strictly increasing”.
If you look at the original data, “x” is already in increasing order such that “x1” is less than “x2”.
Hi,
Th problem is that when fitting x1 and x2 are parameters of your function and will vary. Then it is possible that x1 becomes larger than x2. I would limit them to vary between some defined range for example x1 should never become bigger than (x1_0+x2_0)/2 and x2 never smaller that this value, where x1_01 and x2_0 are the initial values of x1 and x2.