Barycentric Lagrange Interpolation
4.2.3 Barycentric Lagrange Interpolation
Lagrange’s interpolation formula was introduced in Sec. 4.1.2. For distinct real interpolation points x i , i = 1 : n, this formula uses the cardinal basis of P n consisting of the Lagrange polynomials of degree n − 1:
with the property that
Quite often it is asserted that the Lagrange form is a bad choice for practical compu- tations, 130 since for each new value of x the functions ℓ j (x) have to be recomputed at a cost O(n 2 ) . Further, adding a new data point x n +1 ,f n +1 will require a new computation from scratch. Therefore, it is concluded that Lagrange’s formula is not as efficient as Newton’s interpolation formula.
The above assertions are, however, not well-founded. The Lagrange representation can easily be rewritten in two more attractive forms which are both eminently suitable for computation ; see Rutishauser [312] and Berrut and Trefethen [24]. The key idea is to take out the common factor M n (x) in (4.1.15) and introduce the support coefficients
130 “For actual numerical interpolation Lagrange’s formula is, however, as a rule not very suitable.” (Stef- fensen [330, p. 25].)
368 Chapter 4. Interpolation and Approximation The Lagrange polynomials can then be written as
ℓ j (x) =M n (x)
x −x j
Taking out the common factor gives the modified form of Lagrange’s interpolation formula:
p(x) j =M
Here w j depend only on the given points x j , j = 1 : n, and can be computed in 2(n − 1) flops. This is slightly more than the 3 2 n(n − 1) flops required to compute the divided differences for Newton’s interpolation formula. Then, to evaluate p(x) from (4.2.29) for a new value of x we only need to compute M n (x) and w j /(x −x j ) , j = 1 : n, which just requires O(n) operations.
The product factor M n (x) in (4.2.29) can be eliminated as follows. Since the interpo- lation formula is exact for f (x) ≡ 1, we have
Substituting this in (4.2.29),
f (x j )
−x j
p(x) =
j , j = 1 : n, (4.2.30)
w j j =1 x −x j
which is the barycentric form of Lagrange’s interpolation formula. This expresses the value p(x) as a weighted mean of the values f i . (Note that the coefficients w j /(x −x j ) need not be positive, so the term “barycentric” is not quite appropriate.)
The barycentric formula (4.2.30) has a beautiful symmetric form and is “eminently suitable for machine computation” (Henrici [195, p. 237]). Unlike Newton’s interpolation formula, it does not depend on how the nodes are ordered. The numerical stability of the two modified Lagrange interpolation formulas is, contrary to what is often stated, very good. Note that the interpolation property of p(x) is preserved even if the coefficients w i are perturbed, but then p(x) is usually no longer a polynomial but a rational function.
There seems to be a stability problem for the formula (4.2.30) when x is very close to one of the interpolation points x i . In this case w i /(x −x i ) will be very large and not accurately computed because of the cancellation in the denominator. But this is in fact no problem, since there will be exactly the same error in the denominator. Further, in case
4 i = fl (x − x i ) is exactly zero, we can simply put 4 i = u, where u is the unit roundoff; see Theorem 2.2.2. The barycentric form of Lagrange’s interpolation formula can be as efficiently updated as Newton’s formula. Suppose the support coefficients w (k −1)
, i = 1 : k − 1, for the points x 1 ,...,x k −1 are known. Adding the point x k , the first k − 1 new support coefficients can
be calculated from
w (k
(k)
=w −1) i /(x i −x k ), i = 1 : k − 1,
4.2. Interpolation Formulas and Algorithms 369
k using (k − 1) divisions and subtractions. Finally we have w −1
i =1 (x k −x i ) . The computation of the support coefficients is summarized in the following program:
(k)
% Compute support coefficients w(1) = 1; for k = 2:n
w(k) = 1; for i = 1:k-1
w(i) = w(i)/(x(i) - x(k)); w(k) = w(k)/(x(k) - x(i));
end end
Note that the support coefficients w i do not depend on the function to be interpolated. Once they are known interpolating a new function f only requires O(n) operations. This contrasts favorably with Newton’s interpolation formula, which requires the calculation of
a new table of divided differences for each new function. Suppose that we use interpolation points in an interval [a, b] of length 2C. Then as
n → ∞ the scale of the weights will grow or decay exponentially at the rate C −n . If n is large or C is far from 1, the result may underflow or overflow even in IEEE double precision. In such cases there may be a need to rescale the support coefficients.
The computation of the support coefficients can be done in only n(n−1) flops by using n the relation (see Problem 4.2.5 and [318, Sec. 3.2.1])
i =1 w i = 0, n > 1, to compute w n
i =1 w i . But using this identity destroys the symmetry and can lead to stability problems for large n. Serious cancellation in the sum will occur whenever max i |w i | is
much larger than |w n |. Hence the use of this identity is not recommended in general. Theorem 4.2.6 (Higham [200]).
Assume that x i ,f i , and x are floating-point numbers. Then the computed value ˜p(x) of the interpolation polynomial using the modified Lagrange formula (
4.2.29) satisfies
5(n+1)
p(x) ˜ =M n (x)
where |δ ij | ≤ u. Thus the formula (
4.2.29) computes the exact value of an interpolating polynomial corresponding to slightly perturbed function values f (x i ). Hence this formula is backward stable in the sense of Definition 2.4.10.
The barycentric formula is not backward stable. A forward error bound similar to that for the modified formula but containing an extra term proportional to n
j =1 |ℓ j (x) | can be shown. Hence the barycentric formula can be significantly less accurate than the
modified Lagrange formula (4.2.29) only for a poor choice of interpolation points with a large Lebesgue constant X n .
For various important distributions of interpolating points, it is possible to compute the support coefficients w i analytically.
370 Chapter 4. Interpolation and Approximation
Example 4.2.4.
For interpolation at the equidistant points x 1 ,x i =x 1 + (i − 1)h, i = 2 : n, the support coefficients are
In the barycentric formula (4.2.30) a common factor in the coefficients w i cancels and we may use instead the modified support coefficients
i +1 n −1 w i = (−1)
For a given n these can be evaluated in only 2n operations using the recursion w ∗ = n − 1,
w i 1 ∗ =w ∗ n −i i −1 , i = 2 : n.
Example 4.2.5.
Explicit support coefficients are also known for the Chebyshev points of the first and second kind on [−1, 1]. For the Chebyshev points of the first kind they are
( 2i − 1) π
2i − 1)
w i = (−1) sin
i = cos
, i = 1 : n. (4.2.33)
For the Chebyshev points of the second kind they are
(i
i = (−1) δ j ,
where δ j = 1/2 if i = 1 or i = n, and 1 otherwise. Note that all but two weights are equal. This will be considered from another point of view in Sec. 4.6.
For an interval [a, b] the Chebyshev points can be generated by a linear transformation. The corresponding weight w i then gets multiplied by 2 n (b
− a) n . But this factor cancels out in the barycentric formula, and there is no need to include it. Indeed, by not doing so
the risk of overflow or underflow, when |b − a| is far from 1 and n is large, is avoided. The two examples above show that with equidistant or Chebyshev points only O(n)
operations are needed to get the weights w i . For these cases the barycentric formula seems superior to all other interpolation formulas.
Lagrange’s interpolation formula can be used to compute the inverse of the Vander-
= W = (w n ij ) i,j =1 , then WV = I , the ith row of which can be written
monde matrix V in (4.1.5) in O(n 2 ) operations. If we set V −1
ij x k =δ ik , k = 1 : n.
j =1
4.2. Interpolation Formulas and Algorithms 371 This is an interpolation problem that is solved by the Lagrange basis polynomial
Clearly V is nonsingular if and only if the points x i are distinct. The elements w ij in inverse Vandermonde matrix W = V −1 can be computed as follows: First compute the coefficients of the polynomial
This can be done by the following MATLAB script: % Compute inverse Vandermonde matrix
a(1) = -x(1); a(2) = 1; for k = 2:n
a(k+1) = 1; for j = k:-1:2
a(j) = a(j-1) - x(k)*a(j); end a(1) = -x(k)*a(1);
end Then compute the coefficients of the polynomials
q i (x) =M n (x)/(x −x i ), i = 1 : n,
by synthetic division (see Sec. 1.2.2). By (4.2.35) the n 2 elements in W equal the coefficients of the Lagrange polynomials
ℓ i (x) =q i (x)/q i (x i ), i = 1 : n.
Here the scalars q i (x i ) are computed by Horner’s rule. The cost of computing the n 2
elements in W by this algorithm is only 6n 2 flops.