% Metodo secante
clear, clc
cf = input('Funcion:');
f = inline(cf);
x0 = input('Valor x0:');
x1 = input('Valor x1:');
lim = 0.000;
e = 100;
n = 0;
fprintf('n x0 x1 x2 Error\n');
while(e > lim)
x2 = x1 - (x1-x0)*f(x1)/(f(x1)-f(x0));
e = abs(f(x2));
fprintf('%i %4.4f %4.4f %4.4f %4.4f\n',n, x0,x1,x2,e);
x0 = x1;
x1 = x2;
n = n+1;
end