% Integrate Runge's function numerically by a composite
% method with the trapezoidal rule

f = @(x) 1./(1+25*x.^2);
m = 5:20;

integral = zeros(size(m));
for mInd = 1:length(m)
	x = linspace(-1, 1, m(mInd)+1);
	for i = 1:m(mInd)
		integral(mInd) = integral(mInd) + (f(x(i))+f(x(i+1)))/m(mInd);
	end
end

plot(m, integral, '.-');
xlabel('m');
ylabel('Composite method');