function p=newtonraphson(f,df,x,tolerance,nmax)
% secant method for root finding
if nargin<5 nmax=100;end
if nargin<4 tolerance=1e-10;end
i=0;
fx=f(x);
while (abs(fx) > tolerance) && i<nmax
    fx=f(x);
    dfx=df(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    