% p11.m - Chebyshev differentiation of a smooth function u = exp(x)*sin(5x)
%         (from Trefethen, 2000, p. 56)

  % Plotting points
  xx = -1:.01:1;
  uu = exp(xx).*sin(5*xx);

  for N = [10 20]
    [D x] = cheb(N);
    u = exp(x).*sin(5*x);
    dudx = D*u; % Chebyshev approximate derivative

    % Calculate error and make plots

    dudx_ex = exp(x).*(sin(5*x)+5*cos(5*x));
    error = dudx - dudx_ex;   

    subplot('position',[.15 .66-.4*(N==20) .31 .28])
    plot(x,u,'.','markersize',14), grid on
    line(xx,uu)
    title(['u(x), N=' int2str(N)])

    subplot('position',[.55 .66-.4*(N==20) .31 .28])
    plot(x,error,'.','markersize',14), grid on
    line(x,error)
    title(['  error in u''(x), N=' int2str(N)])
  
  end
