  function [D,x] = cheb01 (N)

% function [D,x] = cheb01 (N)
%
% compute D = differentiation matrix, x = Chebyshev grid for [0,1].
% Modified from Trefethen's cheb.m code for [-1,1].

  if N==0, D=0; x=1; return, end
  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'));                 % diagonal entries

  D = D*2; x = (x+1)/2;                   % ME: modification for [0,1]
