representing a given polynomial in Chebyshev polynomials

14 views (last 30 days)
Given a polynomial, is there a way to have its representation in Chebyshev polynomials? I'm thinking a function as follows: the input can be a vector whose entries are coefficient of a polynomial, i.e. the coefficients in monic monomials (1, x, x^2, x^3, ...) and the output is the coefficients as if the same polynomial was represented in Chebyshev polynomials, i.e. T_0(x), T_1(x), T_2(x), ...
For example, the input is [2 2 1], i.e. 2*x^2+2*x+1 and the output is [1, 2, 2], i.e. T_2(x)+2*T_1(x)+T_0(x).
If there isn't such a function, is there a way at all to do so using the symbolic toolbox?
Thank you very much!

Answers (2)

John D'Errico
John D'Errico on 5 Apr 2016
Edited: John D'Errico on 5 Apr 2016
You can easily enough build the first kind Chebyshev polynomials in symbolic TB form. (Or second kind if you wish.)
https://en.wikipedia.org/wiki/Chebyshev_polynomials
function T = cheby1(N)
% Compute the first kind Chebyshev polynomial T_N(x)
syms x
if N == 0
T = 1;
elseif N == 1
T = x;
else
T0 = 1;
T1 = x;
for n = 2:N
T = expand(2*x*T1 - T0);
T0 = T1;
T1 = T;
end
end
Then you get the coefficients by a dot product. Don't forget to divide by 1/sqrt(1-x^2) in the dot product. As these polynomials are generated, don't forget how they are normalized.
T3 = cheby1(3)
T3 =
4*x^3 - 3*x
int(T3*T3/sqrt(1-x^2),[-1,1])
ans =
pi/2
Recovering those coefficients for a given polynomial, it is just a set of dot products...
T0 = cheby1(0)
T0 =
1
>> T1 = cheby1(1)
T1 =
x
>> T2 = cheby1(2)
T2 =
2*x^2 - 1
>> int((2*x^2+2*x+1)*T0/sqrt(1-x^2),[-1,1])/(pi)
ans =
2
>> int((2*x^2+2*x+1)*T1/sqrt(1-x^2),[-1,1])/(pi/2)
ans =
2
>> int((2*x^2+2*x+1)*T2/sqrt(1-x^2),[-1,1])/(pi/2)
ans =
1
Be careful about how those polynomials are normalized.
  2 Comments
Kuan Xu
Kuan Xu on 5 Apr 2016
Hi, Thanks very much for your answer! It's a very good answer. But I guess that your method is very expensive. Because for each Chebyshev coefficient, you need to evaluate an integral.
Do you have other ideas?
On another note - since Matlab 2015a, we don't bother to construct Chebyshev polynomials on our own. The new command ChebyshevT can do the construction for us. For example,
>> chebyshevT(5,x)
ans =
16*x^5 - 20*x^3 + 5*x
John D'Errico
John D'Errico on 9 Apr 2016
Edited: John D'Errico on 9 Apr 2016
Well, you never said you needed it to be cheap in your question. :) Virtually ANY way that you work with Chebyshev polynomials in symbolic form, it will be more expensive than working with them purely in terms of their coefficients.
But suppose you wish to compute the solution sing simple linear algebra. Then just compute the polynomials in terms of their coefficients, and do so directly.
For example, to compute the first N chebyshev polynomials just as a coefficient array. Here, I'll do it for n = 3;
N = 3;
C = zeros(N,N);
C(1,1) = 1;
C(2,2) = 1;
for n = 3:N
C(n,:) = [0,2*C(n-1,1:N-1)] - C(n-2,:);
end
C = fliplr( C );
Now it is trivial to quickly compute the linear combination in terms of Chebyshev polynomials, since that linear combination is unique.
For example, given the target polynomial of
2*x^2 + 2*x + 1
it has coefficients
Tpoly = [2 2 1];
Now, compute the linear combination of the Chebyshev polynomials.
Tpoly/C
ans =
2 2 1
Thus, we see that
2*T0 + 2*T1 + T2 = 2*x^2 + 2*x + 1
As you desire, this is FAR more efficient than using the symbolic toolbox.
Does it work in general? Lets try a higher degree polynomial.
Tpoly = [1 2 3 4 5 6];
N = 6;
C = zeros(N,N);
C(1,1) = 1;
C(2,2) = 1;
for n = 3:N
C(n,:) = [0,2*C(n-1,1:N-1)] - C(n-2,:);
end
C = fliplr( C );
TpolyLC = Tpoly/C
TpolyLC =
8.75 7.875 3 1.0625 0.25 0.0625
Did this recover the target polynomial?
syms x
P = 0;
for n = 1:6
P = P + chebyshevT(n-1,x)*TpolyLC(n);
end
P
P =
x^5 + 2*x^4 + 3*x^3 + 4*x^2 + 5*x + 6
There are limits of course, since if we go too high in N, the coefficients will have problems when expressed as doubles.

Sign in to comment.


Torsten
Torsten on 5 Apr 2016
  1 Comment
Kuan Xu
Kuan Xu on 5 Apr 2016
Hi Torsten, Probably you forgot that during your two recent visits to the Chebfun team, we met.
What I am looking for is, in fact, a symbolic solution of this conversion, unlike Chebfun, which does the job numerically.
Thanks a lot anyway!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!