from
Chebpack
by Damian Trif The MATLAB package Chebpack solves specific problems for differential or integral equations.
D=deriv(n,dom)
function D=deriv(n,dom)
% D: the spectral differentiation matrix D (sparse)
% n: the dimension, dom: the domain [a,b]
%
% Written by Damian Trif, 2011
%
e=0:n;
D=2*spdiags(repmat(e',1,floor(n/2)),1:2:n-1,n,n);
alpha=(dom(2)-dom(1))/2;
D=D/alpha;