ChebyshevPolys.mws

Linear Algebra Powertool

Polynomial Approximation - II

Legandre vs Chebyshev Polynomials

Worksheet by Mike May, S.J., maymk@slu.edu

> restart;

Overview

In the last worksheet we looked at polynomial approximation using Legandre polynomials. These polynomials form an orthogonal set with a least squares fit definition for the norm. In this worksheet we will look at other norms and the corresponding sets of orthogonal polynomials.

We begin by loading Maple's package for othogonal polynomials. We also load the plots package so that we can graph our results. We repeat the technical commands from the last worksheet.

> with(orthopoly); with(plots):
assume('i',integer): assume('j',integer):
interface(showassumed=0):

[G, H, L, P, T, U]

Warning, the name changecoords has been redefined

For the Legangre polynomials we saw that the norm is defined by <f(x), g(x)> = int(f(x)*g(x),x = -1 .. 1) . The other inner products we will look at are defined by <f(x), g(x)> = int(wtfunc(x)*f(x)*g(x),x = -1 .. 1) where wtfunc(x) is a weight function. The use of different weight functions gives us a way to make some parts of the domain more important than others. It also makes it possible to allow functions with poles into the set of functions we are trying to appoximate.

Chebyshev polynomials of the first kind

We will begin with Chebyshev polynomials of the first kind.

> ?orthopoly,T

The help page shows us that weight function of Chebyshev polynomials of the first kind is (1-x^2)^(-1/2), The effect of the weight function is to make the endpoints count more when defining what it means for function to be small.

> plot({(1-x^2)^(-1/2),1}, x=-1..1, y=0..3);

[Maple Plot]

Once we have loaded the orthopoly package, we obtain the nth Chebychev polynomial with T(n,x);

> T(3,x);

4*x^3-3*x

E xercise:

1) Find the 1st, second, and 5th Chebychev polynomials of the first kind. Verify that they are orthogonal under the oppropriate inner product.

>

An extended example, back to f(x) = sin(3*Pi*x)

Time to look at an example to see how this works out in a particular case. Once again we will use sin(3¹x) as our function.

> func := x -> sin(3*Pi*x);

