% Integrate Runge's function numerically by Newton-Cotes methods

f = @(x) 1./(1+25*x.^2);
% f = @(x) cos(x);
N = 10000;
x = linspace(-1, 1, N);

intOrder = 1:20;	% Interpolation orders
integral = zeros(size(n));
for n = 1:length(intOrder)
	quadPts = linspace(-1, 1, intOrder(n));
	p = interpolate(f, quadPts, x);
	integral(n) = 2/N*sum(p);
end

plot(intOrder, integral, '.-');
xlabel('n');
ylabel('Numerical quadrature');