Function Repository Resource:

PolyharmonicSplineInterpolation

Source Notebook

Interpolate data using polyharmonic splines

Contributed by: Jan Mangaldan

ResourceFunction["PolyharmonicSplineInterpolation"][{f1,f2,}]

constructs a polyharmonic spline interpolation of the function values fi, assumed to correspond to x values 1, 2, ….

ResourceFunction["PolyharmonicSplineInterpolation"][{{x1,f1},{x2,f2},}]

constructs a polyharmonic spline interpolation of the function values fi corresponding to x values xi.

ResourceFunction["PolyharmonicSplineInterpolation"][{{{x1,y1,},f1},{{x2,y2,},f2},}]

constructs a polyharmonic spline interpolation of multidimensional data.

Details and Options

ResourceFunction["PolyharmonicSplineInterpolation"] returns a Listable pure function by default.
The pure function returned by ResourceFunction["PolyharmonicSplineInterpolation"][data] is set up so as to agree with data at every point explicitly specified in data.
The function values fi can be real or complex numbers.
The fi can be lists or arrays of any dimension.
The function arguments xi, yi, etc. must be real numbers.
ResourceFunction["PolyharmonicSplineInterpolation"] creates a polyharmonic interpolation by performing a radial basis function interpolation over the given data points, using polyharmonic radial basis functions and linear polynomial terms.
The order of the polyharmonic radial basis functions is specified by the option InterpolationOrder.
The default setting is InterpolationOrder2, corresponding to a thin plate spline.
A polyharmonic radial basis function of order k is given by φ(r)=rklog r if k is even, and φ(r)=rk if k is odd, where r is EuclideanDistance[{x,y,},{x1,y1,}].
ResourceFunction["PolyharmonicSplineInterpolation"] supports a Compiled option. Setting CompiledTrue makes ResourceFunction["PolyharmonicSplineInterpolation"] return a listable compiled function.

Examples

Basic Examples (4) 

Construct an approximate function that interpolates the data:

In[1]:=
f = ResourceFunction[
   "PolyharmonicSplineInterpolation"][{1., 2., 3., 5., 8., 5.}];

Apply the function to find interpolated values:

In[2]:=
f[2.5]
Out[2]=

Plot the interpolation function:

In[3]:=
Plot[f[x], {x, 1, 6}]
Out[3]=

Compare with the original data:

In[4]:=
Show[%, ListPlot[{1, 2, 3, 5, 8, 5}]]
Out[4]=

Scope (6) 

Interpolate between points at arbitrary x-values:

In[5]:=
f = ResourceFunction[
   "PolyharmonicSplineInterpolation"][{{1., 4.2}, {2., 9.3}, {4., 7.1}, {5., 4.3}, {8., 5.7}, {9., 10.2}, {10., 10.6}, {12., 7.2}}];
Plot[f[x], {x, 1, 12}]
Out[5]=

Create a list of multidimensional data:

In[6]:=
Flatten[Table[N@{{x, y}, LCM[x, y]}, {x, 4}, {y, 4}], 1]
Out[6]=

Create a compiled interpolating function:

In[7]:=
f = ResourceFunction["PolyharmonicSplineInterpolation"][%, Compiled -> True];

Plot the interpolating function:

In[8]:=
ContourPlot[f[x, y], {x, 1, 4}, {y, 1, 4}]
Out[8]=

Interpolate complex values:

In[9]:=
f = ResourceFunction[
   "PolyharmonicSplineInterpolation"][{1 + I, 2., 3. - .5 I, 7. I, 6. - 10. I}];

Plot it:

In[10]:=
Plot[{Re[f[x]], Im[f[x]]}, {x, 1, 6}]
Out[10]=

Create a list of scattered data:

In[11]:=
data = {{{875, 3375}, 632}, {{500, 4000}, 634}, {{2250, 1250}, 654.2}, {{3000, 875}, 646.4}, {{2560, 1187}, 641.5}, {{1000, 750},
     650}, {{2060, 1560}, 634}, {{3000, 1750}, 643.3}, {{2750, 2560}, 639.4}, {{1125, 2500}, 630.1}, {{875, 3125}, 638}, {{1000, 3375}, 632.3}, {{1060, 3500}, 630.8}, {{1250, 3625}, 635.8}, {{750, 3375}, 625.6}, {{560, 4125}, 632}, {{185, 3625}, 624.2}};

Create a compiled interpolating function:

In[12]:=
f = ResourceFunction["PolyharmonicSplineInterpolation"][data, Compiled -> True];

Plot the interpolating function:

In[13]:=
ContourPlot[f[x, y], {x, 0, 3500}, {y, 500, 4500}]
Out[13]=

Create a vector-valued function of one variable from vector-valued data:

In[14]:=
data = {{{0.}, {1., 2.}}, {{1.2}, {3., 4.}}, {{2.1}, {5., 4.}}, {{3.}, {0., 4.}}};
fun = ResourceFunction["PolyharmonicSplineInterpolation"][data];

The value is a vector:

In[15]:=
fun[1.5]
Out[15]=

Plot both components:

In[16]:=
Plot[fun[t], {t, 0, 3}]
Out[16]=

Create a vector-valued function of two variables from vector-valued data:

In[17]:=
data = Flatten[
   Table[{{x, y}, {x Sin[\[Pi] y], y Cos[\[Pi] x], Tan[\[Pi] x y]}}, {x, 0, 1, .2}, {y, 0, 1, .2}], 1];
fun = ResourceFunction["PolyharmonicSplineInterpolation"][data];

The value is a vector:

In[18]:=
fun[.5, .5]
Out[18]=

Plot3D will show all three components:

In[19]:=
Plot3D[fun[x, y], {x, 0, 1}, {y, 0, 1}]
Out[19]=

A single component may be plotted using Indexed:

In[20]:=
DensityPlot[Indexed[fun[x, y], 3], {x, 0, 1}, {y, 0, 1}, Exclusions -> None]
Out[20]=

Options (3) 

Compiled (2) 

Use CompiledTrue to generate a compiled function from machine precision data:

In[21]:=
fC = ResourceFunction[
  "PolyharmonicSplineInterpolation"][{1., 2., 3., 5., 8., 5.}, Compiled -> True]
Out[21]=

A compiled function evaluates more quickly than an uncompiled one:

In[22]:=
fC[2.5] // RepeatedTiming
Out[22]=
In[23]:=
fU = ResourceFunction[
   "PolyharmonicSplineInterpolation"][{1., 2., 3., 5., 8., 5.}, Compiled -> False];
fU[2.5] // RepeatedTiming
Out[23]=

CompiledFalse is appropriate for data with arbitrary precision:

In[24]:=
f = ResourceFunction["PolyharmonicSplineInterpolation"][
   N[{{0, 0}, {1/10, 3/10}, {1/2, 3/5}, {1, -1/5}, {2, 3}}, 25], Compiled -> False];
f[3/2]
Out[24]=

InterpolationOrder (1) 

Compare interpolating functions of different orders:

In[25]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/6e1ca173-f435-40bf-9934-36b33666b234"]
Out[25]=

Properties and Relations (1) 

The interpolating function always goes through the data points:

In[26]:=
data = {1, 2, 3, 5, 8, 5};
f = ResourceFunction["PolyharmonicSplineInterpolation"][data];
Show[ListPlot[data], Plot[f[x], {x, 1, 6}]]
Out[26]=

Version History

  • 1.0.0 – 19 January 2021

Source Metadata

Related Resources

License Information