lunes, 28 de noviembre de 2022

Chebyshev Approximation and How It Can Help You Save Money, Win Friends, and Influence People

https://www.embeddedrelated.com/showarticle/152.php

Chebyshev Approximation and How It Can Help You Save Money, Win Friends, and Influence People


CHEBYSHEV POLYNOMIALS

The key to using polynomials to evaluate functions, is not to think of polynomials of being composed of linear combinations of 1,x,x2,x3, etc., but as linear combinations of Chebyshev polynomials Tn(x). As discussed in more detail in the Wikipedia page, these have the following special properties:

  • they are minimax functions over the range [1,1], e.g. all their minima/maxima/extrema are at ± 1 (see diagram below)
  • they are orthogonal over the range [1,1] with weight 11x2
  • T0(x)=1,T1(x)=x,Tn+1(x)=2xTn(x)Tn1(x)
  • Tn(x)=cos(ncos1x)

Figure: Chebyshev functions Tn(x), courtesy of Wikipedia

Let's say we have a given function f(x) over the range x[a,b]. We can express f(x)=ckTk(u) where u=2xabba and x=ba2u+a+b2, which is a transformation which maps the interval x[a,b] to u[1,1]. The problem then becomes a matter of figuring out the coefficients ck, which can be done using the Chebyshev nodes:

These are easier to understand graphically; they are merely the projections onto the x-axis of the midpoints of equal interval circular arcs of a semicircle:

You will note that the nodes are spaced equally near 0 and more compressed towards ± 1.

To approximate a function by a linear combination of the first N Chebyshev polynomials (k=0 to N-1), the coefficient ck is simply equal to A(k) times the average of the products Tk(u)f(x) evaluated at the N Chebyshev nodes, where A=1 for k=0 and A=2 for all other k.

Let's illustrate the process more clearly with an example.

Suppose f(x)=13x3+2x2+x10 over the range [1,3], with u=x12,x=2u+1:

Let's use N=5. The Chebyshev nodes for N=5 are u=0.951057,0.587785,0,+0.587785,+0.951057. This corresponds to x=0.902113,0.175571,1,2.175771,2.902113, and the function f(x) evaluated at those nodes are y=9.51921,10.11572,6.66667,5.07419,17.89408.

For c0 we compute the average value of y = (9.5192110.115726.66667+5.07419+17.89408)/5=0.66667.

For c1 we compute 2 × the average value of u × y = 2×(9.51921×0.951057+10.11572×0.587785 +6.66667×0+5.07419×0.587785+17.89408×0.951057)=14

For c2 we compute 2 × the average value of T2(u)×y=(2u21)×yc2=6

For c3 we compute 2 × the average value of T3(u)×y=(4u33u)×yc3=0.66667

For c4 we compute 2 × the average value of T4(u)×y=(8u48u2+1)×yc4=0

The conclusion here is that f(x)=23T0(u)+14T1(u)+6T2(u)+23T3(u) ; if you go and crunch through the algebra you will see that the result is the same as f(x)=13x3+2x2+x10.

So what was the point here....? Well, if you already have the coefficients of a polynomial, there's no point in using Chebyshev polynomials. (If the input range is significantly different from [1,1], a linear transformation from x to u where u[1,1] will give you a polynomial in u that has better numerical stability, and Chebyshev polynomials are one way to do this transformation. More on this later) If you want to approximate the polynomial with a polynomial of lesser degree, Chebyshev polynomials will give you the best approximation.

For example let's use a quadratic function to approximate f(x) over the input range in question. All we need to do is truncate the Chebyshev coefficients: let's computef2(x)=23T0(u)+14T1(u)+6T2(u)=23+14u+6×(2u21)=203+14u+12u2=203+7(x1)+3(x1)2=3x2+x323.

Voila! We have a quadratic function that is close to the original cubic function, and the magnitude of the error is just the coefficient of the Chebyshev polynomial we removed = 23.

You will note that these two polynomials (13x3+2x2+x10 and 3x2+x323), expressed in their normal power series form, have no obvious relation to each other, whereas the Chebyshev coefficients are the same except in coefficient c3 which we set to zero to get a quadratic function.

In my view, this is the primary utility of expressing a function in terms of its Chebyshev coefficients: The coefficient c0 tells you the function's average value over the input range; c1 tells you the function's "linearness", c2 tells you the function's "quadraticness", c3 tells you the function's "cubicness", etc.

Here's a more typical and less trivial example. Suppose we wish to approximate log2x over the range [1,2].

A decomposition into Chebyshev coefficients up to degree 6 yields the following:

c0=+0.54311c1=+0.49505c2=0.042469c3=+0.0048577c4=6.2508×104c5=+8.5757×105c6=1.1996×105



You will note that each coefficient is only a fraction of the magnitude of the previous coefficient. This is an indicator that the function in question (over the specified input range) lends itself well to polynomial approximation. If the Chebyshev coefficients don't decrease significantly by the 5th coefficient, I would classify that function as "nonpolynomial" over the range of interest.

The maximum error for the 6th-degree Chebyshev approximation for log2x over x[1,2] is only about 2.2×10-6, which is approximately the value of the next Chebyshev coefficient.

If we truncate the series to a 4th-degree Chebyshev approximation, we get a maximum error that is about equal to c5=8.6×105:



No hay comentarios:

Publicar un comentario