You are on page 1of 2

Interpolating Tabular Data with Mathcad

We are frequently required to interpolate tabular data; for example, the VLE data in HWK #4 was
given in tabular form. Another example is need to interpolate the steam table. One (old fashioned)
method of interpolation is to plot the data and draw a smooth curve through the points. Less
accurate is to linearly interpolate.
In this module, we will show how to make Mathcad do the interpolation for us. It turns out that
Mathcad can perform "cubic spline" interpolations to convert columns of x-y data into continuous
functions that can be used as y = f(x) or x = g(y)
As an example, we will take the tabular data from HWK #4, Prob. 4 and perform the cubic-spline
interpolation.

xs

f( x )

.1

.36

.3

.7

.5
.55

ys

.875
.9

.7

.95

.9

.989

The first step is to enter the columns of data. The end result is
shown at left. To get a column vector of placeholders to appear
after the ":=", just type Ctrl-M or use the Math/Matrices menu.
This brings up a dialog box where you can enter the number of
columns and rows (we used 1 column and 8 rows). We then
manually typed the numbers in each placeholder.

interp( pspline( xs , ys ) , xs , ys , x )

In this statement, we define a function f(x) that for a given


value of x, interpolates the table for the corresponding
value of y.

This definition uses two built-in Mathcad functions: "interp" and "pspline". In place of "pspline" you
might substitute "lspline" or "cspline". "pspline", "lspline" and "cspline" perform parabolic-, linear- or
cubic-spline interpolations, respectively. All of these functions are available (along with some
documentation) using the f(x) tool on the toolbar.

0.8

f( x ) 0.6
x
ys
i

0.4

0 .. last( ys )

0 , .02 .. 1
Here we have created a plot in which
our new f(x) function is used to
interpolate the tabular data (black
squares) at 0.02 intervals in x. The
interpolated values are plotted as red
+'s. Note that a nice smooth curve
connects the original tabular data.

0.2

0.2

0.4

0.6
x , x , xs
i

0.8