Function Repository Resource:

GeneralizedAkimaInterpolation

Source Notebook

Interpolate data using Akima's method or modifications of it

Contributed by: Jan Mangaldan

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

constructs a cubic Hermite interpolation of the function values fi, assumed to correspond to x values 1, 2, …, using Akima's method.

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

constructs a cubic Hermite interpolation of the function values fi corresponding to x values xi using Akima's method.

Details and Options

ResourceFunction["GeneralizedAkimaInterpolation"] returns an InterpolatingFunction object, which can be used like any other pure function.
The interpolation function returned by ResourceFunction["GeneralizedAkimaInterpolation"][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.
ResourceFunction["GeneralizedAkimaInterpolation"][data] generates an InterpolatingFunction object that returns values with the same precision as those in data.
ResourceFunction["GeneralizedAkimaInterpolation"] takes the following options:
MethodAutomaticmethod to use
PeriodicInterpolationFalsewhether to treat the data as periodic
Possible settings for the Method option include:
"AkimaClassic"classical Akima method (1970)
"AkimaNew"new Akima method (1991)
"ModifiedAkima"Ionita's modification of Akima's method
With the setting PeriodicInterpolationTrue, only the data for a single fundamental period are required.

Examples

Basic Examples (3) 

Construct an approximate function that interpolates the data:

In[1]:=
f = ResourceFunction[
  "GeneralizedAkimaInterpolation"][{0., 0.6, 1., 1.3, 1.4, 2.1}]
Out[1]=

Apply the function to find interpolated values:

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

Plot the interpolation function along with the original data:

In[3]:=
Show[Plot[f[x], {x, 1, 6}], ListPlot[{0., 0.6, 1., 1.3, 1.4, 2.1}]]
Out[3]=

Scope (2) 

Interpolate between points at arbitrary x values:

In[4]:=
data = {{0., 0.}, {0.1, 0.3}, {0.5, 0.6}, {1., -0.2}, {2., 3.}};
fun = ResourceFunction["GeneralizedAkimaInterpolation"][data];
In[5]:=
Plot[fun[x], {x, 0, 2}, Epilog -> {Directive[AbsolutePointSize[5], ColorData[97, 4]], Point[data]}]
Out[5]=

Form an interpolation from data given as a TimeSeries:

In[6]:=
ts = TemporalData[
  TimeSeries, {{{1, Cos[1] + Sin[1], Cos[2] + Sin[2], Cos[3] + Sin[3],
       Cos[4] + Sin[4], Cos[5] + Sin[5], Cos[6] + Sin[6], Cos[7] + Sin[7], Cos[8] + Sin[8], Cos[9] + Sin[9], Cos[10] + Sin[10]}}, {{{0.016965744360214943`, 0.9973865299845299, 1.24591736467102, 1.8114088692820352`, 1.9107450982712126`, 3.013995043949912, 3.323754146542503, 4.551557869716615, 5.13709169763333, 5.334143602077121, 5.441221219515277}}}, 1, {"Continuous", 1}, {"Discrete", 1}, 1, {ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}},
    False, 10.1];
In[7]:=
ListPlot[ts, Filling -> Axis]
Out[7]=
In[8]:=
fun = ResourceFunction["GeneralizedAkimaInterpolation"][ts]
Out[8]=
In[9]:=
Plot[fun[x], {x, ts["FirstTime"], ts["LastTime"]}]
Out[9]=

Options (2) 

Method (1) 

Compare different versions of Akima interpolation:

In[10]:=
data = {{0., 0.}, {1., 0.}, {2., 0.}, {3., 0.}, {4., 0.}, {5., 1.}, {6., 10.}, {7., 80.}, {8., 100.}, {9., 150.}};
In[11]:=
f1970 = ResourceFunction["GeneralizedAkimaInterpolation"][data, Method -> "AkimaClassic"];
f1991 = ResourceFunction["GeneralizedAkimaInterpolation"][data, Method -> "AkimaNew"];
fMod = ResourceFunction["GeneralizedAkimaInterpolation"][data, Method -> "ModifiedAkima"];
In[12]:=
Plot[{f1970[x], f1991[x], fMod[x]}, {x, 0, 9}, PlotLegends -> {"Classic (1970)", "New (1991)", "Modified"}]
Out[12]=

PeriodicInterpolation (1) 

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

In[13]:=
fp = ResourceFunction[
  "GeneralizedAkimaInterpolation"][{1, 5, 7, 2, 3, 1}, PeriodicInterpolation -> True]
Out[13]=
In[14]:=
Plot[fp[x], {x, -12, 18}, {Axes -> None, Frame -> True}]
Out[14]=

Properties and Relations (2) 

Setting Method"AkimaClassic" in GeneralizedAkimaInterpolation gives results equivalent to the one from the resource function AkimaInterpolation:

In[15]:=
data = {{1., 0.}, {2., 0.}, {3., 0.}, {4., 0.5}, {5., 0.4}, {5.5, 1.2}, {7., 1.2}, {8., 0.1}, {9., 0.}, {9.5, 0.3}, {10., 0.6}};
f1 = ResourceFunction["AkimaInterpolation"][data];
f2 = ResourceFunction["GeneralizedAkimaInterpolation"][data, Method -> "AkimaClassic"];
In[16]:=
Plot[{f1[x], f2[x]}, {x, 1, 10}, Epilog -> {Directive[AbsolutePointSize[6], ColorData[97, 4]], Point[data]}, PlotStyle -> {Thick, Directive[Thick, Dashed]}]
Out[16]=

The interpolant returned by GeneralizedAkimaInterpolation is continuous up to its first derivative:

In[17]:=
data = {{1., 1.}, {2., 1.8}, {3., 5.}, {3.006, 5.0001}, {5., 7.}, {6.,
     10.}, {7., 10.}};
fun = ResourceFunction["GeneralizedAkimaInterpolation"][data];
In[18]:=
Plot[{fun[x], fun'[x], fun''[x]}, {x, 1, 7}, PlotLegends -> {"f", "f'", "f''"}, PlotRange -> {-15, 15}]
Out[18]=

Version History

  • 1.0.0 – 12 July 2021

Source Metadata

Related Resources

License Information