9101
9101
9101
3.1 Introduction
The Figure below illustrates a set of tabular data in the form of a set of [x, f(x)]
pairs. The function f(x) is known at a finite set (actually eight) of discrete values
of x. The value of the function can be determined at any of the eight values of x
simply by a table lookup. However, a problem arises when the value of the
function is needed at any value of x between the discrete values in the table. The
actual function is not known and cannot be determined form the tabular values.
However, the actual function can be approximated by some known function, and
the value of the approximating function can be determined at any desired value
of x. This process, which is called interpolation, is the subject of this Chapter.
The discrete data of the figure below are actually values of the
function f ( x) = 1 / x .
In many applications, the values of the discrete data at the specific points
are not all that is needed. Values of the function at points other than the known
discrete points may be needed (i.e. interpolation). The derivative of the function
may be required (i.e. differentiation). The integral of the function may be of
interest (i.e. integration). These processes are performed by fitting an
approximating function to the set of discrete data and performing the desired
process on the approximating function.
62
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
Many types of approximating functions exist. In fact, any analytical function can
be used as an approximating function. Three of the more common
approximating functions are:
1. Polynomials.
2. Trigonometric functions.
3. Exponential functions.
1. Exact fits.
2. Approximate fits.
An exact fit yields a polynomial that passes exactly through all of the discrete
points, as illustrated in the figure below. This type of fit is useful for small sets
of smooth data. An approximate fit yields a polynomial that passes through the
set of data in the best manner possible, without being required to pass exactly
through any of the data points. Approximate fits are useful for large sets of
smooth data and small or large sets of rough data.
63
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
f o = ao + a1 xo + a2 xo + .........+ an xo
2 n
....................................... (2. 0)
f1 = ao + a1 x1 + a2 x1 + .........+ an x1
2 n
....................................... (2.1)
..........................................................
f n = ao + a1 xn + a2 xn + .........+ an xn
2 n
....................................... (2. n)
x f(x)
3.35 0.298507
3.40 0.294118
3.50 0.285714
3.60 0.277778
64
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
Let's interpolate for y at x = 3.44 using linear, quadratic, and cubic interpolation.
The exact value is
1
y (3.44) = f (3.44) = = 0.290698...
3.44
P2 ( x) = a + b x + c x 2
To center data around x = 3.44, the first three points are used. Applying P2(x) at
each of these data points gives the following three equations:
For a linear polynomial, use x = 3.4 and 3.5 to center that data around
x = 3.44. The resulting linear polynomial is
P1 ( x) = 0.579854 − 0.0840400 x
65
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
For cubic polynomial, all four points must be used. The resulting cubic
polynomial is
The results are summarized below, where the results of linear, quadratic, and
cubic interpolation and the errors, Error(3.44) = pn (3.44) − 0.290698, are
tabulated. The advantages of higher-degree interpolation are obvious.
________________________________________________________________
The main advantage of direct fit polynomials is that the explicit form of the
approximating function is obtained, and the interpolation at several values of x
can be accomplished simply by evaluating the polynomial at each value of x.
The work required to obtain the polynomial does not have to be redone for each
value of x. A second advantage is that the data can be unequally spaced.
The main disadvantage of direct fit polynomials is that each time the degree
of the polynomial is changed, all of the work required to fit the new polynomial
must be redone.
66
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
Many problems arise in engineering and science when the dependant variable is
a function of two or more independent variables, for example, z = f(x.y) is a two
variable or bivariate, function. Such functions in general called multivariate
functions. When multivariate function is given by tabular data, multivariate
approximation is required for interpolation, differentiation, and integration.
Consider the bivariate function, z = f(x.y), and the set of tabular data presented
in the following table. The tabular data can be fit be a multivariate polynomial
of the form
The number of data points must equal the number of coefficients in the
polynomial. A linear bivariate polynomial in x and y is obtained by including the
first four terms in the equation. A quadratic bivariate polynomial in x and y is
obtained by including the first eight terms in the equation. The number of terms
in approximating polynomial increases rapidly as the degree of approximations
increases. This leads to ill-conditioned systems of linear equations for
determining the coefficients. Consequently, multivariate high-degree
approximation must be used with caution.
x
y 800 1000 1200
1150 1380.4 1500.2 1614.5
1200 1377.7 1499.0 1613.6
1250 1375.2 1497.1 1612.6
z = f ( x, y ) = a + bx + cy + dxy
67
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
Substituting the four data points that bracket x = 1100 and y = 1225 into the
polynomial gives
3.3.1 Introduction
An approximate fit yields a polynomial that passes through the set of points in
the best possible manner without being required to pass exactly through any of
the points. Several definitions of best possible manner exist. Consider the set of
discrete points, xi , Y ( xi ) = ( xi , Yi ) , and the approximate polynomial y(x)
chosen to represent the set of discrete points, as illustrated in the figure below.
The discrete points do not fall on the approximating polynomial. The deviations
(i.e. distances) of the points from the approximating function must be minimized
in some manner.
68
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
If the values of the independent variable xi are considered exact, then all the
deviation is assigned to the dependant variable Yi, and the deviation ei is the
vertical distance between Yi and yi=f(xi). Thus,
ei = Yi − yi
It is certainly possible that the values of Yi are quite accurate, but the
corresponding values of xi are in error. In that case, the deviation would be
measured by the horizontal distance illustrated in the above figure. If xi and Yi
both have uncertainties in their values, then the perpendicular distance between
a point and the approximating function would be the deviation. The usual
approach in the approximate fitting of tabular data is to assume that the
deviation is the vertical distance between a point and the approximating
function, as specified by the above equation.
Several best criteria are illustrated in the next figure for a straight line
approximation. From the figure we can see that the least squares criteria, in
which the sum of the squares of the deviations is minimized. The least squares
procedure yields a good compromise criterion for the best fit approximation.
69
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
The simplest polynomial is a linear polynomial, the straight lint. Least squares
straight line approximations are an extremely useful and common approximate
fit, which is determined as follows. Given N data points, (xi ,Yi), fit the best
straight line through the set data. The approximating function is
y = a + b x ............................................................ (1)
yi = a + b xi (i = 1, ............, N )
ei = Yi − yi (i = 1, ............, N )
The sum of the squares of the deviations defines the function S(a,b):
N N
S (a, b) = (ei ) = (Yi − a − bx i ) 2
2
i =1 i =1
S N
= 2 (Yi − a − bxi ) (−1) = 0
a i =1
......................... (2)
S N
= 2 (Yi − a − bxi ) (− xi ) = 0
b i =1
N N
a N + b xi = Yi
i =1 i =1
N N N
a xi + b xi = xi Yi
2
i =1 i =1 i =1
Which is called the normal equations of the least squares fit. They can be
solved for a and b by Gauss elimination.
70
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
i =1 i =1 i =1
Evaluating the summations and substituting into the above equations gives
8 a + 5200 b = 8.5331
5200 a + 3,800,000 b = 5632.74
Substituting the initial values of T into this equation gives the results presented
in the next table and figure, which presents the exact data, the least squares
straight line approximation, and the percent error. The straight line is not a very
good approximation of the data.
71
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
Given the N data points, (xi ,Yi), fit the best nth-degree polynomial through the
set of data. Consider the nth-degree polynomial:
y = ao + a1 x + a2 x 2 + .........+ an x n
N N
S (a0 , a1 ,..., an ) = (ei ) 2 = (Yi − ao − a1 xi − .... − an xi ) 2
n
i =1 i =1
S N
= 2 (Yi − ao − a1 xi − .... − a n xi ) (−1) = 0
n
ao i =1
..............................................................................
S N
= 2 (Yi − ao − a1 xi − .... − a n xi ) (− xi ) = 0
n n
a n i =1
N N N
ao N + a1 xi + .... + a n xi = Yi
n
i =1 i =1 i =1
.............................................................
N N N N
ao xi + a1 xi + .... + a n xi = xi Yi
n n +1 2n n
i =1 i =1 i =1 i =1
72
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
y = a + b x + c x2
For this problem the polynomial becomes
a N + b xi + c xi = Yi
2
a xi + b xi + c xi = xi Yi
2 3
a xi +b xi + c xi = xi Yi
2 3 4 2
N
x x i i
a Yi
2
3
xi x x i b = xi Yi
2
i
x 2 x x 3 4
xi 2 Yi
i i i c
5 10 10 3 22.5 10 6 a 6.1762
3
10 10 22.5 10 55 10 b = 12.5413 10
3 6 9
22.5 10 6 55 10 9 12
142.125 10 c 288.5186 10 6
Substituting the initial values of x into the approximating polynomial gives the
results presented in the next table and figure. The quadratic polynomial is
a reasonable approximation of the discrete data.
Y y
73
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
z = a + bx + cy
S
= 2 ( Z i − a − bx i − cyi ) (−1) = 0
a
S
= 2 ( Z i − a − bx i − cyi ) (− xi ) = 0
b
S
= 2 ( Z i − a − bx i − cyi ) (− yi ) = 0
b
N N N
a N + b xi + c y i = Z i
i =1 i =1 i =1
N N N N
a x i + b xi + c x i y i = x i Z i
2
i =1 i =1 i =1 i =1
N N N N
a y i + b xi y i + c y i = y i Z i
2
i =1 i =1 i =1 i =1
74
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
A linear fit to a set of bivariate data may be inadequate. Consider the quadratic
bivariate polynomial:
z = a + b x + c y + d x 2 + e y 2 + f xy
S
= 2 ( Z i − a − bx i − cyi − dxi − eyi − f xi yi ) (−1) = 0
2 2
a
...................................................................................
S
= 2 ( Z i − a − bx i − cyi − dxi − eyi − f xi yi ) (− xi yi ) = 0
2 2
f
a N + b xi + c y i + d xi + e y i + f xi y i = Z i
2 2
a xi + b xi + c xi yi + d xi + e xi yi + f xi yi = xi Z i
2 3 2 2
a y i + b xi y i + c y i + d xi y i + e y i + f xi y i = y i Z i
2 2 3 2
a xi + b xi + c xi yi + d xi + e xi yi + f xi yi = xi Z i
2 3 2 4 2 2 3 2
a yi + b xi yi + c yi + d xi yi + e yi + f xi yi = yi Z i
2 2 3 2 2 4 3 2
a xi yi + b xi yi + c xi yi + d xi yi + e xi yi + f xi yi = xi yi Z i
2 2 3 3 2 2
75
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
Solution: Consider the following values, use Least squares quadratic bivariate
polynomial to calculate z(x,y) = z(1100, 1225),
x
y 800 1000 1200
1150 1380.4 1500.2 1614.5
1200 1377.7 1499.0 1613.6
1250 1375.2 1497.1 1612.6
z = a + b x + c y + d x 2 + e y 2 + f xy
N x y x y x y a
i
2 2
Z
i i i i i i
xi x x y x x y x y i i
2 3 2 2
i i i i i i i i b x Z
2
yi Z i
i2 x y y x y y x y
2 2 3
y i i c
=
i i i i i i
xi x x y x x y x y i d xi Z i
3 2 4 2 2 3 2
i i i i i i i
3
e yi 2 Z i
yi x y y x y y x y
2 2 3 2 2 4
i i
i i i i i i
xy i i i
2
i i x y x y x y x y x y
i
2
i i i
2
i
3
i i i
3
i
2
i
f x y Z
76
Engineering Numerical Methods Chapter 3: Interpolation and curve fitting
A problem arises for high-degree polynomials. The coefficients in the matrix are
varying over a range of several orders of magnitude, which gives rise to
ill-conditioned system. Normalizing each equation helps the situation. Double
precision calculations are required.
Each raw in the matrix should be normalized by the exponential term in the first
coefficient of each raw. Solving the normalized equations by Gauss eliminations
yields
The error is, Error = 1556.3 - 1556.0 = 0.3, which is smaller than the error
incurred by interpolation using direct multivariate linear approximation.
77