FunctionInterpolation

FunctionInterpolation[
expr
,
x
,
xmin
,
xmax
] evaluates expr with x running from xmin to xmax and constructs an InterpolatingFunction object which represents an approximate function corresponding to the result.

FunctionInterpolation[
expr
,
x
,
xmin
,
xmax
,
y
,
ymin
,
ymax
, ... ] constructs an InterpolatingFunction object with several arguments.

You can use FunctionInterpolation to generate a single InterpolatingFunction object from an expression containing several such objects.

The option InterpolationPrecision specifies the precision of values to be returned by the InterpolatingFunction generated.

See notes for Interpolation.

See the Mathematica book: Section 3.8.2.

See also: ListInterpolation, InterpolatingPolynomial, Table.

**Further Examples**

FunctionInterpolation can be used to simplify a combination of InterpolatingFunction objects. It can also be used to make an approximate function to a desired precision and accuracy goal from a function that is costly to evaluate.

Here is a function with argument t that gives the x value of the intersection of the graphs y
=
x and y
=
Cos[t
x].

In[1]:=

If it is necessary to compute it repeatedly, it is useful to construct a faster approximate function.

In[2]:=

Out[2]=

Now the approximation can be used without having to call FindRoot again, as in a plot, for example.

Evaluate the cell to see the graphic.

In[3]:=

There happens to be a solution for the equation in Mathematica.

In[4]:=

InverseFunction::ifun: Warning: Inverse functions are being used. Values may be lost for multivalued inverses.

Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found.

Out[4]=

The approximation was computed so that the default accuracy and precision goals ( digits) would be met if possible. Thie plot indicates that these goals were fairly well met.

Evaluate the cell to see the graphic.

In[5]:=

FunctionInterpolation provides an easy way to combine InterpolatingFunction objects with other functions to produce a new approximate function.

The function int is an InterpolatingFunction object that depends on the parameter .

In[6]:=

Out[6]=

The function fint is an InterpolatingFunction object that interpolates over a two-dimensional domain, with t varying over the domain of int and x positive.

In[7]:=

Out[7]=

Its values approximate the function.

In[8]:=

Out[8]=

The function int3 is a three-dimensional InterpolatingFunction object.

In[9]:=

Out[9]=

A "slice" can be taken along a complicated curve or surface.

Here is an InterpolatingFunction object that represents the values of int3 on the cone .

In[10]:=

Out[10]=

The "slice" can be taken along a more complicated curve or surface.

Here is another one that gives an InterpolatingFunction object that represents the values along a section of a helix.

In[11]:=

Out[11]=

This InterpolatingFunction object is an approximate solution to a differential equation.

In[12]:=

Out[12]=

Here is a plot of the function.

Evaluate the cell to see the graphic.

In[13]:=

Because the solution is growing so fast, NDSolve needs to use more points than are absolutely necessary for a good approximation. The solution given by NDSolve uses all the points where NDSolve evaluated the equation, so the size of the solution is large.

In[14]:=

Out[14]=

FunctionInterpolation can be used to eliminate points in a case like this.

In[15]:=

Out[15]=

The size of the solution has decreased dramatically.

In[16]:=

Out[16]=

Since the solution grows so quickly, the error controls for NDSolve and FunctionInterpolation are based on precision (relative error). The plot shows that the solution with fewer points stored does not have less precision overall than the solution with more points stored.

Evaluate the cell to see the graphic.

In[17]:=

Let's clean up by getting rid of the symbols defined in these examples.

In[18]:=