|
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
--
|