Code covered by the BSD License

# Numerical Methods Using MATLAB, 3e

### John Mathews (view profile)

20 Aug 2002 (Updated )

Companion Software

[C,X,Y]=cheby(fun,n,a,b)
```function [C,X,Y]=cheby(fun,n,a,b)

%Input   - fun is the string function to be approximated
%        - N is the degree of the Chebyshev interpolating polynomial
%        - a is the left endpoint
%        - b is the right endpoint
%Output  - C is the coefficient list for the polynomial
%        - X contains the abscissas
%        - Y contains the ordinates

% NUMERICAL METHODS: MATLAB Programs
%(c) 1999 by John H. Mathews and Kurtis D. Fink
%To accompany the textbook:
%NUMERICAL METHODS Using MATLAB,
%by John H. Mathews and Kurtis D. Fink
%ISBN 0-13-270042-5, (c) 1999
%PRENTICE HALL, INC.

if nargin==2, a=-1;b=1;end
d=pi/(2*n+2);
C=zeros(1,n+1);

for k=1:n+1
X(k)=cos((2*k-1)*d);
end

X=(b-a)*X/2+(a+b)/2;
x=X;
Y=eval(fun);

for k =1:n+1
z=(2*k-1)*d;
for j=1:n+1
C(j)=C(j)+Y(k)*cos((j-1)*z);
end
end

C=2*C/(n+1);
C(1)=C(1)/2;

```