%
% Demo: Chebyshev rational expansion for exp(-x) on [-1, 1].
%
n = 5; m = 5;
NN = n + m*2 + 1;
a = zeros(NN,1);
tol = 1e-12;
for k = 1:NN
   a(k) = quad(@(x)ChebyExampleFun(x,k-1),0, pi, tol);
end
a(1)= a(1)/pi;
a(2:end) = a(2:end)*(2/pi);
[q,p,A] = ChebyshevRat(a,m,n);
x    = randn(20,1);
mask = find(abs(x)<1);
x    = x(mask);
y    = ChebyshevEval(max(n,m),x);
px   = y(:,1:n+1)*p;
qx   = y(:,1:m+1)*q;
ChebyError = exp(-x)-(px./qx);


