function demosecanti_2018(test)

if nargin < 1
test=1;
end

switch test
    case 1 % flat
        f=inline('exp(x)-2+x'); 
        % df=inline('exp(x)+1'); 
        x(1)=0;
        x(2)=1; 
        %x0=1;
        sol=0.4428544010023885;
    case 2
        f=inline('sin(x)-x'); 
        % df=inline('cos(x)-1'); 
        x(1)=-2; 
        x(2)=3;
        sol=0;
    case 3
        f=inline('x.^2-2'); 
        % df=inline('2*x'); 
        % x0=-2; 
        x(1)=1;
        x(2)=2;
        x0=2;
        sol=sqrt(2);
    case 4
        f=inline('1./x-0.85'); 
        % df=inline('-1./x.^2'); 
        x(1)=1;
        x(2)=2;
        sol=1/0.85;
end

tol=10^(-15);
kmax=10000;
% [x,ko]=newton2011(x0,tol,kmax,f,df);

[x, fxv, n, flag] = secantfun (f, x(1), x(2), tol, kmax);

ae_old=NaN;

for ii=1:length(x)
    ae=abs(x(ii)-sol);
    if ii > 1
    steps=abs(x(ii)-x(ii-1));
    else
        steps=realmax;
    end
    res=f(x(ii));
    if ii == 1
        fprintf('\n \t $%4.0f$ & $%1.15e$ & $%1.2e$ & $%1.2e$ & $%1.2e$',...
    ii-1,x(ii),ae,steps,res);
    else
        fprintf('\n \t $%4.0f$ & $%1.15e$ & $%1.2e$ & $%1.2e$ & $%1.2e$',...
    ii-1,x(ii),ae,steps,res);

    end
    ae_old=ae;
end

fprintf('\n \n');

figure(1)
ae=abs(x-sol);
semilogy(0:length(x)-1,ae,'ro-','Linewidth',1);





