lunes, 28 de noviembre de 2022

Chebyshev polynomials and interpolation

https://drlvk.github.io/nm/section-chebyshev-polynomials-interpolation.html

Chebyshev polynomials and interpolation


22.2 Chebyshev polynomials and interpolation

In Chapter 15 we studied Legendre polynomials Pn which are orthogonal on the interval [1,1] in the sense that 11Pn(x)Pk(x)dx=0 when nk. We also use Laguerre polynomials Ln which are orthogonal on [0,) with the weight function ex, meaning that 11Ln(x)Lk(x)exdx=0 when nk. The Chebyshev polynomials Tn are orthogonal on the interval [1,1] with the weight function 1/1x2, meaning that

11Tn(x)Tk(x)dx1x2=0when nk

As for other families of orthogonal polynomials, we have a recursive formula for Chebyshev polynomials: starting with T0(x)=1 and T1(x)=x we can compute the rest as

(22.2.1)Tn+1(x)=2xTn(x)Tn1(x)

The recursion is simpler than for Pn or Ln: there is no division, so all polynomials Tn have integer coefficients.

Example 22.2.1 indicates that Chebyshev polynomials oscillate between 1 and 1 on the interval [1,1]. The following remarkable identity confirms this observation:

Example 22.2.1. Plot Chebyshev polynomials Tn. 
 

Recursively find the coefficients of Chebyshev polynomials Tn for n6. Plot all of them on the interval [1,1].

This is a straightforward modification of Example 15.4.1.

p = [1];
q = [1 0];
x = linspace(-1, 1, 1000);
hold on
plot(x, polyval(p, x), x, polyval(q, x));

for n = 1:5
    r = 2*[q 0] - [0 0 p];
    p = q;
    q = r;
    plot(x, polyval(r, x))
end
hold off
in-context
(22.2.2)Tn(cosθ)=cos(nθ)

for all θR. The proof is by induction. Base of induction is n=0,1: for T0(x)=1 and T1(x)=x the validity of (22.2.2) is obvious. For the inductive step, assume (22.2.2) holds for T0,,Tn and use (22.2.1):

(22.2.2)Tn(cosθ)=cos(nθ)
in-context
Tn+1(cosθ)=2cosθcos(nθ)cos((n1)θ)=cos((n+1)θ)

where the second step involves the identity

2cosαcosβ=cos(αβ)+cos(α+β)

The right hand side of (22.2.2) is zero when nθ is an odd multiple of π/2, hence θ=(2k1)π2n. Plugging k=1,,n we find that

(22.2.2)Tn(cosθ)=cos(nθ)
in-context
(22.2.3)Tn(x)=0when x=cos((2k1)π2n), k=1,,n

and since the polynomial Tn can have at most n real roots, these are all of its roots. They are easy to visualize: draw a semi-circle with interval [a,b] as diameter, divide it into n equal arcs, and project the midpoint of each arc back to the interval.

Figure 22.2.2. Chebyshev points of the first kind

The recursive formula shows that the leading coefficient of Tn is 2n1. Therefore,

Tn(x)=2n1k=1n(xxk)

where x1,,xn are the roots (22.2.3). It follows that the absolute value of the product k=1n(xxk) is bounded by 21n. It can be proved that 21n is as small as one can get for any choice of n points on the interval [1,1]. This suggests that Chebyshev points should work well for polynomial interpolation, and they do. Let us re-do Example 21.2.2 with random data to illustrate this.

Example 21.2.2. Plot the Lagrange polynomial through 10 points. 
 

Plot the Lagrange polynomial each of the following data sets:

  1. the points (k,sink), k=1,,10;
  2. the points with xk as above, and yk chosen randomly from the standard normal distribution.
n = 10;
x = 1:n;
y = sin(x);  % or y = randn(1, n);
w = ones(1, n);
for k = 1:n
    for j = 1:n
        if j ~= k
            w(k) = w(k)/(x(k)-x(j));
        end
    end
end

p = @(t) (y.*w*(t - x').^(-1)) ./ (w*(t - x').^(-1));
t = linspace(min(x)-0.01, max(x)+0.01, 1000);
plot(t, p(t), x, y, 'r*')

The double loop computes the weights w which do not involve the argument of the interpolating polynomial p. This argument is called t because x is already used for the data points. The interval for plotting is chosen to contain the given x-values with a small margin on both sides: this helps both visualization and evaluation, because we avoid plugging in t=x1,xn. The barycentric evaluation of the polynomial is vectorized. When t is a scalar, t - x' is a column vector. Taking reciprocals element-wise gives another column vector. Dot-product with w or y.*w implements the sums such as k=1nwk/(txk).

How does p accept a row vector as t? The expression t - x' is the difference of a row vector and a column vector; in Matlab this creates a matrix where (i,j) entry is tjxi. Subsequent operations proceed as above, and the result is a row vector of values p(t).

in-context
(22.2.3)Tn(x)=0when x=cos((2k1)π2n), k=1,,n
in-context

Running the code Example 22.2.3 several times, we see that the interpolating polynomial behaves reasonably, without unnatural oscillations that come from interpolating at equally spaced points.

Example 22.2.3. An interpolating polynomial using Chebyshev points. 
 

Let x1,,x10 be the roots of T10. Choose yk randomly from the standard normal distribution, and draw the interpolating polynomial through the points (xk,yk).

The only change to Example 21.2.2 is replacing the x-coordinates.

n = 10;
x = cos((2*(1:n)-1)*pi/(2*n)); 
y = randn(1, n);
w = ones(1, n);
for k = 1:n
    for j = 1:n
        if j ~= k
            w(k) = w(k)/(x(k)-x(j));
        end
    end
end

p = @(t) (y.*w*(t - x').^(-1)) ./ (w*(t - x').^(-1));
t = linspace(min(x)-0.01, max(x)+0.01, 1000);
plot(t, p(t), x, y, 'r*')

No hay comentarios:

Publicar un comentario