forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 9:33 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Spline 2D
PostPosted: Sun Sep 05, 2010 8:02 pm 
Offline

Joined: Sun Sep 05, 2010 7:58 pm
Posts: 2
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?


Top
 Profile  
 
 Post subject: Re: Spline 2D
PostPosted: Mon Sep 06, 2010 7:30 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: Spline 2D
PostPosted: Mon Sep 06, 2010 11:06 am 
Offline

Joined: Sun Sep 05, 2010 7:58 pm
Posts: 2
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group