Code covered by the BSD License  

Highlights from
Chebpack

image thumbnail

Chebpack

by

 

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

[z,fz,m]=chebroots(c,dom,loc,tol)
function [z,fz,m]=chebroots(c,dom,loc,tol)
% Calculates the roots of f
% f is given by its n Chebyshev coefficients c for the domain dom
% z are the roots in the interval "loc" and fz=f(z) (for test)
% tol is a tolerance used for retaining only the first m coefficients of c
% and for select the real roots z>local(1)+tol.
%
% Example: exp(sin(x))=2, x in [0,10]
%   x=pd(64,[0,10],2);val=exp(sin(x));c=x2t(val-2,2);
%   [z,fz,m]=chebroots(c,[0 10],[0 10],1.e-13);
%
c=c(:);n=length(c);w=c;w(1)=w(1)/2;
M=max(abs(w));
m=find(abs(w)>M*tol,1,'last');
w=w(1:m);
%construct the matrix C
d=ones(m-1,1)/2;
C=diag(d,1)+diag(d,-1);C(1,2)=1;
w = w(1:end-1) / w(end)/2;
A=C(1:end-1,1:end-1);A(end,:)=A(end,:)-w.';
% calculate the roots inside the interval "loc": z>loc(1), z<=loc(2)
z=eig(A);z=z(abs(imag(z))<tol);z=real(z);
z=(dom(2)-dom(1))*z/2+(dom(2)+dom(1))/2;
z=z(loc(1)+tol<z & z<=loc(2));
[~,I]=sort(z);z=z(I);T=cpv(n,z,dom);fz=T*c;

Contact us