% secant.m: Does secant method on given function.
% Usage: secant('f', eps, a, b).  eps is tolerance, [a,b] initial guess
function c = secant(f, eps, a, b)

%Treat a as old, b as new
fa = f(a); fb = f(b);

k = 1;
while abs(b-a)>eps %Dumb termination criterion, but OK for now.
    
    c = (a*fb-b*fa)/(fb-fa);
    disp([k, a, b, c]);
    fc = f(c);
    
    a=b; b=c; fa=fb; fb=fc;
    %disp([k, c]);
    k = k + 1;
    
end

c;