/ tutorials / laplace-dirichlet
Sign in
tutorials / laplace-dirichlet
laplace-dirichlet / src / matlab / lp_cheb.m
13 lines · 578 BBlameHistoryRaw
1function [D, x] = lp_cheb(N)
2% LP_CHEB Chebyshev differentiation matrix and nodes on [-1, 1].
3%
4% x = cos(pi*(0:N)/N), ordered from 1 down to -1, and D is the (N+1)-by-(N+1)
5% matrix with (D*v)(i) = p'(x_i) for the polynomial p of degree <= N through
6% the data v. This is Trefethen's cheb.m (Spectral Methods in MATLAB, 2000).
7x = cos(pi*(0:N)'/N);
8c = [2; ones(N-1, 1); 2] .* (-1).^(0:N)';
9X = repmat(x, 1, N+1);
10dX = X - X';
11D = (c * (1 ./ c)') ./ (dX + eye(N+1)); % off-diagonal entries
12D = D - diag(sum(D, 2)); % diagonal, by the zero-row-sum rule
13end
↑↓ move↵openescclose