function p=secant(f,x,tolerance,nmax)
% secant method for root finding
if nargin<4 nmax=100;end
if nargin<3 tolerance=1e-10;end
i=0;
fx=f(x);
while (abs(fx) > tolerance) && i<nmax
    fx=f(x);
    dfx=df(f,x);
    x=x-fx/dfx;
    i=i+1;
end
p=x;
if i>=nmax fprintf('Maximum number of iterations is exceeded the result may not be valid');end
end    