Re: 2D interpolation

• To: mathgroup at smc.vnet.net
• Subject: [mg72924] Re: 2D interpolation
• From: Bill Rowe <readnewsciv at sbcglobal.net>
• Date: Thu, 25 Jan 2007 07:11:30 -0500 (EST)

```On 1/24/07 at 5:33 PM, F.Jouvenot at liverpool.ac.uk (Jouvenot, Fabrice)
wrote:

>I am asking (again) for your knowledge to help me. I try to have a 2
>dimensional interpolation of points {x, y, f(x,y)}. After some try,
>I wrote these lines (as an exemple of what I want to do) that works
>: ________________________________________
>
>data = {{1, 1, -10}, {1, 2, 2}, {1, 3, 3}, {1, 4, 4}, {1, 5, 5}, {2,
>1, 2}, {2, 2, 4}, {2, 3, 6}, {2, 4, 8}, {2, 5, 10}, {3., 1, -9}, {3,
>2, 6}, {3, 3, 90}, {3, 4, 12}, {3, 5, 15}, {4, 1, 4}, {4, 2, 8}, {4,
>3, 12}, {4, 4, 16}, {4, 5, 20}, {5, 1, 5}, {5, 2, 10}, {5, 3, 15},
>{5, 4, 20}, {5, 5, 40.5}};

>MatrixForm[data]

>test[x_, y_] := Interpolation[data][x, y];

>test[1.5, 1.5]

While this clearly gives you the result you are looking for this
is a very poor way to define your function. This definition will
cause Mathematica to re-compute the interpolation function
everytime it is called. That means there will be a lot more
computation than you need. A better approach would be:

In[13]:=
f=Interpolation[data];

In[14]:=
f[1.5,1.5]

Out[14]=
10.2578

Using this approach, the interpolation function is computed only once.

>Plot[test[x, 1], {x, 1, 5}];

>Plot[test[x, x], {x, 1, 5}];

Neither of the above will work since Plot will not provide both
arguments needed to define a numeric value for your function.

>Plot3D[test[x, y], {x, 1, 5}, {y, 1, 5}];

This should work albeit slowly due to the excessive computations
required as described above.

When I define the function as I've indicated above, Mathematica
returns a surface plot in about 0.04 seconds.
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: pdf
• Next by Date: Re: 2D interpolation
• Previous by thread: Re: 2D interpolation
• Next by thread: RE: Re: 2D interpolation