You are on page 1of 19

Computational aspects of multivariate Polynomial Interpolation

by
Thomas Sauer
Mathematical Institute
University ErlangenNuremberg
Bismarckstr. 1
1
2
91054 Erlangen
Germany
sauer@mi.uni-erlangen.de
Abstract
The paper is concerned with the practical implementation of two methods to
compute the solution of polynomial interpolation problems. In addition to a de-
scription of the implementation, practical results and several improvements will be
discussed, focusing on speed and robustness of the algorithms under consideration.
Keywords
Lagrange interpolation, nite dierence, algorithm.
1991 Mathematics Subject Classication: Primary: 41A05, 41A10, 65D05, 65D10
Version: August 29, 1994
Compiled: January 20, 2003
1 INTRODUCTION 1
1 Introduction
A new approach to multivariate Lagrange interpolation by polynomials via nite dier-
ences has been given in [3] leading to, among other things, algorithms for the practical
computation of interpolating polynomials. These algorithms cover both aspects of clas-
sical univariate polynomial interpolation; i.e., computation of the Lagrange fundamental
polynomials as well as a Newton method. Both algorithms are based on the notion of
blockwise interpolation, introduced in [3]. For the convenience of the reader this concept
will be sketched in the next section.
It is the intention of this paper to report on some of the results we obtained during
implementing and testing these algorithms. Particular care has been put on two aspects
of our numerical experiments: eciency; i.e., the time the algorithms need to compute
the interpolants and robustness of the algorithms. For the the latter issue we consider
the error of the interpolant at the interpolation points. Although this value should theo-
retically be equal to zero, there is always an inuence of accumulated roundo errors in
computational practice which can signicantly distort the results. Moreover, an ecient
scheme to compute the dierences needed in the Newton method will be given. Finally,
the numerical results will be given to highlight the dierences between the Newton and
Lagrange schemes.
A brief remark is in order about the computational environment used for the tests.
The program was written in C++, compiled by GNU GCC 2.5.6, and run on a usual
single processor SUN SparcStation10 (SunOS 4.1.3), equipped with 48 MB of memory.
All oating point numbers were stored and processed in double precision. The algorithms
are based on an implementation of the class polynomial, equipped with constructors for
monomials, assignment operator, constructor by reference (these are the standard oper-
ations for a C++ class) and the vector space operations (polynomial)(polynomial),
(double)*(polynomial) and (polynomial)/(double). The declaration of the methods
used in the class polynomial then reads as
class polynom {
public:
polynom(); // Zero polynomial
polynom(int n, int k = -1); // x^i y^(n-i)
polynom(polynom& p); // Constructor by reference
~polynom(); // Destructor
double operator() (double,double); // Evaluation, Horner
polynom &operator= (polynom& ); // Assignment
polynom &operator+= (polynom& ); // Add
polynom &operator-= (polynom& ); // Subtract
friend polynom operator+(polynom&,polynom&);
friend polynom operator-(polynom&,polynom&);
friend polynom operator*(double,polynom&);
friend polynom operator/(polynom&,double);
};
2 MULTIVARIATE INTERPOLATION 2
Once this has been implemented, one can, loosely speaking, use the construct polynomial
for programming in the same way as one uses, e.g., ints or doubles in C. Of course, the
performance of the program depends strongly on the performance of the class polynomial.
This is basically due to the fact that frequently used organizational tasks like allocating
and deallocating memory take quite a share of the runtime. For example, replacing
statements of the type p = p+q; by p += q;, after implementing the operator+= for
the class polynomial, improves the performance by not less than 40% although the only
dierence is that a deallocation and an allocation could be omitted.
For information about programming in C++ the reader is referred to the books of
Stroustrup [5] or of Lippman [2].
2 Multivariate interpolation
To make the paper selfcontained and to provide the necessary background, we briey
recapitulate some concepts developed in [3]. For that purpose it is convenient to use
standard multiindex notation; i.e., for any multiindex N
d
0
we denote its length by || =

1
+ +
d
, and for any x = (
1
, . . . ,
d
) R
d
we write x

1
1

d
d
. The ith unit
vector, either taken as a multiindex or a point in R
d
, is written as e
i
= (0, . . . , 0, 1, 0, . . . , 0),
1 i d. Moreover, we denote by
d
n
the space of all real polynomials in d variables of
total degree less than or equal to n; its dimension is denoted by r
d
n
=
_
n+d
d
_
.
Given any set of points x
1
, . . . , x
N
R
d
, N = dim
d
n
, the Lagrange interpolation
problem consists of determining a polynomial p of degree less or equal to n such that for
a given set of values, f
1
, . . . , f
N
R,
p(x
i
) = f
i
, i = 1, . . . , N.
Clearly, the Lagrange interpolation problem is solvable for any set of values f
i
if and only
if the respective Vandermonde determinant is nonsingular. In this case the interpolant p
is uniquely determined and the Lagrange interpolation problem is called poised. This is
in turn equivalent to the existence of polynomials q
i

d
n
, i = 1, . . . , N, such that
q
i
(x
j
) =
ij
, i, j = 1, . . . , N. (1)
The multivariate Newton method introduced in [3] takes a dierent approach by using
the fact that, whenever the Lagrange interpolation problem is poised, the points can be
multiindexed, say by x

, || n, such that there exist polynomials p


d
||
satisfying
p

