I'm using the following method:
IInterpolation ii = MathNet.Numerics.Interpolation.Interpolate.RationalWithoutPoles(points, values);
It seems to work when I'm passing in lists that are less than about 700 items, but fails when I'm using lists that are greater than about 800 items. I'm trying to interpolate an elevation when given a volume.
The attached text file has the raw data (861 items) Ignore the first two columns. The third is the elevation and forth is the volume. When using this data I'm getting either negative values or values that exceed the maximum elevation in the set. If I reduce the same set, by not including the first 200 items, it provides what appears to be a reasonable answer.
Thanks
Comments: Some more notes, related more to your problem than the reported issue itself: Note that an interpolation to a rational function of order >800 is somewhat brutal (school-book approaches like a neville polynomial would utterly fail here, even more as the samples are equidistant); you may want to consider a spline interpolation instead: ``` var ii = new CubicSplineInterpolation(x,y); ``` Looking at the actual curve it seems a rational curve of order 3-4 should represent the data quite well. Do you really need an interpolation, or would a regression (see http://christoph.ruegg.name/blog/2012/9/9/linear-regression-mathnet-numerics.html) e.g. to a polynomial function of order 3-6 do the job as well? Alternatively, interpolating over a small subset of e.g. 5 samples (of the provided 800) could work as well, e.g. like this: ``` var n = 5; var chebyshevNodes = Enumerable.Range(1,n) .Select(i => Math.Cos((2*i-1)*Math.PI/(2*n))) .Select(z => (int)Math.Round((z+1)*(x.Length-1)/2)) .Concat(new[] {0,x.Length-1}) .OrderBy(k => k); var ii = Interpolate.RationalWithoutPoles( chebyshevNodes.Select(k => x[k]).ToArray(), chebyshevNodes.Select(k => y[k]).ToArray()); ```
IInterpolation ii = MathNet.Numerics.Interpolation.Interpolate.RationalWithoutPoles(points, values);
It seems to work when I'm passing in lists that are less than about 700 items, but fails when I'm using lists that are greater than about 800 items. I'm trying to interpolate an elevation when given a volume.
The attached text file has the raw data (861 items) Ignore the first two columns. The third is the elevation and forth is the volume. When using this data I'm getting either negative values or values that exceed the maximum elevation in the set. If I reduce the same set, by not including the first 200 items, it provides what appears to be a reasonable answer.
Thanks
Comments: Some more notes, related more to your problem than the reported issue itself: Note that an interpolation to a rational function of order >800 is somewhat brutal (school-book approaches like a neville polynomial would utterly fail here, even more as the samples are equidistant); you may want to consider a spline interpolation instead: ``` var ii = new CubicSplineInterpolation(x,y); ``` Looking at the actual curve it seems a rational curve of order 3-4 should represent the data quite well. Do you really need an interpolation, or would a regression (see http://christoph.ruegg.name/blog/2012/9/9/linear-regression-mathnet-numerics.html) e.g. to a polynomial function of order 3-6 do the job as well? Alternatively, interpolating over a small subset of e.g. 5 samples (of the provided 800) could work as well, e.g. like this: ``` var n = 5; var chebyshevNodes = Enumerable.Range(1,n) .Select(i => Math.Cos((2*i-1)*Math.PI/(2*n))) .Select(z => (int)Math.Round((z+1)*(x.Length-1)/2)) .Concat(new[] {0,x.Length-1}) .OrderBy(k => k); var ii = Interpolate.RationalWithoutPoles( chebyshevNodes.Select(k => x[k]).ToArray(), chebyshevNodes.Select(k => y[k]).ToArray()); ```