 x = chebfun('x',[0 1]);
 nmax = 100;

 f1 = chebfun('exp(x)',[0 1]);
 f2 = chebfun('exp(x).*(x.*(1-x)).^(1.25)',[0 1]);
 f3 = chebfun('exp(x).*(x.^2).*((1-x).^2)',[0 1]);

 c1 = zeros(nmax,1);
 c2 = zeros(nmax,1);
 c3 = zeros(nmax,1);

 for n=1:nmax
    psi_n = sqrt(2)*sin(n*pi*x);
    c1(n) = psi_n'*f1;  
    c2(n) = psi_n'*f2;  
    c3(n) = psi_n'*f3;  
 end
 figure(1), clf
 loglog([1:nmax],abs(c1),'r.-','linewidth',2,'markersize',12)
 hold on
 loglog([1:nmax],abs(c2),'b.-','linewidth',2,'markersize',12)
 loglog([1:nmax],abs(c3),'k.-','linewidth',2,'markersize',12)
 loglog([1:nmax],.1*[1:nmax].^(-1),'r--','linewidth',2,'markersize',12)
 loglog([1:nmax],.1*[1:nmax].^(-2),'b--','linewidth',2,'markersize',12)
 loglog([1:nmax],.1*[1:nmax].^(-3),'k--','linewidth',2,'markersize',12)

 xlabel('$n$','fontsize',18,'interpreter','latex')
 ylabel('$|(f, \psi_n)|$','fontsize',18,'interpreter','latex')
 title('Magnitude of Fourier Coefficients','fontsize',18,'interpreter','latex')
 leg=legend('$f_1$','$f_2$','$f_3$','$1/n$', '$1/n^2$', '$1/n^3$', ...
      'location','southwest','orientation','vertical');
 set(leg,'interpreter','latex','fontsize',18)
