function val=AitkenMethod(a,steps,object,display) % function S = AitkenMethod(a,steps,object,display) % % extrapolates a sequence or series by using % Aitkens Delta^2 method % % a vector of terms % steps number of extrapolation steps % (method needs 2*steps+1 elements of a) % object 'sequence': extrapolation to the limit of a % 'series' : extrapolation to the limit of cumsum(a) % display 'on': plot the absolute value of differences in the first % row of the extrapolation table for diagnosis % % S extrapolatd value % Vektor a als Spaltenvektor anpassen dims = size(a); if dims(1) == 1 a = a'; end S=zeros(length(a),steps+1); switch object case 'sequence' S(:,1)=a; case 'series' S(:,1)=cumsum(a); otherwise error('MATLAB:badopt','%s: no such object known',object); end for j=2:steps+1 d2=diff(S(2:end-2*j+4,j-1)); d1=diff(S(1:end-2*j+3,j-1)); r=d2./d1; fac=r./(1-r); S(1:end-2*j+2,j)=S(3:end-2*j+4,j-1)+fac.*d2; end if isequal(display,'on') h=semilogy(1:length(S(1,:))-1,abs(diff(S(1,:)))); set(h,'LineWidth',3); end S; val=S(1,end); return