(x

) =
,
, || || n. (2)
This is proved by the construction of Algorithm 4.3 which will be given below. It will be
seen from this algorithm that there are several ways to multiindex the points, although
some arrangements do not have the above property. Moreover, it seems worthwhile to
point out that equation (2) means that whenever the Lagrange interpolation problem
is poised, the points can be arranged in such a way that the respective interpolation
2 MULTIVARIATE INTERPOLATION 3
subproblems associated to the points x

, || k, k = 0, . . . , n, are poised, too. For


notational purposes let us collect the points on the same level in blocks; i.e., we arrange
them into vectors
x
k
= [x

: || = k] , k = 0, . . . , n.
From now on, let the interpolation problem be poised and let the points be already
properly arranged as x

, || n. We consider two bases of


d
n
, namely the multiindex
version of the polynomials in (1), the Lagrange fundamental polynomials q


d
n
, || n,
satisfying
q

(x

) =
,
, ||, || n, (3)
and the Newton fundamental polynomials p


d
||
, dened by equation (2). A crucial
dierence between the two bases is that p

has degree || while q

has degree exactly n.


Let f : R
d
R be any function and let L
n
(f, x)
d
n
denote the unique solution of
the poised Lagrange interpolation problem
L
n
(f, x

) = f(x

), || n. (4)
Then L
n
(f, x) can be written by as
L
n
(f, x) =

||n
f(x

)q

(x),
or as
L
n
(f, x) =

||n

||
[x
0
, . . . , x
||1
, x

]f p

(x),
where the nite dierence operator
n
[x
0
, . . . , x
n1
, x]f is dened either by the recurrence

0
[x]f = f(x),

k+1
[x
0
, . . . , x
k
, x]f =
k
[x
0
, . . . , x
k1
, x]f

||=k

k
[x
0
, . . . , x
k1
, x

]f p

(x),
(5)
or by the formula

k
[x
0
, . . . , x
k1
, x]f = f(x) L
k1
(f, x), (6)
where L
k
(f, x) denotes the solution of the interpolation problem with respect to the points
x

, || k.
Let me remark here that in special cases the nite dierence takes a very familiar
form. For instance, when d = 1 we have

n
[x
0
, . . . , x
n1
, x]f = f[x
0
, . . . , x
n1
, x] (x x
0
) (x x
n
),
the usual divided dierence of f without division. In the case that x

= , || n, we
have

k
[x
0
, . . . , x
k1
, x

]f =

f(0), || = k, k = 0, . . . , n,
3 REPRESENTATION OF POLYNOMIALS 4
where

is the nth degree cardinal forward dierence of f dened recursively as

0
f(x) = f(x),

+e
i
f(x) =

f(x + e
i
)

f(x), 1 i d,
x R
d
.
This special case is considered in [4].
In general, to give a representation of the dierence operator (and thus by formula (6)
of the error of interpolation) in terms of derivatives, we need further notation. We denote
a subset of lattice vectors by

n
:=
_
= (
0
, . . . ,
n
) :
i
N
d
0
, |
i
| = i, i = 0, . . . , n
_
and associate to each
n
the path
x

= {x

0
, . . . , x

n
}.
Note that x

is a set of points in R
d
while x
i
is a vector of points. Any index set
n
corresponds to a subset of interpolation points that contains exactly one point on each
of the levels x
i
, i = 0, . . . , n. The name path is motivated by the image that one
travels from x
(0,...,0)
to some point x

, || = n, at level n, ascending one level in each


step. Moreover, to any such path we can associate a directional derivative that travels
exactly the same way, namely
D
n
x
:= D
x

n
x

n1
D
x

n1
x

n2
D
x

1
x

0
,
n
.
We also require

(x

) :=
n1

i=0
p

i
(x

i+1
),
n
.
Then the representation formula for any (n + 1) times dierentiable function f reads as
f(x) L
n
(f, x) =
n+1
[x
0
, . . . , x
n
, x]f
=

n
p

n
(x)

(x

)
_
R
d
D
xx

n
D
n
x
f(y)M(y|x

, x)dy, (7)
where M( |x

, x) denotes the simplex spline (distribution) with the knots x

0
, . . . , x

