
tol=1e-15;

n=2;
fpre=1;
fcur=1;
fnew=2;
rcur=fcur/fpre;
rnew=fnew/fcur;
fprintf('  %3d   %9d     %20.15f \n',n,fnew,rnew);

while abs(rnew - rcur) > tol
    % advance n and update pre, cur, new values
    n=n+1;
    fpre=fcur;
    fcur=fnew;
    fnew=fcur+fpre;
    rcur=rnew;
    rnew=fnew/fcur;
    fprintf('  %3d   %9d     %20.15f \n',n,fnew,rnew);
end