in

.NET Opensource

Community for opensource projects by Christoph Rüegg

interpolation method question (beginner)

Last post 05-21-2009 13:52 by Christoph Rüegg. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-26-2009 18:18

    interpolation method question (beginner)

    I came across Math.NET when searching for a simple linear interpolator in c#.  It seems an elegant and useful solution,  I would like to use it, but have a small problem, perhaps somebody can help.

    I have an application in which I need to do 1-d interpolation with an unknown number of points, between 3 and 7, the number will vary.

    The default method (barycentric) seems to fail with only 3 points.


                double[ values = new double[ { 6.0, 12.0, 16.0 };
                double[ points = new double[ { 1.0, 2.0, 3.0 };
                IInterpolationMethod method = Interpolation.Create(points,values); // t, x);
                IInterpolationMethod method2 = Interpolation.CreatePolynomial(points, values);

                double a = method.Interpolate(2.5);

                double b = method2.Interpolate(2.5);

     a gives NaN, b gives 14.25

     CreatePolynomial works, but I would prefer linear interpolation between the closest points, to return value of 14.0.  I do not see an obvious linear interpolation example.  Can anyone advise me as to the best approach for using Math.Net with only 3 values, advise as to what would come closest to linear interpolation, and point me to a relatively simple explanation of the various  interpolants that are supported.

     Thanks in advance.

     Richard Males

    Cincinnati, OH USA

    Filed under:
  • 03-12-2009 19:48 In reply to

    Re: interpolation method question (beginner)

    Thanks for reporting, there is indeed an issue with barycentric interpolation when the number of provided samples are exactly equal to the interpolation order (3 in this case).

    Luckily, since what you really want is linear interpolation, you should use CreateLinearSpline instead, which works fine for your 3 samples and does indeed return 14.0 at 2.5.

  • 03-12-2009 21:47 In reply to

    Re: interpolation method question (beginner)

    Thank you for the response, I discovered and have been using the CreateLinearSpline successfully.

  • 05-21-2009 13:52 In reply to

    Re: interpolation method question (beginner)

    FYI, the mentioned bug IRID-209 about rational pole-free interpolation with exactly 3 samples has just been fixed (commit aa15bf1291a710b21c7b24ec307789e80494deba).
Page 1 of 1 (4 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems