forum.alglib.net
http://forum.alglib.net/

Spline 2D
http://forum.alglib.net/viewtopic.php?f=2&t=55
Page 1 of 1

Author:  sajmon44 [ Sun Sep 05, 2010 8:02 pm ]
Post subject:  Spline 2D

Hi,

i would like use 2d interpolation, for example:

Code:
spline2d.spline2dinterpolant s = new spline2d.spline2dinterpolant();
List<double> x = new List<double>();
List<double> y = new List<double>();
double[,] f = new double[5, 5];

for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++)
    {
        x.Add(j);
        y.Add(i);
        f[i, j] = 0;
    }

spline2d.spline2dbuildbicubic(x.ToArray(), y.ToArray(), f, 5, 5, ref s);

Console.WriteLine(spline2d.spline2dcalc(ref s, 0.4, 0.2)); //this produce "NaN"


but i receive "NaN". Someone can help? what I did wrong?

Author:  Sergey.Bochkanov [ Mon Sep 06, 2010 7:30 am ]
Post subject:  Re: Spline 2D

There is an error in your program. You initialize x and y within inner cycle, so instead of x=y=[0,1,2,3,4] you get x=[0,1,2,3,4,0,1,2,3,4,5,...,3,4] and y=[0,0,0,0,0,1,1,1,1,1,...,4,4,4]. spline2dbuildbicubic() uses only 5 leading elements of x/y, so your code is equivalent to using x=[0,1,2,3,4], y=[0,0,0,0,0]. Of course, with non-distinct nodes, you can't get meaningful result.

Author:  sajmon44 [ Mon Sep 06, 2010 11:06 am ]
Post subject:  Re: Spline 2D

Sergey.Bochkanov wrote:
There is an error in your program. You initialize x and y within inner cycle, so instead of x=y=[0,1,2,3,4] you get x=[0,1,2,3,4,0,1,2,3,4,5,...,3,4] and y=[0,0,0,0,0,1,1,1,1,1,...,4,4,4]. spline2dbuildbicubic() uses only 5 leading elements of x/y, so your code is equivalent to using x=[0,1,2,3,4], y=[0,0,0,0,0]. Of course, with non-distinct nodes, you can't get meaningful result.


Very sorry for my misuderstand. I thought that vector x, and y should contains coordinates for every 25 nodes.
Vectors x, y define a grid, so my exaple should be:

spline2d.spline2dbuildbicubic(new double[] { 0, 1, 2, 3, 4 }, new double[] { 0, 1, 2, 3, 4}, f, 5, 5, ref s);
and matrix f should contains 25 z-values for every nodes.

Now it works perfect.
Thank you for help!

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/