function ret = aitken(arr, els)

% Perform Aitken acceleration on first els elements of arr.
%  If els is not odd, then els-1 elements will be used.

% Check parity of els
if (els/2 == 0)
	els = els - 1;
end

% Initialize aitken arrays
arr1 = arr(1:els);
arr2 = [];

continue = 1;
% Iterate
while (length(arr1) > 1)
	currel = 1;
	stopel = length(arr1) - 1;
	arr1;
	while (currel < stopel)
		vn = arr1(currel);
		vn1 = arr1(currel + 1);
		vn2 = arr1(currel + 2);
		arr2(currel) = (vn*vn2-vn1^2)/(vn2-2*vn1+vn);
		currel = currel + 1;
	end
	arr1 = arr2;
	arr2 = [];
end

ret = arr1;
