# Approximate Functions and Interpolation

In many kinds of numerical computations, it is convenient to introduce *approximate functions*. Approximate functions can be thought of as generalizations of ordinary approximate real numbers. While an approximate real number gives the value to a certain precision of a single numerical quantity, an approximate function gives the value to a certain precision of a quantity which depends on one or more parameters. The Wolfram Language uses approximate functions, for example, to represent numerical solutions to differential equations obtained with NDSolve, as discussed in "Numerical Differential Equations".

Approximate functions in the Wolfram Language are represented by InterpolatingFunction objects. These objects work like the pure functions discussed in "Pure Functions". The basic idea is that when given a particular argument, an InterpolatingFunction object finds the approximate function value that corresponds to that argument.

The InterpolatingFunction object contains a representation of the approximate function based on interpolation. Typically it contains values and possibly derivatives at a sequence of points. It effectively assumes that the function varies smoothly between these points. As a result, when you ask for the value of the function with a particular argument, the InterpolatingFunction object can interpolate to find an approximation to the value you want.

Interpolation[{f_{1},f_{2},…}] | construct an approximate function with values at successive integers |

Interpolation[{{x_{1},f_{1}},{x_{2},f_{2}},…}] | |

construct an approximate function with values at points |

Constructing approximate functions.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

You can work with approximate functions much as you would with any other Wolfram Language functions. You can plot approximate functions, or perform numerical operations such as integration or root finding.

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

If you differentiate an approximate function, the Wolfram Language will return another approximate function that represents the derivative.

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

InterpolatingFunction objects contain all the information the Wolfram Language needs about approximate functions. In standard Wolfram Language output format, however, only the part that gives the domain of the InterpolatingFunction object is printed explicitly. The lists of actual parameters used in the InterpolatingFunction object are shown only in iconic form.

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

The more information you give about the function you are trying to approximate, the better the approximation the Wolfram Language constructs can be. You can, for example, specify not only values of the function at a sequence of points, but also derivatives.

Interpolation[{{{x_{1}},f_{1},df_{1},ddf_{1},…},…}] | |

construct an approximate function with specified derivatives at points |

Constructing approximate functions with specified derivatives.

In[14]:= |

Out[14]= |

In[15]:= |

Out[15]= |

Interpolation works by fitting polynomial curves between the points you specify. You can use the option InterpolationOrder to specify the degree of these polynomial curves. The default setting is InterpolationOrder->3, yielding cubic curves.

In[16]:= |

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

In[19]:= |

Out[19]= |

Increasing the setting for InterpolationOrder typically leads to smoother approximate functions. However, if you increase the setting too much, spurious wiggles may develop.

ListInterpolation[{{f_{11},f_{12},…},{f_{21},…},…}] | |

construct an approximate function from a two‐dimensional grid of values at integer points | |

ListInterpolation[list,{{x_{min},x_{max}},{y_{min},y_{max}}}] | |

assume the values are from an evenly spaced grid with the specified domain | |

ListInterpolation[list,{{x_{1},x_{2},…},{y_{1},y_{2},…}}] | |

assume the values are from a grid with the specified grid lines |

Interpolating multidimensional arrays of data.

In[20]:= |

Out[20]= |

In[21]:= |

Out[21]= |

In[22]:= |

In[23]:= |

Out[23]= |

ListInterpolation works for arrays of any dimension, and in each case it produces an InterpolatingFunction object which takes the appropriate number of arguments.

In[24]:= |

Out[24]= |

In[25]:= |

Out[25]= |

The Wolfram Language can handle not only purely numerical approximate functions, but also ones which involve symbolic parameters.

In[26]:= |

In[27]:= |

Out[27]= |

In[28]:= |

Out[28]= |

In working with approximate functions, you can quite often end up with complicated combinations of InterpolatingFunction objects. You can always tell the Wolfram Language to produce a single InterpolatingFunction object valid over a particular domain by using FunctionInterpolation.

In[29]:= |

Out[29]= |

In[30]:= |

Out[30]= |

In[31]:= |

Out[31]= |

FunctionInterpolation[expr,{x,x_{min},x_{max}}] | |

construct an approximate function by evaluating expr with x ranging from to | |

FunctionInterpolation[expr,{x,x_{min},x_{max}},{y,y_{min},y_{max}},…] | |

construct a higher‐dimensional approximate function |

Constructing approximate functions by evaluating expressions.