clear %% % Consider the integral % % \int_{-1}^1 \frac{1}{1+4x^2} \, dx = \arctan(2). % f = @(x) 1./(1 + 4*x.^2); exact = atan(2); %% % We compare the two spectral integration methods for a range of n values. n = (8:4:60)'; errCC = 0*n; for k = 1:length(n) errCC(k) = exact - ccint(f,n(k)); end figure(1) semilogy( n, abs(errCC), '.-') xlabel('number of nodes') ylabel('error') title('Spectral integration') grid on %% % (The missing dots are where the error is exactly zero.)