1function [CHPTS, SINCH, U, V, U1, V1] = chnodc(A, B, M)
2% CHNODC Constructs Chebyshev nodes and mapping coefficients.
3%
4% [CHPTS, SINCH, U, V, U1, V1] = CHNODC(A, B, M)
5%
6% This function calculates classical Chebyshev nodes for the
7% interval [A, B] and the coefficients for linear mappings
8% between the intervals [-1, 1] and [A, B].
9%
10% INPUT PARAMETERS:
11% A - Lower bound of the interval.
12% B - Upper bound of the interval.
13% M - Number of Chebyshev nodes to generate.
14%
15% OUTPUT PARAMETERS:
16% CHPTS - Array of Chebyshev nodes in the interval [A, B].
17% SINCH - Array containing U * sin(theta) for the Chebyshev points.
18% U - Coefficient for mapping from [-1, 1] to [A, B].
19% V - Coefficient for mapping from [-1, 1] to [A, B].
20% U1 - Coefficient for mapping from [A, B] to [-1, 1].
21% V1 - Coefficient for mapping from [A, B] to [-1, 1].
22%
23% The kth Chebyshev node is computed using:
24% CHPTS(k) = U * cos((2k - 1) * pi / (2M)) + V
25%
26% Example:
27% A = -1;
28% B = 1;
29% M = 5; % Number of Chebyshev nodes
30% [CHPTS, SINCH, U, V, U1, V1] = chnodc(A, B, M);
31%
32% NOTE: code adjusted from code provided by Leslie Greengard.
34if(nargin == 0), test_chnodc; return; end
36% Construct the scaling parameters
37U = (B - A) / 2;
38V = (B + A) / 2;
39U1 = 2 / (B - A);
40V1 = 1 - U1 * B;
42% Preallocate the arrays for Chebyshev nodes and sin values
43CHPTS = zeros(1, M);
44SINCH = zeros(1, M);
46% Construct the Chebyshev nodes and corresponding SIN array
47K = 1:M;
48CHPTS(M - K + 1) = U * cos((2 * K - 1) * pi / (2 * M)) + V;
49SINCH(M - K + 1) = U * sin((2 * K - 1) * pi / (2 * M));
51end
53function test_chnodc
54clf;
56A = -2;
57B = 1;
58M = 20; % Number of Chebyshev nodes
59[CHPTS, SINCH, U, V, U1, V1] = chnodc(A, B, M);
61plot(CHPTS,0,'*r','markerSize',10);
62end