2% CHEXFCDIR computes coefficients of Chebyshev expansion
3% of function tabulated at classical Chebyshev nodes.
4%
5% INPUT:
6% F = function values at Chebyshev nodes in increasing order
7% on the interval (-1,1)
8% N = number of Chebyshev nodes
9%
10% OUTPUT:
11% TEXP = array of expansion coefficients of (N-1)st degree
12% interpolant
13%
14% NOTE: code adjusted from code provided by Leslie Greengard.
16if nargin == 0, test_chexfcdir; return; end
18F = F(:); % ensure the input is a column vector
20FAC = 2/N; % Factor to normalize
21TEXP = zeros(N, 1); % Initialize TEXP array
23J = (1:N)'; % cheb node index
24for I = 1:N % loop for each cheb coefficient
25 TEXP(I) = sum(FAC * F(J).*cos((J - 0.5)*(I - 1)*pi./N));
26 TEXP(I) = -TEXP(I)*(-1)^I; % Apply the sign change
27end
28TEXP(1) = TEXP(1) / 2; % Adjust the first coefficient
30end
32function test_chexfcdir
33N = 16;
34[x, ~, ~, ~, ~, ~] = chnodc(-1, 1, N);
36F = cos(x - 3).*exp(-2*x)';
38TEXP = chexfcdir(F, N);
39disp('Array of expansion coefficients of (N-1)st degree interpolant');
40disp(TEXP);
41end