Computational aspects of multivariate Polynomial ... - Semantic Scholar

3 downloads 0 Views 231KB Size Report
subproblems associated to the points x , j j k, k = 0;:::;n, are poised, too. For notational purposes let us .... two di erent bases for polynomials, namely the monomial basis and the Bernstein{B ezier basis. 4 ...... 2] Stanley B. Lippman. C++ primer.
Computational aspects of multivariate Polynomial Interpolation by Thomas Sauer Mathematical Institute University Erlangen{Nuremberg Bismarckstr. 1 21 91054 Erlangen Germany [email protected]

Abstract

The paper is concerned with the practical implementation of two methods to compute the solution of polynomial interpolation problems. In addition to a description 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 di erence, algorithm. 1991 Mathematics Subject Classi cation: Primary: 41A05, 41A10, 65D05, 65D10

Version: October 1994 Compiled: June 3, 1996

Computational Aspects of Interpolation

Compiled June 3, 1996

1 Introduction A new approach to multivariate Lagrange interpolation by polynomials via nite di erences has been given in [3] leading to, among other things, algorithms for the practical computation of interpolating polynomials. These algorithms cover both aspects of classical 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 theoretically be equal to zero, there is always an in uence of accumulated roundo errors in computational practice which can signi cantly distort the results. Moreover, an ecient scheme to compute the di erences needed in the Newton method will be given. Finally, the numerical results will be given to highlight the di erences 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 operations 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); };

1

Compiled June 3, 1996

