% exercise 2.16

X=[1.0000,2.1314,3.0365,3.7605,4.3398,4.8032,5.1739,5.4705];

%  diff([1 1 2 3 5 8 13 21])
E1=diff(X(2:end));
E2=diff(X(1:end-1));

disp('Ratio of two consecutive differences:')
E1./E2

%% 
disp('Approximation of the convergence value a:')

%a=(X(2:end)-0.8*X(1:end-1))/0.2

a=(X(end)-0.8*X(end-1))/0.2

w=X(end)-a;

disp('Number of additional iterations needed to have about 3 digits of accuracy:')
k=log(abs(5e-4/w))/log(0.8)

disp('Rounded up:')

ceil(k)