Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Chebyshev Polynomial Coefficients needed

Subject: Chebyshev Polynomial Coefficients needed

From: ricklyon@remove.onemain.com (Rick Lyons)

Date: 16 May, 2002 11:05:15

Message: 1 of 5


Hi,

  I need some help. Do any of you have the
MATLAB code for calculating the coefficients used
with Chebyshev polynomials when one wants to
represent common trig functions with a Chebyshev
polynomial?

If so, would you take pity on me and "share"
your code?

The coefficients I'm talking about are the ones
calculated by performing the integration of the
ratio of:

   (trig function to be expanded)*(Cheb polynomials)
  ----------------------------------------------------
     sqrt[1 -(function's independent variable)^2]

If I have to perform that integration on paper,
I'm doomed.

Thanks Much,
[-Rick-]

Subject: Chebyshev Polynomial Coefficients needed

From: John D'Errico

Date: 16 May, 2002 08:41:05

Message: 2 of 5

In article <3ce38fa7.9799881@news.earthlink.net>,
ricklyon@remove.onemain.com (Rick Lyons) wrote:

> I need some help. Do any of you have the
> MATLAB code for calculating the coefficients used
> with Chebyshev polynomials when one wants to
> represent common trig functions with a Chebyshev
> polynomial?

> The coefficients I'm talking about are the ones
> calculated by performing the integration of the
> ratio of:
>
> (trig function to be expanded)*(Cheb polynomials)
> ----------------------------------------------------
> sqrt[1 -(function's independent variable)^2]

Its actually pretty easy. the function cheby1
below gives the first kind Chebyshev polys
in matlab's polyval form. (Verify that I've
provided them with the proper normalization.
I have not checked this.)

% =======================================================
function pn=cheby1(n)
% compute n'th order chebyshev polynomial of the first kind
% initialize (-1)'th and zero'th order polynomials
pn=[];
pnp1=[1];

for i=0:n
  pnm1=pn;
  pn=pnp1;
  pnp1=(2*[pn,0] - [0,0,pnm1]);
  % normalize so that p(1)==1
  pnp1=pnp1/polyval(pnp1,1);
end
% =======================================================

As a test,

»cheby1(0)
ans =
     1
»cheby1(1)
ans =
     1 0
»cheby1(2)
ans =
     2 0 -1
»cheby1(3)
ans =
     4 0 -3 0
»cheby1(4)
ans =
     8 0 -8 0 1
»cheby1(5)
ans =
    16 0 -20 0 5 0


I think they are correct. They are normalized
so that T(1)==1, as given by Abramowitz & Stegun.

Now, something to integrate. Lets try sin(x).

»fun=inline('sin(x).*polyval(p,x)./sqrt(1-x.^2)','x','p')
fun =
     Inline function:
     fun(x,p) = sin(x).*polyval(p,x)./sqrt(1-x.^2)


Numerical integration over the integral [-1,1].
Lets see, even orders should return zero, to within
the integration tolerance, since sin(x) is an odd
function.

»quadl(fun,-1,1,[],[],cheby1(0))

Warning: Divide by zero.
> In Applications:Matlab 5.2:My toolboxes:My_idioms:Funfun toolbox 5.3:@inline:feval.m at line 30
  In Applications:Matlab 5.2:My toolboxes:My_idioms:funfun6.1:quadl.m at
line 63
ans =
   -1.139e-10


Looks ok so far. The divide by zeros are because
the integrand has poles at +/- 1. Quadl seems to
handle it ok.

»quadl(fun,-1,1,[],[],cheby1(1))

Warning: Divide by zero.
> In Applications:Matlab 5.2:My toolboxes:My_idioms:Funfun toolbox 5.3:@inline:feval.m at line 30
  In Applications:Matlab 5.2:My toolboxes:My_idioms:funfun6.1:quadl.m at
line 63
ans =
       1.3825

»quadl(fun,-1,1,[],[],cheby1(2))

Warning: Divide by zero.
> In Applications:Matlab 5.2:My toolboxes:My_idioms:Funfun toolbox 5.3:@inline:feval.m at line 30
  In Applications:Matlab 5.2:My toolboxes:My_idioms:funfun6.1:quadl.m at
line 63
ans =
   -8.951e-11

»quadl(fun,-1,1,[],[],cheby1(3))

Warning: Divide by zero.
> In Applications:Matlab 5.2:My toolboxes:My_idioms:Funfun toolbox 5.3:@inline:feval.m at line 30
  In Applications:Matlab 5.2:My toolboxes:My_idioms:funfun6.1:quadl.m at
line 63
ans =
    -0.061459

»quadl(fun,-1,1,[],[],cheby1(4))

Warning: Divide by zero.
> In Applications:Matlab 5.2:My toolboxes:My_idioms:Funfun toolbox 5.3:@inline:feval.m at line 30
  In Applications:Matlab 5.2:My toolboxes:My_idioms:funfun6.1:quadl.m at
line 63
ans =
   5.9058e-11

If I were you, I'd check these results. Mostly
my choice of normalization.

Hope this helps,
John D'Errico

--

Subject: Chebyshev Polynomial Coefficients needed

From: pjacklam@online.no (Peter J. Acklam)

Date: 16 May, 2002 18:49:14

Message: 3 of 5

ricklyon@remove.onemain.com (Rick Lyons) wrote:

> I need some help. Do any of you have the
> MATLAB code for calculating the coefficients used
> with Chebyshev polynomials when one wants to
> represent common trig functions with a Chebyshev
> polynomial?

These two functions

  http://home.online.no/~pjacklam/matlab/software/util/polyutil/chebpoly.m
  http://home.online.no/~pjacklam/matlab/software/util/polyutil/cheb2poly.m

returns, or evaluates, depending on how you call them, the
Chebychev polynomials of first and second kind.

Peter

--
I followed a bit stream. I found a bit river.

Subject: Chebyshev Polynomial Coefficients needed

From: spellucci@mathematik.tu-darmstadt.de (Peter Spellucci)

Date: 17 May, 2002 11:23:28

Message: 4 of 5


In article <lmak53j4.fsf@online.no>,
 pjacklam@online.no (Peter J. Acklam) writes:
>ricklyon@remove.onemain.com (Rick Lyons) wrote:
>
>> I need some help. Do any of you have the
>> MATLAB code for calculating the coefficients used
>> with Chebyshev polynomials when one wants to
>> represent common trig functions with a Chebyshev
>> polynomial?

this is not a question on how to get the chebyshev polynomials themselves
but the coefficients e.g. given in Clenshaws famous report

Clenshaw, C.W.
Chebyshev series for mathematical functions (English)
[B] London: Her Majesty's Stationery Office, Department of Scientific and Industrial Research IV, 36 p. (1962).
Schlüsselwörter: numerical analysis

how to do it, is best described in this text.
but you can do it by brute force using
the formula you already have , substitution x^2=cos(phi),
(the singularity vanishes)
and integrating using say the matlab function quadl with a high precision
requirement. (after the substitution, the chebyshev polynomials
T_k(x)=cos(k*arccos(x)) simply become cos(k*phi)). for large k you get a
highly oscillatory integral, a thing which is not amenable for brute force
numerical quadrature, hence the special considerations in the paper cited
above were necessary.
hth
peter

Subject: Chebyshev Polynomial Coefficients needed

From: Yash

Date: 14 Jul, 2012 17:23:07

Message: 5 of 5

thnx for the awesome program

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us