function [ root ] = secant(f,x0,x1)
%SECANT secant(f,x0,x1) computes a root of f using the secant method

% Example usage:
%   secant(@(x) x.^2 - 10, 1, 5)
% (which solves x^2 = 10, resulting in sqrt(10).
%
    n = 1;  % this will count (and limit) the number of iterations
    x = [x0 x1];
    m = [];
    
    % loop until max # of steps, or a fixed point is reached 
    while n < 100 && abs(x(end) - x(end-1)) > eps(x(end))
        n = n + 1;
        m(n) = (x(n)-x(n-1))/(f(x(n))-f(x(n-1)));
        x(n+1)=x(n)-f(x(n)).*m(n);
        disp(x(n+1));
    end
    root = x(end);
end