n
, x.
3 Representation of polynomials
The algorithms for Lagrange interpolation in this paper rely on vector space operations
and point evaluation applied to multivariate polynomials. Therefore it is important to
describe how we store, manipulate and evaluate polynomials. In the sequel we will consider
two dierent bases for polynomials, namely the monomial basis and the BernsteinB`ezier
basis.
3 REPRESENTATION OF POLYNOMIALS 5
Let us rst consider monomial representation of polynomials. A polynomial p
d
n
can be written as
p(x) =

||n
c

, c

R, || n. (8)
Thus, if we want to store all the r
d
n
coecients c

, || = n, in a vector of length r
d
n
, we
have to order the multiindices in an appropriate way. The two most convenient ways are
to order the multiindices either inverse lexicographically or rst by degree and then in
inverse lexicographical order. Inverse lexicographical ordering means that the multiindices
of length n are arranged as
ne
1
, (n 1)e
1
+ e
2
, . . . , (n 1)e
1
+ e
d
, (n 1)e
1
, . . . , ne
d
, (n 1)e
d
, . . . , e
d
, 0,
while the latter ordering looks like
0, e
1
, . . . , e
d
, 2e
1
, e
1
+ e
2
, . . . , 2e
d
, . . . , ne
1
, . . . , ne
d
, . . . ,
Let me note that the inverse lexicographical order depends on the length of the underlying
multiindices. As a consequence this implies that, if one wants to write p from (8) as a
polynomial of degree n+1 and uses the inverse lexicographical order, then the coecients
have to be rearranged.
In the sequel, let
0
,
1
, . . . denote multiindices ordered by degree rst and then inverse
lexicographically, while
0
,
1
, . . . denotes multiindices arranged in inverse lexicographical
order; clearly, in the latter case n has to be xed rst. Thus we store a polynomial of degree
n as a vector of r
d
n
oating point numbers (or oats, for short) c[i], where c[i] = c

i
or c[i] = c

i , depending on the ordering we use. The reason for all this eort is that
indexing is not for free; i.e., we may have to compute the index which associates to any
multiindex the natural number 0 i r
d
n
1 such that =
i
or =
i
, respectively.
Due to the performance of oating point processors these operations cannot be neglected
and so we should try to reduce them as much as possible. Therefore, one important goal
is to avoid the explicit computation of indices which in turn implies that we have to nd
an ordering such that we can perform the operations just by processing the array in its
linear order c[0], c[1], . . .
Let us now focus on how to realize the operations on polynomials. Of course, multipli-
cation by some scalar is easily done for any order of multiindices, as well as the addition
of two polynomials which have the same degree. To consider addition of polynomials of
dierent degrees let
p(x) =

||n
1
c

, q(x) =

||n
2
b

,
and assume that n
1
n
2
. Then p + q has the representation
p(x) + q(x) =

||n
2
a

, where a

=
_
c

+ b

|| n
1
b

n
1
< || n
2
.
3 REPRESENTATION OF POLYNOMIALS 6
In other words, we compute
a[i] =
_
c[i] + b[i], 0 < i < r
d
n
1
,
b[i], r
d
n
1
i < r
d
n
2
,
where the values r
d
n
1
are conveniently memorized by the data structures of p and q and
need not be computed during the addition. Thus, for the addition (and subtraction)
of polynomials it is preferable to order the multiindices by degree rst and then inverse
lexicographically.
The evaluation of polynomials will be done by the multivariate version of the Horner
scheme which is based on nested multiplications. Recall that the basic idea of the Horner
scheme is to rewrite the polynomial p, as given in (8), into
p(x) =
1
_

1
(
1
p
n
( x) + p
n1
( x))
_
+ p
0
( x),
where x = (
2
, . . . ,
d
),
p
i
( x) =

||ni,
1
=i
c

i
1
, i = 0, . . . , n,
and the polynomials p
i
are expanded with respect to
2
, . . . ,
d
in the same way. This
Horner scheme can be easily programmed recursively. The advantage of this approach
will be clear if we consider the order in which the coecients are processed: clearly,
since p
n
( x) = c
ne
1 = c

0 and since p
i
uses the coecients c

,
1
= n i, which are
then processed by decreasing order of
2
,
3
, and so on, we see that the Horner scheme
processes the coecients in inverse lexicographical order which seems to be more useful
in evaluating polynomials.
There is, however, a dilemma. Depending on the operations to be performed each of
the two ways of indexing has its advantages and drawbacks. The best seems to be some
mixed strategy: for example, one can order the coecients by degree rst and keep an
additional array of pointers to take care of the inverse lexicographical order. The array
can be set up the rst time a polynomial is evaluated and this will be the only time we
have to make the eort to compute the indices explicitly.
A second way to represent polynomials is by means of the BernsteinBezier basis
which relies on the barycentric coordinates of a point with respect to a given simplex.
Recall that whenever d+1 points v
0
, . . . , v
d
R
d
are in general position (i.e., the simplex
[v
0
, . . . .v
d
] has dimension d), we can write each point x R
d
as
x =
d

i=0

i
(x)v
i
, where
d

i=0

i
(x) = 1.
The vector (x) = (
0
(x), . . . ,
d
(x)) is called the barycentric coordinates of x with respect
to the simplex [v
0
, . . . , v
d
]. Given any multiindex = (
0
, . . . ,
d
) N
d+1
0
(the indices
4 ALGORITHMS 7
start with zero here!), we dene the BernsteinBezier basis polynomial B

(x) as
B

(x) =
_
||

_
(x)

=
||!

0
!
d
!

0
(x)

0

d
(x)

d
.
Any polynomial p
d
n
can be written as
p(x) =

||=n
c

(x), (9)
which is usually called the BBrepresentation of p.
Unfortunately the BBrepresentation does not provide a nested basis. That is, the
collection of polynomials {B

: || n} is not a subset of {B

: || n+1}. Nevertheless
we may convert (9) to a BBrepresentation of degree n + 1 by the degree raising formula
p(x) =

||=n+1
c

(x), where c

=
d

i=0

i
n + 1
c
e
i , || = n + 1. (10)
Since this formula accesses some of the coecients of p several times, there cannot be a
order of the coecients such that they are processed according to it. Thus, computational
eort for indexing is unavoidable. Moreover, if we want to add two polynomials p and q
of degree n
1
and n
2
with n
1
< n
2
, say, we rst have to apply (n
2
n
1
)fold degree raising
to p and then perform the addition.
Point evaluation of polynomials in BBrepresentation is performed in the de Casteljeau
algorithm by computing the numbers
c

=
d

i=0

i
(x)c
+e
i , || = n 1, n 2, . . . , 0,
we end up with c
0
= p(x). Note that here again the coecients are accessed several times.
Comparing the two representations we see that the computational eort is signicantly
higher for the BBrepresentation. Indeed, rst, all operations in BBrepresentation re-
quire access to indexing operations, second, addition of polynomials of dierent degree is a
costly operation since it has to use degree raising and, third, the de Casteljeau algorithm
involves O(n
d+1
) operations while both evaluation schemes for the monomial basis are
satised with O(n
d
) operations.
The inferior performance suggested from these considerations will be veried by the
outcome of the tests, but the BBrepresentation will pay back some of the computational
eort by a signicant decrease of roundo errors if the evaluations are chosen to be inside
the unit simplex.
4 Algorithms
In this section we briey recapitulate the two algorithms for the computation of the
fundamental polynomials given in [3] and give variations thereof. Moreover, we also
4 ALGORITHMS 8
describe an ecient scheme to compute the nite dierences since a direct use of the
recurrence relations (5) is not practical.
The algorithms computing the fundamental polynomials have already been introduced
in [3]; they are repeated here in a slightly modied form in fact they are in principal
the pseudo-code notation of the C++ programs which have been used in the tests. The
algorithms either compute the fundamental polynomials or recognize that the points lie
on some algebraic hypersurface of degree n, that is, the Lagrange interpolation problem
with respect to these points is not poised. Throughout this section we assume the multi-
indices to be ordered by degree rst and then inverse lexicographically. Hence, <
is to be understood in this sense.
The principal algorithm computes the Lagrange fundamental polynomials by a process
similar to the GramSchmidt orthogonalization method:
Algorithm 4.1. (Lagrange fundamental polynomials)
Input: N N, N = r
d
n
and x
0
, . . . , x
N1
R
d
.
for i = 0, . . . , N 1 do
q

i := x

i
;
done;
for i = 0, . . . , N 1 do
for j = i, . . . , N do
if j = N then stop: No solution ;
if q

j (x
i
) = 0 then break; ;
done;
q =
q

j
q

j (x
i
)
;
q

j = q

i ;
q

i = q;
x

i = x
i
;
for || n, =
i
do
q

= q

(x

i )q

i ;
done;
done;
Output: Lagrange fundamental polynomials q


d
n
and points x

, || n.
It is easily seen that for i = 0, . . . , N 1 this algorithm always takes the rst index

j
i such that q

j (x
i
) = 0. Since we divide by this quantity, its absolute value should
be as large as possible. For this reason we use a slightly modied version of Algorithm
4.1 which incorporates a pivoting strategy:
Algorithm 4.2. (Lagrange fundamental polynomials with pivoting)
Input: N N, N = r
d
n
and x
0
, . . . , x
N1
R
d
.
for i = 0, . . . , N 1 do
4 ALGORITHMS 9
q

i := x

i
;
done;
for i = 0, . . . , N 1 do
v
max
= 0;
j
max
= i;
for j = i, . . . , N do
if |q

j (x
i
)| > |v
max
| then
v
max
= q

j (x
i
);
j
max
= j;
;
done;
if v
max
= 0 then stop: No solution ;
j = j
max
;
q =
q

j
q

j (x
i
)
;
q

j = q

i ;
q

i = q;
x

i = x
i
;
for || n, =
i
do
q

= q

(x

i )q

i ;
done;
done;
Output: Lagrange fundamental polynomials q


d
n
and points x

, || n.
Notice that in both cases the algorithm proceeds point-by-point (the iloop is in-
dexed with respect to the points) and then look for a proper polynomial that does not
vanish at this point.
The algorithm for the computation of the Newton fundamental polynomials works the
other way around. Here we proceed polynomial-by-polynomial, where the polynomials
are already multiindexed, and then look for a point at which the respective polynomial
does not vanish. This point is then equipped with the same multiindex as the polynomial.
This is exactly the process which puts the points into block, i.e., the process which nds
the poised subproblems. The computation of the Newton fundamental polynomials reads
as follows:
Algorithm 4.3. (Newton fundamental polynomials)
Input: N N, N = r
d
n
and x
0
, . . . , x
N1
R
d
.
for i = 0, . . . , N 1 do
p

i := x

i
;
done;
for i = 0, . . . , N 1 do
for j = i, . . . , N do
4 ALGORITHMS 10
if j = N then stop: No solution ;
if p

i (x
j
) = 0 then break; ;
done;
x

i = x
j
;
x
j
= x
i
;
p

i =
p

i
p

i (x

i )
;
for |
i
| || n do
p

= p

(x

i )p

i ;
done;
done;
Output: Newton fundamental polynomials p


d
||
and points x

, || n.
Let me remark that, in contrast to Algorithm 4.1, any polynomial p

i in Algorithm 4.3
is only subtracted from polynomials which have the same or higher degree. Of course, this
is necessary since we required the Newton fundamental polynomials p

to be of degree
||. This also means that, in contrast to Algorithm 4.1, we do not have to apply degree
raising operations to these polynomials which would involve costly operations of memory
allocation. Moreover, the number of subtractions of polynomials is signicantly less in
this algorithm which is the second reason that the computation of Newton fundamental
polynomials is much faster than the computation of Lagrange fundamental polynomials.
We will see this fact emerge from the numerical experiments.
Of course, the construction of the Newton fundamental polynomials can be done with
a pivoting strategy in the same way as in Algorithm 4.2.
Observe that the algorithms above use only the vector space structure of polynomials
and point evaluation operations; in other words: these procedures work whenever one
wants to interpolate with some nite dimensional linear space of functions, as long as a
basis of the space can be evaluated.
As mentioned above, the recurrence relation in (5) is extremely slow and thus of no
practical use. To overcome this drawback, let us introduce a triangular scheme which com-
putes the coecients of the interpolating polynomial more eciently. For that purpose,
let f C(R
d
) be given and consider the scheme L
n
= (

)
||n
, initialized by

= f(x

), || = n.
Notice that
0
0
already has the value
0
[x
0
]f = f(x
0
). Next, we compute
1

, || = 1, as

=
1
[x
0
, x

]f =
0
[x

]f
0
[x
0
]f p
0
(x

) =
0

0
0
p
0
(x

).
Applying this to all 1 || n, we obtain

1
0
=
0
[x
0
]f,
1

=
0

0
0
p
0
(x

) =
1
[x
0
, x

]f, 1 || n.
4 ALGORITHMS 11
Proceeding inductively, let us assume that for some 1 k < n the scheme already contains

=
||
[x
0
, . . . , x
||1
, x

]f, || k

=
k
[x
0
, . . . , x
k1
, x

]f, k < || n.
We set
k+1

=
k

if || k and compute for || > k

k+1

=
k+1
[x
0
, . . . , x
k
, x

]f
=
k
[x
0
, . . . , x
k1
, x

]f

||=k1

k
[x
0
, . . . , x
k1
, x

]f p

(x

)
=
k

||=k1

(x

).
Thus, our scheme nally gives
L
n
=
_

||
[x
0
, . . . , x
||1
, x

]f
_
||n
.
This recursion has the nice property that all the coecients of the interpolating polynomial
are computed at the same time, i.e., even the intermediate values are of value.
Finally, if we overwrite
k

by
k+1

in each step of the process, we are in a position to


formulate an algorithm which computes the dierences in an ecient way:
Algorithm 4.4. (Finite Dierences)
Input: Points x

, Newton fundamental polynomials p

, || n, and a function f.
for || n do

= f(x

);
done;
for k = 1, . . . , n do
for || k do

||=k1

(x

);
done;
done;
Output:

=
||
[x
0
, . . . , x
||1
, x

]f, || n.
Note that Algorithm 4.4 uses the evaluation of p

at points of higher level. If we have


to interpolate various functions with respect to the same set of points (the fundamental
polynomials do not change), it might therefore be convenient to store the values p

(x

),
|| < ||, in some matrix instead of repeatedly evaluating the polynomials, each of which
requires O(r
d
||
) ops.
In Algorithm 4.3 and Algorithm 4.4 order by length of the multiindices is used to
access the fundamental polynomials and the entries in the triangular scheme. Therefore
4 ALGORITHMS 12
it is only reasonable to use this order in both cases. This has a further advantage. Let
p[0],p[1],. . .,p[N-1] be the vector of the fundamental polynomials and c[0],c[1],. . .,
c[N-1] be the entries of the triangular scheme. Then the interpolating polynomial q is
the scalar product of these two vectors and can be computed by the following piece of
C++ code:
polynomial q = 0;
for (int i = N-1; i >= 0; i++)
q += c[i] * p[i];
Note that the additions are carried out in inverse order; i.e., the index starts with the
highest value and counts down to zero. This is to avoid unnecessary allocation/deallocation
operations: otherwise, whenever the degree of p[i] is higher than the degree of q, as com-
puted so far, we would have to provide more memory for the coecients of q. This would
lead to the allocation of more memory for q and then the deallocation of the amount of
storage used by q so far. This simple switch of the order of addition, however, already
initializes q with a polynomial of highest degree and therefore avoids the costly operations
of allocation and deallocation.
Let us look at the amount of storage needed for the two approaches. Since the Lagrange
polynomials are of full degree, each of them requires N coecients and since there are
N of them we have a total memory requirement of N
2
oats, the same amount as for
the Vandermonde matrix. Newton fundamental polynomials are cheaper in memory since
most of them are of lower degree and therefore require the storage of a smaller number
of coecients. More precisely, let s
d
j
= r
d
j
r
d
j1
be the number of monomials of degree
equal to j, j = 0, . . . , n, then for any k = 0, . . . , n there are s
d
k
polynomials of degree k
which need r
d
k
coecients. Thus, for the storage of the Newton fundamental polynomials
we need
n

k=0
s
d
k
r
d
k

N
2
2
oats. If we also want to store the values p

(x

), || < || n, then on each level k,


0 k n 1 there are s
d
k
polynomials each of which requires s
d
k+1
+ +s
d
n
evaluations
at higher level points. Therefore we have to provide memory for
n1

k=0
s
d
k
n

j=k+1
s
d
j
additional oats. Taking into account that r
d
k
+ s
d
k+1
+ + s
d
n
= r
d
n
= N, we obtain
a total memory requirement for the Newton method with the additional storage of the
factors in the triangular scheme of
n

k=0
s
d
k
r
d
k
+
n1

k=0
s
d
k
n

j=k+1
s
d
j
=
n1

k=0
s
d
k
r
d
n
+ s
d
n
r
d
n
= N
2
5 NUMERICAL RESULTS 13
oating point numbers. This means, that even with the storage of the values needed in
the triangular scheme for the dierence, the Newton method is not more expensive in
memory consumption than the Lagrange method.
5 Numerical results
The tests which are used for the comparison of the dierent methods will be organized
as follows: given some test function f C(R
d
), we will solve 100 interpolation problems
with 25, 50, 100 and 150 points and 10 problems with 200, 300, 400 and 500 points, all
of them randomly chosen in [0, 1]
2
. Then we measure the mean user time needed to solve
a single interpolation problem and the accuracy of interpolation; i.e., the values
|f(x

) L
n
(f, x

)| , || n.
For the latter quantity we will record the worst case error of all points in all of the 100,
respectively 10, interpolation problems and the arithmetic mean over all of points and all
the interpolation problems. This has been selected as a measure for the robustness of the
algorithms under consideration.
Although the number of points does not match the dimension of some
2
n
in any of
the cases, and therefore the Lagrange interpolation problem cannot be poised in some

2
n
, this does not cause serious problems. We will just interpolate with the subspace
spanned by x

i
, i = 0, . . . , N 1 which lies between
d
|
N1
|1
and
d
|
N1
|
. The random
number generator is always started with a number which only depends on the number of
points, such that both algorithms and any improved version of them have to solve 100,
respectively 10, identical problems. This should keep the competition fair. To limit
the runtime of the test suite the large problems were only run 10 times which looks
unsatisfactory at rst glance. Nevertheless, even these results are signicant since we ran
a lot of test suites with dierent setups and the order of magnitude of errors was always
the same.
The implementation of the algorithms uses a version of the class polynomial which
has been adapted to the bivariate case. All multiindexed objects, such as the coecients
of polynomials, the polynomials themselves, and the entries in the triangular scheme,
are ordered by degree rst. Since in the bivariate case it is easy to compute the inverse
lexicographical order directly, no additional array of pointers was needed for the Horner
scheme.
To compare the Lagrange and Newton methods we use the test function
f(x, y) = e
8
(
(x
1
2
)
2
+(y
1
2
)
2
)
,
a rescaled version of a test function which had also been considered in [1]. The results
are summarized in Table 1.
Incorporating pivoting we obtain the results listed in Table 2 which show that pivoting
usually yields a slight improvement in the quality of interpolation. The time consumption
5 NUMERICAL RESULTS 14
Lagrange Newton
# points worst mean time worst mean time
25 4.463319e-08 2.123451e-10 0.050 5.013276e-08 1.576476e-10 0.025
50 1.761731e-06 2.233217e-08 0.226 5.674630e-08 3.698732e-10 0.115
100 9.742520e-02 2.062384e-04 1.189 3.134884e-06 2.371369e-08 0.574
150 2.299013e+01 6.277672e-02 3.311 2.180735e-04 4.152404e-07 1.692
200 4.149814e+02 1.666190e+00 7.03 9.798922e-05 7.789570e-07 3.41
300 1.446600e+03 7.915207e+00 20.38 4.907759e-05 4.910136e-07 10.20
400 2.126242e+04 6.598622e+01 47.81 1.672096e-03 5.840814e-06 22.85
500 1.101068e+06 1.692285e+03 98.56 1.296537e-04 5.381342e-07 43.26
Table 1: Lagrange and Newton method applied to f = e
8((x1/2)
2
+(y1/2)
2
)
of the Lagrange method is much more aected by pivoting than that of the Newton
method. To search for the pivot element in the computation of the Lagrange fundamental
polynomials means to evaluate polynomials of increasing degree at the same point. Thus,
the computational eort of any single evaluation increases, too. On the other hand, the
search for maximum in the computation of the Newton fundamental polynomials evaluates
the polynomial at dierent points, i.e., the eort for a single evaluation remains constant.
Lagrange Newton
# points worst mean time worst mean time
25 3.018431e-10 4.349764e-12 0.053 3.000489e-11 4.140634e-13 0.026
50 1.711860e-07 1.014681e-09 0.283 4.772637e-09 2.002858e-11 0.123
100 1.625578e-03 8.977995e-06 1.705 6.583254e-07 2.160971e-09 0.629
150 5.495008e+00 9.360874e-03 5.050 9.698928e-06 4.057631e-08 1.775
200 1.254138e+01 2.622521e-01 11.84 1.072316e-05 1.646272e-07 3.76
300 6.081160e+04 2.667516e+02 34.86 1.656613e-05 1.761121e-07 11.30
400 2.921581e+04 2.543345e+02 88.16 2.418902e-04 7.385581e-07 25.40
500 1.424773e+05 1.083359e+03 208.35 3.558768e-05 3.688244e-07 48.07
Table 2: Lagrange and Newton method with pivoting applied to f = e
8((x1/2)
2
+(y1/2)
2
)
The Newton method is superior in all respects. It is not only faster and less sensitive
in performance to pivoting, but also provides a surprising immunity against roundo
errors even for 500 points (which is degree 31, but in the Horner scheme the number
of nested multiplications and additions and thats what causes the roundo errors is
equivalent to that for univariate polynomials of degree 499) we only have a worst case
error of magnitude 10
4
.
The computation changes dramatically if we interpolate the test function
f(x, y) = |x y|,
5 NUMERICAL RESULTS 15
which is known to be very unfriendly to interpolation. Table 3 shows the eect of this
function on the robustness of the Newton method which is now of the same order of
magnitude.
Lagrange Newton
# points worst mean worst mean
25 6.384678e-08 2.208463e-10 6.349903e-08 2.040262e-10
50 3.761145e-06 2.048795e-08 3.762834e-06 1.324844e-08
100 5.650217e-02 2.833983e-04 5.630920e-02 2.361960e-04
150 6.863485e+01 1.689310e-01 6.856829e+01 1.663155e-01
200 1.585731e+02 9.668451e-01 5.347714e+01 5.921686e-01
300 1.021281e+03 6.622473e+00 1.095193e+03 6.131108e+00
400 3.074677e+03 2.381371e+01 8.510057e+03 4.445905e+01
500 2.859273e+05 4.280414e+02 6.850754e+04 1.338527e+02
Table 3: Lagrange and Newton method applied to f(x, y) = |x y|
Let us try to interpret this behavior of the interpolation algorithms. Clearly, the
smoothness of the interpolated function can hardly aect the Lagrange method. For
the Newton method, however, formula (7) hints that for smooth functions with fairly
rapidly decreasing values of the derivatives the dierences
n
[x
0
, . . . , x
n1
, x]f should be
small for increasing n. Thus the contribution of high degree monomials which are mainly
responsible for large roundo errors will be very small. The identity
L
n
(f, x) = L
n1
(f, x) +

||=n
(f(x

) L
n1
(f, x

)) p

(x), (11)
visualizes the connection between convergence and robustness: if L
n
f converges to f, i.e.,
if interpolation is compatible with f, then the contribution of high degree polynomials is
small and thus the Newton interpolation method is accurate. Conversely, if L
n
f does not
converge to f or even diverges to innity, then polynomials of high degree will contribute
strongly and cause severe roundo errors. As it can be seen from the function |x y| the
quality of any interpolation method is very poor if we want to interpolate at more than
100 points.
Thus the smoothness of the underlying function should inuence the quality of the
interpolant quite signicantly. To give some numerical evidence of this phenomenon, let
us consider the truncated powers
(x y)
k
+
=
_
(x y)
k
, x > y,
0, x y
, k = 0, . . . , 15,
interpolated at 200 random points (100 tests in each case). The results depicted in Table
4 show this evidently. Whenever we raise the exponent and therefore the smoothness of
the function, we also improve the accuracy of the interpolant. Of course, there is some
limit where accuracy cannot be improved any more.
6 BERNSTEINB

EZIER REPRESENTATION ACHANGE OF BASIS ANDREGION16


function worst mean
(x y)
0
+
1.414161e+04 3.424847e+01
(x y)
1
+
2.306302e+02 5.885873e-01
(x y)
2
+
5.711645e+00 2.686329e-02
(x y)
3
+
6.327744e-01 2.285044e-03
(x y)
4
+
4.419375e-02 2.499046e-04
(x y)
5
+
1.386771e-02 4.013625e-05
(x y)
6
+
1.386838e-03 7.848432e-06
(x y)
7
+
7.082329e-04 1.852051e-06
(x y)
8
+
8.876935e-05 5.685933e-07
(x y)
9
+
7.252913e-05 1.818965e-07
(x y)
10
+
1.324360e-05 8.374641e-08
(x y)
11
+
1.388975e-05 3.676999e-08
(x y)
12
+
4.363844e-06 2.402691e-08
(x y)
13
+
4.803590e-06 1.398927e-08
(x y)
14
+
2.595656e-06 1.368125e-08
(x y)
15
+
3.119068e-06 1.028765e-08
Table 4: Truncated powers at 200 points
6 BernsteinBezier representation a change of ba-
sis and region
Since Algorithms 4.1 and 4.3 apply only vector space operations and point evaluation
to polynomials in
d
n
, the basis used by the class polynomial has no inuence on the
algorithms themselves. Thus it is reasonable to try other bases in order to obtain better
results, for example the BernsteinBezier representation. The drawback of this basis,
however, is its reduced eciency. Not only the evaluation algorithm requires greater
eort, also addition of polynomials is more expensive in most cases. Since we therefore can
expect our algorithms to run signicantly slower, the BBrepresentation should provide
some payo in form of a reasonable increase of robustness. For this purpose we compare
the two bases on two regions: on the unit square [0, 1]
2
and on S
2
which is the home
domain of the BernsteinBezier representation. Since in the latter region evaluation
consists of repeated convex combinations we might expect some increased accuracy.
First we consider the numerical results when using the BernsteinBezier basis to in-
terpolate
f(x, y) = e
8
(
(x
1
2
)
2
+(y
1
2
)
2
)
(12)
without and with pivoting on the square. The results are listed in Table 5, where, for any
number of points the above value represents the case without pivoting and the one below
the case with pivoting.
Finally, let us turn to the unit triangle S
2
where the computations based on the
REFERENCES 17
Lagrange Newton
# points worst mean time worst mean time
25 4.153078e-08 4.381949e-11 0.143 4.230155e-08 3.968871e-11 0.081
1.083748e-10 1.309538e-12 0.148 6.192943e-11 2.049121e-13 0.085
50 7.442618e-07 1.650317e-09 0.936 2.733975e-07 2.671148e-10 0.520
1.042958e-07 2.489006e-10 1.120 3.148098e-08 2.221031e-11 0.538
100 1.442830e-02 1.158003e-05 6.387 2.537013e-05 2.599283e-08 4.425
1.208056e-04 4.729123e-07 9.778 9.677265e-06 5.352320e-09 4.992
150 3.143096e+01 8.127532e-03 21.733 5.713038e-03 2.192207e-06 13.873
1.642021e-01 3.686560e-04 30.030 3.084068e-04 2.498247e-07 15.845
200 7.005735e+02 9.282342e-01 53.47 1.608834e-02 8.909492e-06 35.46
8.948881e+00 2.188881e-02 85.06 4.664504e-03 3.710750e-06 40.61
300 3.189365e+05 1.729660e+02 184.59 9.516154e-03 8.805335e-06 136.59
3.495457e+06 1.350418e+03 299.19 1.056081e-02 1.034365e-05 157.58
400 1.719140e+06 2.277616e+03 503.76 1.006455e-02 6.551872e-06 362.45
1.289018e+09 3.750547e+05 848.98 6.423332e-02 3.150639e-05 418.94
500 2.826352e+07 1.943249e+04 1177.89 1.106003e-01 6.435752e-05 775.97
6.314407e+09 8.461617e+06 2057.78 8.235633e-03 2.226675e-05 894.82
Table 5: BernsteinBezier basis on the square.
monomial basis show signicantly less accuracy than on the unit square (see Table 6),
regardless whether one uses pivoting or not. Using the BernsteinBezier basis increases
the robustness of the algorithms (see Table 7). In both cases the exponential test function
was interpolated.
References
[1] C. de Boor and A. Ron. Computational aspects of polynomial interpolation in several
variables. Math. Comp., 58 (1992), 705727.
[2] Stanley B. Lippman. C++ primer. Addison-Wesley, 2. edition, 1991.
[3] Th. Sauer and Y. Xu. On multivariate Lagrange interpolation. To appear in Math.
Comp.
[4] Th. Sauer and Y. Xu. A case study in multivariate Lagrange interpolation. To appear
in NATO Conference Proceedings, Maratea, 1994.
[5] Bjarne Stroustrup. The C++ programming language. Addison-Wesley, 2. edition,
1991.
REFERENCES 18
Lagrange Newton
# points worst mean time worst mean time
25 2.595999e-08 3.506247e-10 0.049 2.285563e-10 2.280260e-12 0.026
1.074825e-09 2.290780e-11 0.050 1.533060e-11 2.845596e-13 0.027
50 3.637496e-03 5.572239e-06 0.224 1.359431e-07 4.865755e-10 0.115
8.149359e-06 4.233035e-08 0.271 4.207358e-09 2.234978e-11 0.123
100 5.306237e+00 1.964924e-02 1.340 1.418371e-05 3.573037e-08 0.621
2.020826e+00 2.971576e-03 1.806 1.117948e-06 5.123820e-09 0.657
150 4.290398e+03 2.879124e+00 3.277 9.530273e-05 7.940892e-08 1.599
8.264331e+02 5.689910e-01 4.721 5.619064e-07 2.356249e-09 1.760
200 1.397175e+04 4.095677e+01 7.03 1.851206e-05 9.712912e-08 3.38
9.590505e+02 4.029076e+00 11.26 2.789856e-06 1.478546e-08 3.75
300 1.260878e+06 1.249520e+03 20.40 1.615770e-04 4.271359e-07 10.21
1.727911e+06 1.184524e+03 32.83 1.275465e-04 7.152282e-07 11.30
400 2.333500e+06 4.685404e+03 47.74 2.794906e-02 2.483787e-05 22.85
1.031858e+05 4.051350e+02 84.17 2.093549e-02 2.071717e-05 25.38
500 8.841285e+06 6.011905e+03 98.23 3.430555e-02 4.103941e-05 43.29
1.066711e+06 2.297083e+03 195.83 9.312563e-03 1.625316e-05 48.11
Table 6: Monomial basis on the simplex.
Lagrange Newton
# points worst mean time worst mean time
25 5.348628e-10 6.441988e-12 0.141 4.802492e-12 6.702319e-14 0.080
7.016343e-11 9.325487e-13 0.154 4.139064e-12 1.601193e-14 0.086
50 1.514022e-06 5.204759e-09 0.881 5.660951e-09 6.084635e-12 0.493
9.387515e-09 1.309740e-10 1.050 1.023810e-10 4.031219e-13 0.541
100 1.205453e-04 9.340927e-07 6.404 9.607325e-08 2.191867e-10 4.520
8.842270e-06 1.051278e-07 9.158 2.442366e-08 2.908022e-11 4.801
150 1.196788e-01 1.128211e-04 20.556 3.381104e-08 6.833958e-11 13.893
4.799341e-03 1.793391e-05 29.150 4.455833e-08 9.066702e-11 15.843
200 7.178328e-02 7.012317e-04 53.49 8.678002e-10 9.645799e-12 35.47
7.809762e-02 7.424870e-04 83.56 3.764280e-09 3.069413e-11 40.61
300 2.762541e+02 6.919600e-01 184.51 9.583710e-09 3.971020e-11 136.63
7.957496e+02 2.732732e+00 293.39 2.640019e-09 2.897659e-11 157.57
400 3.897538e+04 6.350886e+01 570.28 1.234486e-07 2.703590e-10 385.10
1.208065e+05 3.404518e+02 884.46 9.571587e-06 2.067182e-08 419.06
500 6.920784e+06 5.978468e+03 1178.17 2.468131e-05 3.407266e-08 772.19
4.037479e+06 7.611616e+03 2152.51 4.447331e-05 5.611746e-08 894.65
Table 7: BernsteinBezier basis on the simplex.

You might also like