func := proc (x) options operator, arrow; sin(3*Pi*...

Computing coefficients and approximating polynomials

Next we start computing coefficients. We will find the coefficients for both the Legangre polynomials and for Chebyshev polynomials of the first kind. Recall that if P(n,x) is the nth Legandre polynomial, the projection coeffient of f(x) onto P(n,x) should be int(f(x)*P(0,x),x = -1 .. 1) divided by int(P(n,x)*P(n,x),x = -1 .. 1) . Similarly, if T(n,x) is the nth Chebyshev polynomial of the first kind, the projection coefficient of f(x) onto T(n,x) is int(wtCheb(x)*f(x)*P(0,x),x = -1 .. 1) divided by int(wtCheb(x)*P(n,x)*P(n,x),x = -1 .. 1) , where wtCheb(x) = (1-x^2)^(-1/2).

> wtchev := (1-x^2)^(-1/2):
for i from 0 to 15 do
normP[i] := evalf(Int((P(i,x))^2, x=-1..1));
coeffP[i] := evalf(Int(simplify(P(i,x)*func(x)*1.0), x=-1..1));
normT[i] := evalf(Int(wtchev*(T(i,x))^2, x=-1..1));
coeffT[i] := evalf(Int(wtchev*T(i,x)*func(x), x=-1..1)):
od;

normP[0] := 2.

coeffP[0] := 0.

normT[0] := 3.141592654

coeffT[0] := 0.

normP[1] := .6666666667

coeffP[1] := .2122065907

normT[1] := 1.570796327

coeffT[1] := .5551985872

normP[2] := .4000000000

coeffP[2] := 0.

normT[2] := 1.570796327

coeffT[2] := 0.

normP[3] := .2857142857

coeffP[3] := .1763715524

normT[3] := 1.570796327

coeffT[3] := .2635803132

normP[4] := .2222222222

coeffP[4] := 0.

normT[4] := 1.570796327

coeffT[4] := 0.

normP[5] := .1818181818

coeffP[5] := -.1322273781e-1

normT[5] := 1.570796327

coeffT[5] := -.4620896712

normP[6] := .1538461538

coeffP[6] := 0.

normT[6] := 1.570796327

coeffT[6] := 0.

normP[7] := .1333333333

coeffP[7] := -.2657941222

normT[7] := 1.570796327

coeffT[7] := -.9263350154

normP[8] := .1176470588

coeffP[8] := 0.

normT[8] := 1.570796327

coeffT[8] := 0.

normP[9] := .1052631579

coeffP[9] := .1669531813

normT[9] := 1.570796327

coeffT[9] := .7906766020

normP[10] := .9523809524e-1

coeffP[10] := 0.

normT[10] := 1.570796327

coeffT[10] := 0.

normP[11] := .8695652174e-1

coeffP[11] := -.4841458486e-1

normT[11] := 1.570796327

coeffT[11] := -.2675504440

normP[12] := .8000000000e-1

coeffP[12] := 0.

normT[12] := 1.570796327

coeffT[12] := 0.

normP[13] := .7407407407e-1

coeffP[13] := .8597245012e-2

normT[13] := 1.570796327

coeffT[13] := .5294405753e-1

normP[14] := .6896551724e-1

coeffP[14] := 0.

normT[14] := 1.570796327

coeffT[14] := 0.

normP[15] := .6451612903e-1

coeffP[15] := -.1053256856e-2

normT[15] := 1.570796327

coeffT[15] := -.7062371922e-2

Now we define the approximating polynomials.

> Lapprox := proc(m,x)
local count:
sum(P(count,x)*coeffP[count]/normP[count],count=0..m):
end;
Chebapprox := proc(m,x)
local count:
sum(T(count,x)*coeffT[count]/normT[count],count=0..m):
end;

Lapprox := proc (m, x) local count; sum(P(count,x)*...

Chebapprox := proc (m, x) local count; sum(T(count,...

Comparing the approximations

Since our function has 6 bumps and looks like it could be a 7th degreee polynomial, we want to compare the 7th degree approximations. Note first that the polynomial approximations are significantly different.

> n:= 7:
Lapprox(n,x);
Chebapprox(n,x);

3.616684570*x-37.06656803*x^3+85.76884958*x^5-53.44...

2.507234281*x-26.46978826*x^3+61.34219016*x^5-37.74...

Next compare the graphs of the approximations and of the errors.

> lowy := -1.2: highy := 1.6: n:= 7:
pl1 := plot(func(x), x=-1..1,y=lowy..highy, color=red):
pl2 := plot(Lapprox(n,x), x=-1..1,y=lowy..highy, color=green):
pl3 := plot(Chebapprox(n,x), x=-1..1,y=lowy..highy, color=blue):
B := textplot({[-0.8,highy-(highy-lowy)/20,
`The function and the `||n||` term approximations`],
[-0.8,highy-(highy-lowy)/9, `Chebyshev (blue) vs Legandre (green)`]},
align=RIGHT, font = [TIMES, BOLD, 12] ):
display({pl1, pl2, pl3, B},view=[-1..1, lowy..highy]);

[Maple Plot]

As expected, the Legandre approximation tends to be better in the center of the graph, while the Chebyshev approximation tends to be better on the ends. This becomes even clearer when we look at the graphs of the errors.

> lowy := -1.0: highy := 1.4: n:= 7:
pl1 := plot(func(x) - Chebapprox(n,x), x=-1..1,y=lowy..highy, color=green):
pl2 := plot(func(x) - Lapprox(n,x), x=-1..1,y=lowy..highy, color=blue):
B := textplot({[-0.8,highy-(highy-lowy)/20,
`The `||n||` term Legandre error (blue)`],
[-0.8,highy-(highy-lowy)/9, `and Chebychev error (green)`]},
align=RIGHT, font = [HELVETICA, BOLD, 12] ):
display({pl1, pl2, B});

[Maple Plot]

It is clear that the Chebyshev approximation is better at the endpoints, for degree 7.

>

Exercises:

>

2) For the example above, approximately what is the maximum error for over the domain [-1, 1] for the 11th degree Legandre and Chebyshev approximations?

>

3) For the example above, approximately what is the maximum error for over the domain [-.5, .5] for the 11th degree Legandre and Chebyshev approximations?

>

>

Viewing the pattern of approximations

To illustrate the pattern we can do an animation of the errors produced by the polynomials.

> framererrCheb := proc(n,x, lowy, highy)
local pl1, pl2, B:
pl1 := plot(func(x) - Chebapprox(n,x),
x = -1..1, y = lowy..highy, color = green):
pl2 := plot(func(x) - Lapprox(n,x),
x = -1..1, y = lowy..highy, color = blue):
B := textplot({[-0.8,highy-(highy-lowy)/20,
`The `||n||` term Legandre error (blue)`],
[-0.8,highy-(highy-lowy)/9, `and Chebyshev error (green)`]},
align=RIGHT, font = [HELVETICA, BOLD, 12] ):
display({pl1, pl2, B});
end:

> display([seq(framererrCheb(counta,x, -1.2, 1.6), counta=1..15)], insequence = true);

[Maple Plot]

>

Exercise:

4) Explain why, with our example, the error only changes with odd degree approximations.

>

More exercises:

5) Find the 10th degree Legandre and Chebyshev polynomial approximations to sin(Pi*x)+cos(2*Pi*x). Approximately what is the maximum error for each of these polynomials? Approximately what is the error at the endpoints of the domain for each of the approximations.

>

6) Give a function that has a norm under either the Legandre or Chebyshev inner product but not under the other.

>

>