## 3.8.2 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. Mathematica uses approximate functions, for example, to represent numerical solutions to differential equations obtained with NDSolve, as discussed in Section 1.6.4.
Approximate functions in Mathematica are represented by InterpolatingFunction objects. These objects work like the pure functions discussed in Section 2.2.5. 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.

Constructing approximate functions.

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

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

InterpolatingFunction objects contain all the information Mathematica needs about approximate functions. In standard Mathematica 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.

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

Constructing approximate functions with specified derivatives.

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.

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

Interpolating multidimensional arrays of data.

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

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

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

Constructing approximate functions by evaluating expressions.