Function Repository Resource:

AkimaInterpolation

Source Notebook

Interpolation and smooth curve fitting based on local procedures

Contributed by: Robert B. Nachbar (Wolfram Solutions)

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

constructs an interpolation of the function values fi, assumed to correspond to x values of 1,2,, using Akima’s method.

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

constructs an interpolation of the function values fi corresponding to x values xi.

Details and Options

ResourceFunction["AkimaInterpolation"] returns an InterpolatingFunction object, which can be used like any other pure function.
The interpolation function returned by ResourceFunction["AkimaInterpolation"][data] is set up so as to agree with data at every point explicitly specified in data.
The function values fi are expected to be real or complex numbers.
The function arguments xi must be real numbers.
The interpolation works by fitting a third-degree polynomial curve between successive data points.
The interpolation automatically makes use of local numerical derivatives.
If the data is periodic, only the data for a single fundamental period are required. The option PeriodicInterpolation is used.

Examples

Basic Examples (4) 

Construct an approximate function that interpolates the data:

In[1]:=
data = {1, 2, 3, 5, 8, 5};
f = ResourceFunction["AkimaInterpolation"][data]
Out[2]=

Apply the function to find interpolated values:

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

Plot the interpolation function:

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

Compare with the original data:

In[5]:=
Show[p, ListPlot[data, PlotStyle -> {PointSize[Large], Red}]]
Out[5]=

Scope (1) 

Interpolate between points at arbitrary x-values:

In[6]:=
ResourceFunction[
 "AkimaInterpolation"][{{0, 0}, {0.1, .3}, {0.5, .6}, {1, -.2}, {2, 3}}]
Out[6]=
In[7]:=
Plot[%[x], {x, 0, 2}]
Out[7]=

Options (2) 

PeriodicInterpolation (2) 

With PeriodicInterpolationTrue, the data are interpreted as one period of a periodic function:

In[8]:=
data = {1, 5, 7, 2, 3, 1};
fp = ResourceFunction["AkimaInterpolation"][data, PeriodicInterpolation -> True]
Out[9]=

Periodic interpolation can be used outside the range of the data:

In[10]:=
Show[Plot[fp[x], {x, -12, 18}], ListPlot[data, PlotStyle -> {PointSize[Large], Red}]]
Out[10]=

Applications (1) 

Interpolate random data:

In[11]:=
f = ResourceFunction["AkimaInterpolation"][r = RandomReal[1, 20]]
Out[11]=
In[12]:=
Show[ListPlot[r, PlotStyle -> {PointSize[Large], Red}], Plot[f[x], {x, 1, 20}]]
Out[12]=

Properties and Relations (2) 

Compare the output from AkimaInterpolation to that from Interpolation:

In[13]:=
data = {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 1}, {6, 10}, {7, 80}, {8, 100}, {9, 150}};
afun = ResourceFunction["AkimaInterpolation"][data];
ifun = Interpolation[data];
sfun = Interpolation[data, Method -> Spline];
Plot[{ifun[x], afun[x], sfun[x]}, {x, 0, 9}, Epilog -> {Red, PointSize[0.02], Point[data]}, PlotLegends -> {"Akima", "Hermite", "Spline"}, AspectRatio -> 1]
Out[14]=

Examine the region between 4 and 6:

In[15]:=
Plot[{afun[x], ifun[x], sfun[x]}, {x, 4, 6}, Epilog -> {Red, PointSize[0.02], Point[data]}, PlotLegends -> {"Akima", "Hermite", "Spline"}, AspectRatio -> 1]
Out[15]=

Possible Issues (3) 

Extrapolation is attempted to go beyond the original data:

In[16]:=
f = ResourceFunction["AkimaInterpolation"][{1, 2, 4, -2, 1}]
Out[16]=
In[17]:=
Table[f[i], {i, 0, 6}]
Out[17]=

At least 2 points are needed:

In[18]:=
ResourceFunction["AkimaInterpolation"][{1}]
Out[18]=
In[19]:=
ResourceFunction["AkimaInterpolation"][{1, 2}]
Out[19]=

The interpolation function will always be continuous and first-order differentiable, but may not be higher-order differentiable:

In[20]:=
f = ResourceFunction["AkimaInterpolation"][r = RandomReal[1, 10]]
Out[20]=
In[21]:=
Show[Plot[Evaluate[{f[x], D[f[x], x], D[f[x], {x, 2}]}], {x, 1, 10}, PlotLegends -> {\[ScriptF], Derivative[1][\[ScriptF]][x], (\[ScriptF]^\[Prime]\[Prime])[x]}], ListPlot[r, PlotStyle -> {PointSize[Large], Red}]]
Out[21]=

Neat Examples (2) 

Excessive undulation is suppressed:

In[22]:=
data = {3, 10, 3, 10, 6};
afun = ResourceFunction["AkimaInterpolation"][data];
ifun = Interpolation[data];
sfun = Interpolation[data, Method -> "Spline"];
Plot[{afun[x], ifun[x], sfun[x]}, {x, 1, 5}, Epilog -> {Red, PointSize[0.02], Point[Thread[{Range[5], data}]]}, PlotLegends -> {"Akima", "Hermite", "Spline"}]
Out[23]=

Reasonable extrapolation is permitted:

In[24]:=
data = {{1, 3}, {2, 3/2}, {3, 1}, {4, 7/2}, {5, 5}};
afun = ResourceFunction["AkimaInterpolation"][data];
ifun = Interpolation[data];
sfun = Interpolation[data, Method -> "Spline"];
Plot[{afun[x], ifun[x], sfun[x]}, {x, 0, 6}, Epilog -> {Red, PointSize[0.02], Point[data]}, PlotLegends -> {"Akima", "Hermite", "Spline"}]
Out[28]=

Publisher

Robert Nachbar

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.1 – 24 January 2024
  • 1.0.0 – 09 January 2019

Source Metadata

Related Resources

License Information