function [D, x] = lp_cheb(N) % LP_CHEB Chebyshev differentiation matrix and nodes on [-1, 1]. % % x = cos(pi*(0:N)/N), ordered from 1 down to -1, and D is the (N+1)-by-(N+1) % matrix with (D*v)(i) = p'(x_i) for the polynomial p of degree <= N through % the data v. This is Trefethen's cheb.m (Spectral Methods in MATLAB, 2000). x = cos(pi*(0:N)'/N); c = [2; ones(N-1, 1); 2] .* (-1).^(0:N)'; X = repmat(x, 1, N+1); dX = X - X'; D = (c * (1 ./ c)') ./ (dX + eye(N+1)); % off-diagonal entries D = D - diag(sum(D, 2)); % diagonal, by the zero-row-sum rule end