Computational Aspects of Interpolation

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 di erence 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 self{contained and to provide the necessary background, we brie y recapitulate some concepts developed in [3]. For that purpose it is convenient to use standard multiindex notation; i.e., for any multiindex 2 Nd0 we denote its length by j j = 1 +    + d , and for any x = (1 ; : : : ; d ) 2 Rd we write x = 1 1    d d . The i{th unit vector, either taken as a multiindex or a point in Rd, is written as ei = (0; : : : ; 0; 1; 0; : : : ; 0), 1  i  d. Moreover, we denote by dn the space of all real polynomials  ind variables of d total degree less than or equal to n; its dimension is denoted by rn = n+d d . Given any set of points x1; : : : ; xN 2 Rd, N = dimdn, 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, f1; : : : ; fN 2 R, p(xi ) = fi ; i = 1; : : : ; N: Clearly, the Lagrange interpolation problem is solvable for any set of values fi 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 qi 2 dn, i = 1; : : : ; N , such that qi (xj ) = ij ;

i; j = 1; : : : ; N:

(2.1) The multivariate Newton method introduced in [3] takes a di erent approach by using the fact that, whenever the Lagrange interpolation problem is poised, the points can be multiindexed, say by x , j j  n, such that there exist polynomials p 2 dj j satisfying

j j  j j  n:

p (x ) =  ; ;

(2.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.2) means that whenever the Lagrange interpolation problem is poised, the points can be arranged in such a way that the respective interpolation 2

Compiled June 3, 1996

Computational Aspects of Interpolation

subproblems associated to the points x , j j  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 xk = [x : j j = k ] ; k = 0; : : : ; n: From now on, let the interpolation problem be poised and let the points be already properly arranged as x , j j  n. We consider two bases of dn, namely the multiindex version of the polynomials in (2.1), the Lagrange fundamental polynomials q 2 dn, j j  n, satisfying q (x ) =  ; ; j j; j j  n; (2.3) and the Newton fundamental polynomials p 2 dj j, de ned by equation (2.2). A crucial di erence between the two bases is that p has degree j j while q has degree exactly n. Let f : Rd ! R be any function and let Ln (f; x) 2 dn denote the unique solution of the poised Lagrange interpolation problem Ln (f; x ) = f (x );

Then Ln(f; x) can be written by as Ln (f; x) =

or as

Ln (f; x) =

X

j jn

X

j jn

j j  n:

(2.4)

f (x )q (x);

j j[x0; : : : ; xj j?1; x ]f  p (x);

where the nite di erence operator n [x0; : : : ; xn?1 ; x]f is de ned either by the recurrence k+1

0 [x]f 0 [x ; : : : ; xk ; x]f

or by the formula

= f (x); = k [x0; : : : ; xk?1 ; x]f ?

X

j j=k

k [x0; : : : ; xk?1 ; x ]f  p (x);

(2.5)

k [x0; : : : ; xk?1 ; x]f = f (x) ? Lk?1 (f; x);

(2.6) where Lk (f; x) denotes the solution of the interpolation problem with respect to the points x , j j  k . Let me remark here that in special cases the nite di erence takes a very familiar form. For instance, when d = 1 we have n [x0; : : : ; xn?1 ; x]f = f [x0; : : : ; xn?1 ; x]  (x ? x0 )    (x ? xn );

the usual divided di erence of f \without division". In the case that x = , j j  n, we have k [x0; : : : ; xk?1 ; x ]f =  f (0); j j = k; k = 0; : : : ; n; 3

Compiled June 3, 1996

Computational Aspects of Interpolation

where  is the n{th degree cardinal forward di erence of f de ned recursively as 0f (x) = f (x); =  f (x + ei) ?  f (x);

 +ei f (x)

1  i  d;

x 2 Rd :

This special case is considered in [4]. In general, to give a representation of the di erence operator (and thus by formula (2.6) of the error of interpolation) in terms of derivatives, we need further notation. We denote a subset of lattice vectors by n

n :=  = (0; : : : ; n ) : i 2 Nd0 ; jij = i; i = 0; : : : ; n

o

and associate to each  2 n the path x = fx0 ; : : : ; xn g:

Note that x is a set of points in Rd while xi is a vector of points. Any index set  2 n corresponds to a subset of interpolation points that contains exactly one point on each of the levels xi, i = 0; : : : ; n. The name \path" is motivated by the image that one travels from x(0;:::;0) to some point x , j j = 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 Dxn := Dxn ?xn?1 Dxn?1 ?xn?2    Dx1 ?x0 ;  2 n :

We also require

 (x ) :=

nY ?1 i=0

pi (xi+1 );  2 n :

Then the representation formula for any (n + 1) times di erentiable function f reads as f (x) ? Ln (f; x) = n+1 [x0; : : : ; xn ; x]Zf X pn (x) (x ) d Dx?xn Dxn f (y )M (y jx; x)dy; = R 2n

(2.7)

where M (  jx ; x) denotes the simplex spline (distribution) with the knots x0 ; : : : ; xn ; 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 di erent bases for polynomials, namely the monomial basis and the Bernstein{Bezier basis. 4

Compiled June 3, 1996

Computational Aspects of Interpolation

Let us rst consider monomial representation of polynomials. A polynomial p 2 dn can be written as X p(x) = c x ; c 2 R; j j  n: (3.1) j jn the rnd coecients c , j j

Thus, if we want to store all = n, in a vector of length rnd , 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 ne1 ; (n ? 1)e1 + e2 ; : : : ; (n ? 1)e1 + ed; (n ? 1)e1 ; : : : ; ned ; (n ? 1)ed ; : : : ; ed ; 0;

while the latter ordering looks like 0; e1; : : : ; ed; 2e1; e1 + e2; : : : ; 2ed; : : : ; ne1; : : : ; ned; : : : ; 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 (3.1) 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 rnd 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 e ort 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  rnd ? 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, multiplication 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 di erent degrees let p(x) =

X

j jn1

c x ;

q (x) =

X

j jn2

b x ;

and assume that n1  n2. Then p + q has the representation p(x) + q (x) =

X

j jn2

a x ;

(

where a = c b+ b n j< jj j n1 n : 1 2 5

Compiled June 3, 1996

Computational Aspects of Interpolation

In other words, we compute

(

[ ] + b[i]; 0 < i < rnd1 ; b[i]; rnd 1  i < rnd 2 ; where the values rnd1 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 (3.1), into   p(x) = 1    1 (1 pn (^x) + pn?1 (^x))    + p0 (^x); where x^ = (2; : : : ; d), [ ]=

ai

pi (^x) =

ci

x c i ; i = 0; : : : ; n; j jn?i; 1 =i 1 X

and the polynomials pi 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 pn (^x) = cne1 = c 0 and since pi 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 e ort to compute the indices explicitly. A second way to represent polynomials is by means of the Bernstein{Bezier basis which relies on the barycentric coordinates of a point with respect to a given simplex. Recall that whenever d +1 points v0; : : : ; vd 2 Rd are in general position (i.e., the simplex [v0; : : : :vd] has dimension d), we can write each point x 2 Rd as x=

d X i=0

i (x)v i;

where

d X i=0

i (x) = 1:

The vector (x) = ( 0(x); : : : ; d (x)) is called the barycentric coordinates of x with respect to the simplex [v0; : : : ; vd]. Given any multiindex = ( 0; : : : ; d) 2 Nd0+1 (the indices start with zero here!), we de ne the Bernstein{Bezier basis polynomial B (x) as ! j j! (x) 0    (x) d : j j

(x) = B (x) = d 0 !    d ! 0 6

Compiled June 3, 1996

Computational Aspects of Interpolation

Any polynomial p 2 dn can be written as X p(x) = c B (x);

(3.2)

j j=n

which is usually called the BB{representation of p. Unfortunately the BB{representation does not provide a nested basis. That is, the collection of polynomials fB : j j  ng is not a subset of fB : j j  n +1g. Nevertheless we may convert (3.2) to a BB{representation of degree n +1 by the degree raising formula p(x) =

X

j j=n+1

c^ B (x); where c^ =

d X

i

i=0 n + 1

c ?ei ; j j = n + 1:

(3.3)

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 e ort for indexing is unavoidable. Moreover, if we want to add two polynomials p and q of degree n1 and n2 with n1 < n2, say, we rst have to apply (n2 ? n1){fold degree raising to p and then perform the addition. Point evaluation of polynomials in BB{representation is performed in the de Casteljeau algorithm by computing the numbers c =

d X i=0

i (x)c +ei ;

j j = n ? 1; n ? 2; : : : ; 0;

we end up with c0 = p(x). Note that here again the coecients are accessed several times. Comparing the two representations we see that the computational e ort is signi cantly higher for the BB{representation. Indeed, rst, all operations in BB{representation require access to indexing operations, second, addition of polynomials of di erent degree is a costly operation since it has to use degree raising and, third, the de Casteljeau algorithm involves O(nd+1 ) operations while both evaluation schemes for the monomial basis are satis ed with O(nd ) operations. The inferior performance suggested from these considerations will be veri ed by the outcome of the tests, but the BB{representation will pay back some of the computational e ort by a signi cant decrease of roundo errors if the evaluations are chosen to be inside the unit simplex.

4 Algorithms In this section we brie y recapitulate the two algorithms for the computation of the fundamental polynomials given in [3] and give variations thereof. Moreover, we also describe an ecient scheme to compute the nite di erences since a direct use of the recurrence relations (2.5) is not practical. The algorithms computing the fundamental polynomials have already been introduced in [3]; they are repeated here in a slightly modi ed form { in fact they are in principal 7

Compiled June 3, 1996

Computational Aspects of Interpolation

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 multiindices 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 Gram{Schmidt orthogonalization method: Algorithm 4.1. (Lagrange fundamental polynomials)

Input: N 2 N, N = rnd and x0; : : : ; xN ?1 2 Rd. for i = 0; : : : ;iN ? 1 do q i := x ;

done; for i = 0; : : : ; N ? 1 do for j = i; : : : ; N do if j = N then stop: No solution if q j (xi) =6 0 then break; done;q j

; ;

q= ; q j (xi) q j = q i ; q i = q ; x i = xi ; for j j  n, 6= i do q = q ? q (x i )q i ;

done; done; Output: Lagrange fundamental polynomials q 2 dn and points x , j j  n. j

It is easily seen that for i = 0; : : : ; N ? 1 this algorithm always takes the rst index  i such that q j (xi) 6= 0. Since we divide by this quantity, its absolute value should

be as large as possible. For this reason we use a slightly modi ed version of Algorithm 4.1 which incorporates a pivoting strategy: Algorithm 4.2. (Lagrange fundamental polynomials with pivoting)

Input: N 2 N, N = rnd and x0; : : : ; xN ?1 2 Rd. for i = 0; : : : ;iN ? 1 do q i := x ;

done; for i = 0; : : : ; N ? 1 do vmax = 0;

8

Compiled June 3, 1996

Computational Aspects of Interpolation

jmax = i; for j = i; : : : ; N do if jq j (xi)j > jvmaxj then vmax = q j (xi); jmax = j ;

; done; if vmax = 0

then stop: No solution

j = jmax ; qj q= ; q j (xi) q j = q i ; q i = q ; x i = xi ; for j j  n, 6= i do q = q ? q (x i )q i ;

;

done; done; Output: Lagrange fundamental polynomials q 2 dn and points x , j j  n. Notice that in both cases the algorithm proceeds \point-by-point" (the i{loop is indexed 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 2 N, N = rnd and x0; : : : ; xN ?1 2 Rd. for i = 0; : : : ;iN ? 1 do p i := x ;

done; for i = 0; : : : ; N ? 1 do for j = i; : : : ; N do if j = N then stop: No solution if p i (xj ) 6= 0 then break; done; x i = xj ;

9

; ;

Compiled June 3, 1996

Computational Aspects of Interpolation

xj = xi; p i p i = ; p i (x i ) for j ij  j j  n do p = p ? p (x i )p i ;

done; done; Output: Newton fundamental polynomials p 2 dj j and points x , j j  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 j j. 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 signi cantly 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 (2.5) is extremely slow and thus of no practical use. To overcome this drawback, let us introduce a triangular scheme which computes the coecients of the interpolating polynomial more eciently. For that purpose, let f 2 C (Rd) be given and consider the scheme Ln = (` )j jn, initialized by `0 = f (x );

j j = n:

Notice that `00 already has the value 0 [x0]f = f (x0). Next, we compute `1 , j j = 1, as `1 = 1 [x0; x ]f = 0 [x ]f ? 0 [x0]f  p0 (x ) = `0 ? `00 p0 (x ):

Applying this to all 1  j j  n, we obtain `10 = 0 [x0]f; `1 = `0 ? `00 p0 (x ) = 1 [x0; x ]f; 1  j j  n:

Proceeding inductively, let us assume that for some 1  k < n the scheme already contains `k = j j [x0; : : : ; xj j?1 ; x ]f; j j  k `k = k [x0; : : : ; xk?1 ; x ]f; k < j j  n: 10

Compiled June 3, 1996

Computational Aspects of Interpolation

We set `k +1 = `k if j j  k and compute for j j > k `k +1 = k+1 [x0 ; : : : ; xk ; x ]f X = k [x0; : : : ; xk?1; x ]f ? k [x0; : : : ; xk?1 ; x ]f p (x )

= `k ?

X

j j=k?1

Thus, our scheme nally gives

Ln =

`k p (x ):

j j=k?1





j j [x0; : : : ; xj j?1; x ]f j jn :

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 di erences in an ecient way: Algorithm 4.4. (Finite Di erences)

Input: Points x , Newton fundamental polynomials p , j j  n, and a function f . for j j  n do ` = f (x ); done; for k = 1; : : : ; n do for j j  k do X ` = ` ? ` p (x ); j j=k?1 done; done; Output: ` = j j[x0; : : : ; xj j?1; x ]f , j j  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 ), j j < j j, in some matrix instead of repeatedly evaluating the polynomials, each of which requires O(rjd j) 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 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: 11

Compiled June 3, 1996

Computational Aspects of Interpolation 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 computed 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 sdj = rjd ? rjd?1 be the number of monomials of degree equal to j , j = 0; : : : ; n, then for any k = 0; : : : ; n there are sdk polynomials of degree k which need rkd coecients. Thus, for the storage of the Newton fundamental polynomials we need n 2

 N2

X d d s k rk k=0

oats. If we also want to store the values p (x ), j j < j j  n, then on each level k, 0  k  n ? 1 there are sdk polynomials each of which requires sdk+1 +    + sdn evaluations at higher level points. Therefore we have to provide memory for nX ?1 n X d sk sdj k=0 j =k+1

additional oats. Taking into account that rkd + sdk+1 +    + sdn = rnd = N , we obtain a total memory requirement for the Newton method with the additional storage of the factors in the triangular scheme of n nX ?1 n X X sdk rkd + sdk sdj k=0 k=0 j =k+1

=

nX ?1 sdk rnd + sdn rnd k=0

= N2

oating point numbers. This means, that even with the storage of the values needed in the triangular scheme for the di erence, the Newton method is not more expensive in memory consumption than the Lagrange method. 12

Computational Aspects of Interpolation

Compiled June 3, 1996

5 Numerical results The tests which are used for the comparison of the di erent methods will be organized as follows: given some test function f 2 C (Rd), 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

jf (x ) ? Ln (f; x )j ; j j  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 2n in any of the cases, and therefore the Lagrange interpolation problem cannot be poised in some 2n, this does inot cause serious problems. We will just interpolate with the subspace spanned by x , i = 0; : : : ; N ? 1 which lies between dj N ?1j?1 and dj N ?1j. 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 signi cant since we ran a lot of test suites with di erent 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 1 2 1 2 f (x; y ) = e?8((x? 2 ) +(y? 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 of the Lagrange method is much more a ected 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 e ort of any single evaluation increases, too. On the other hand, the 13

Compiled June 3, 1996

Computational Aspects of Interpolation

# points 25 50 100 150 200 300 400 500

worst 4.463319e-08 1.761731e-06 9.742520e-02 2.299013e+01 4.149814e+02 1.446600e+03 2.126242e+04 1.101068e+06

Lagrange mean 2.123451e-10 2.233217e-08 2.062384e-04 6.277672e-02 1.666190e+00 7.915207e+00 6.598622e+01 1.692285e+03

time 0.050 0.226 1.189 3.311 7.03 20.38 47.81 98.56

worst 5.013276e-08 5.674630e-08 3.134884e-06 2.180735e-04 9.798922e-05 4.907759e-05 1.672096e-03 1.296537e-04

Newton mean 1.576476e-10 3.698732e-10 2.371369e-08 4.152404e-07 7.789570e-07 4.910136e-07 5.840814e-06 5.381342e-07

time 0.025 0.115 0.574 1.692 3.41 10.20 22.85 43.26

Table 1: Lagrange and Newton method applied to f = e?8((x?1=2)2+(y?1=2)2)

# points 25 50 100 150 200 300 400 500

worst 3.018431e-10 1.711860e-07 1.625578e-03 5.495008e+00 1.254138e+01 6.081160e+04 2.921581e+04 1.424773e+05

Lagrange mean 4.349764e-12 1.014681e-09 8.977995e-06 9.360874e-03 2.622521e-01 2.667516e+02 2.543345e+02 1.083359e+03

time 0.053 0.283 1.705 5.050 11.84 34.86 88.16 208.35

worst 3.000489e-11 4.772637e-09 6.583254e-07 9.698928e-06 1.072316e-05 1.656613e-05 2.418902e-04 3.558768e-05

Newton mean 4.140634e-13 2.002858e-11 2.160971e-09 4.057631e-08 1.646272e-07 1.761121e-07 7.385581e-07 3.688244e-07

time 0.026 0.123 0.629 1.775 3.76 11.30 25.40 48.07

Table 2: Lagrange and Newton method with pivoting applied to f = e?8((x?1=2)2+(y?1=2)2) search for maximumin the computation of the Newton fundamental polynomials evaluates the polynomial at di erent points, i.e., the e ort for a single evaluation remains constant. 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 that's 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 ) = jx ? y j;

which is known to be very unfriendly to interpolation. Table 3 shows the e ect of this function on the robustness of the Newton method which is now of the same order of magnitude. 14

Compiled June 3, 1996

Computational Aspects of Interpolation

# points 25 50 100 150 200 300 400 500

Lagrange worst mean 6.384678e-08 2.208463e-10 3.761145e-06 2.048795e-08 5.650217e-02 2.833983e-04 6.863485e+01 1.689310e-01 1.585731e+02 9.668451e-01 1.021281e+03 6.622473e+00 3.074677e+03 2.381371e+01 2.859273e+05 4.280414e+02

Newton worst mean 6.349903e-08 2.040262e-10 3.762834e-06 1.324844e-08 5.630920e-02 2.361960e-04 6.856829e+01 1.663155e-01 5.347714e+01 5.921686e-01 1.095193e+03 6.131108e+00 8.510057e+03 4.445905e+01 6.850754e+04 1.338527e+02

Table 3: Lagrange and Newton method applied to f (x; y) = jx ? yj Let us try to interpret this behavior of the interpolation algorithms. Clearly, the smoothness of the interpolated function can hardly a ect the Lagrange method. For the Newton method, however, formula (2.7) hints that for smooth functions with fairly rapidly decreasing values of the derivatives the di erences n [x0; : : : ; xn?1; 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 Ln (f; x) = Ln?1 (f; x) +

X

j j=n

(f (x ) ? Ln?1(f; x )) p (x);

(5.1)

visualizes the connection between convergence and robustness: if Ln 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 Ln f does not converge to f or even diverges to in nity, then polynomials of high degree will contribute strongly and cause severe roundo errors. As it can be seen from the function jx ? yj 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 in uence the quality of the interpolant quite signi cantly. To give some numerical evidence of this phenomenon, let us consider the truncated powers (

(x ? y)k ; x > y; ; = + 0; xy

(x ? y)k

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. 15

Compiled June 3, 1996

Computational Aspects of Interpolation

function (x ? y )0+ (x ? y )1+ (x ? y )2+ (x ? y )3+ (x ? y )4+ (x ? y )5+ (x ? y )6+ (x ? y )7+ (x ? y )8+ (x ? y )9+ (x ? y )10 + (x ? y )11 + (x ? y )12 + (x ? y )13 + (x ? y )14 + (x ? y )15 +

worst 1.414161e+04 2.306302e+02 5.711645e+00 6.327744e-01 4.419375e-02 1.386771e-02 1.386838e-03 7.082329e-04 8.876935e-05 7.252913e-05 1.324360e-05 1.388975e-05 4.363844e-06 4.803590e-06 2.595656e-06 3.119068e-06

mean 3.424847e+01 5.885873e-01 2.686329e-02 2.285044e-03 2.499046e-04 4.013625e-05 7.848432e-06 1.852051e-06 5.685933e-07 1.818965e-07 8.374641e-08 3.676999e-08 2.402691e-08 1.398927e-08 1.368125e-08 1.028765e-08

Table 4: Truncated powers at 200 points

6 Bernstein{Bezier representation { a change of basis and region Since Algorithms 4.1 and 4.3 apply only vector space operations and point evaluation to polynomials in dn, the basis used by the class polynomial has no in uence on the algorithms themselves. Thus it is reasonable to try other bases in order to obtain better results, for example the Bernstein{Bezier representation. The drawback of this basis, however, is its reduced eciency. Not only the evaluation algorithm requires greater e ort, also addition of polynomials is more expensive in most cases. Since we therefore can expect our algorithms to run signi cantly slower, the BB{representation 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 S2 which is the \home domain" of the Bernstein{Bezier 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 Bernstein{Bezier basis to interpolate 1 2 1 2 f (x; y ) = e?8((x? 2 ) +(y? 2 ) ) (6.1) 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 S2 where the computations based on the 16

Compiled June 3, 1996

Computational Aspects of Interpolation

# points worst 25 4.153078e-08 1.083748e-10 50 7.442618e-07 1.042958e-07 100 1.442830e-02 1.208056e-04 150 3.143096e+01 1.642021e-01 200 7.005735e+02 8.948881e+00 300 3.189365e+05 3.495457e+06 400 1.719140e+06 1.289018e+09 500 2.826352e+07 6.314407e+09

Lagrange mean 4.381949e-11 1.309538e-12 1.650317e-09 2.489006e-10 1.158003e-05 4.729123e-07 8.127532e-03 3.686560e-04 9.282342e-01 2.188881e-02 1.729660e+02 1.350418e+03 2.277616e+03 3.750547e+05 1.943249e+04 8.461617e+06

time 0.143 0.148 0.936 1.120 6.387 9.778 21.733 30.030 53.47 85.06 184.59 299.19 503.76 848.98 1177.89 2057.78

worst 4.230155e-08 6.192943e-11 2.733975e-07 3.148098e-08 2.537013e-05 9.677265e-06 5.713038e-03 3.084068e-04 1.608834e-02 4.664504e-03 9.516154e-03 1.056081e-02 1.006455e-02 6.423332e-02 1.106003e-01 8.235633e-03

Newton mean 3.968871e-11 2.049121e-13 2.671148e-10 2.221031e-11 2.599283e-08 5.352320e-09 2.192207e-06 2.498247e-07 8.909492e-06 3.710750e-06 8.805335e-06 1.034365e-05 6.551872e-06 3.150639e-05 6.435752e-05 2.226675e-05

time 0.081 0.085 0.520 0.538 4.425 4.992 13.873 15.845 35.46 40.61 136.59 157.58 362.45 418.94 775.97 894.82

Table 5: Bernstein{Bezier basis on the square. monomial basis show signi cantly less accuracy than on the unit square (see Table 6), regardless whether one uses pivoting or not. Using the Bernstein{Bezier 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), 705{727. [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.

17

Compiled June 3, 1996

Computational Aspects of Interpolation

# points worst 25 2.595999e-08 1.074825e-09 50 3.637496e-03 8.149359e-06 100 5.306237e+00 2.020826e+00 150 4.290398e+03 8.264331e+02 200 1.397175e+04 9.590505e+02 300 1.260878e+06 1.727911e+06 400 2.333500e+06 1.031858e+05 500 8.841285e+06 1.066711e+06

Lagrange mean 3.506247e-10 2.290780e-11 5.572239e-06 4.233035e-08 1.964924e-02 2.971576e-03 2.879124e+00 5.689910e-01 4.095677e+01 4.029076e+00 1.249520e+03 1.184524e+03 4.685404e+03 4.051350e+02 6.011905e+03 2.297083e+03

time 0.049 0.050 0.224 0.271 1.340 1.806 3.277 4.721 7.03 11.26 20.40 32.83 47.74 84.17 98.23 195.83

worst 2.285563e-10 1.533060e-11 1.359431e-07 4.207358e-09 1.418371e-05 1.117948e-06 9.530273e-05 5.619064e-07 1.851206e-05 2.789856e-06 1.615770e-04 1.275465e-04 2.794906e-02 2.093549e-02 3.430555e-02 9.312563e-03

Newton mean 2.280260e-12 2.845596e-13 4.865755e-10 2.234978e-11 3.573037e-08 5.123820e-09 7.940892e-08 2.356249e-09 9.712912e-08 1.478546e-08 4.271359e-07 7.152282e-07 2.483787e-05 2.071717e-05 4.103941e-05 1.625316e-05

time 0.026 0.027 0.115 0.123 0.621 0.657 1.599 1.760 3.38 3.75 10.21 11.30 22.85 25.38 43.29 48.11

Newton mean 6.702319e-14 1.601193e-14 6.084635e-12 4.031219e-13 2.191867e-10 2.908022e-11 6.833958e-11 9.066702e-11 9.645799e-12 3.069413e-11 3.971020e-11 2.897659e-11 2.703590e-10 2.067182e-08 3.407266e-08 5.611746e-08

time 0.080 0.086 0.493 0.541 4.520 4.801 13.893 15.843 35.47 40.61 136.63 157.57 385.10 419.06 772.19 894.65

Table 6: Monomial basis on the simplex.

# points worst 25 5.348628e-10 7.016343e-11 50 1.514022e-06 9.387515e-09 100 1.205453e-04 8.842270e-06 150 1.196788e-01 4.799341e-03 200 7.178328e-02 7.809762e-02 300 2.762541e+02 7.957496e+02 400 3.897538e+04 1.208065e+05 500 6.920784e+06 4.037479e+06

Lagrange mean 6.441988e-12 9.325487e-13 5.204759e-09 1.309740e-10 9.340927e-07 1.051278e-07 1.128211e-04 1.793391e-05 7.012317e-04 7.424870e-04 6.919600e-01 2.732732e+00 6.350886e+01 3.404518e+02 5.978468e+03 7.611616e+03

time 0.141 0.154 0.881 1.050 6.404 9.158 20.556 29.150 53.49 83.56 184.51 293.39 570.28 884.46 1178.17 2152.51

worst 4.802492e-12 4.139064e-12 5.660951e-09 1.023810e-10 9.607325e-08 2.442366e-08 3.381104e-08 4.455833e-08 8.678002e-10 3.764280e-09 9.583710e-09 2.640019e-09 1.234486e-07 9.571587e-06 2.468131e-05 4.447331e-05

Table 7: Bernstein{Bezier basis on the simplex. 18