This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Built-in Functions / Numerical Computation / Data Manipulation /

Further Examples: Interpolation

Approximating Sqrt

Here is a table of values of the square root function at the points .

In[1]:=

Out[1]=

This constructs an approximate function that represents these 10 values on the domain .

In[2]:=

Out[2]=

The values of the function match the data at the given points.

In[3]:=

Out[3]=

The function sqrt1 also gives a fair approximation to the square root function at other points between and .

In[4]:=

Out[4]=

A plot of the difference between the two functions shows that the approximation is better at some points than at others.

In[5]:=

Here is another set of data that gives values of the square root function as well as its derivatives at the points .

In[6]:=

Out[6]=

Here is the corresponding interpolating function.

In[7]:=

Out[7]=

The values of this function likewise match the data at the given points.

In[8]:=

Out[8]=

Here is the plot of the difference between the square root function and sqrt2.

In[9]:=

This shows that in general sqrt2 gives a significantly better approximation to the square root function than sqrt1 does.

In[10]:=

Out[10]=

In[11]:=

Finding Closest Integers

This defines the function closestIntegers which returns the integers in list1 that are closest to those in list2.

In[12]:=

In[13]:=

Out[13]=

Periodic Interpolation

This creates an InterpolatingFunction object which repeats itself periodically. The data at the endpoints of the fundamental period must match: otherwise the function would not be periodic.

In[14]:=

In[15]:=

In more than one dimension, you can specify that some dimensions be repeated periodically and that others are not by giving the value of the option as a list. This sets up an InterpolatingFunction which will be periodic in the second dimension but not in the first.

In[16]:=

In[17]:=

In[18]:=

In[19]:=