function p=df(f,x,dx)
% derivative of a function
if nargin==3 dx=0.001;end
while (abs(fx) > tolerance) && i<nmax
    fx=f(x);
    dfx=df(f,x);
    x=x-fx/dfx;
    i=i+1;
end
if i>=nmax fprintf('Maximum number of iterations is exceeded the result may not be valid');end
end    