function p=newton(FUN,dFUN,p0,TOL,N);
%%  function y=bisection(FUN, dFUN,p0,TOL,N);
%%
%%  The Newton method is to find a solution to f(x)=0 given an intial 
%%  approximation p0
%%  
%%
%%  INPUT:
%%  FUN  - the given function to be solved  which is entered as
%%           a string, enclosed in ' ', with the name the m-file of the 
%%           function.
%%  dFun - the drivative of FUN which must be entered as a a string, enclosed
%%         in ' ', with the name the m-file of the function.
%%  p0 - the intiapproximation
%%  TOL - tolerance
%%  N - maximum number of interations 
%%  OUTPUT:
%%  p- approximat solution p or massage of failure
y=feval(FUN,p0);
dy=feval(dFUN,p0);
if dy==0
   massage='this method failed'
   return;
end;   
i=1;
while i<=N
    p=p0-y/dy;
    if abs(p-p0)<TOL
       break;
    end;
    i=i+1;
    p0=p;
    y=feval(FUN,p0);
    dy=feval(dFUN,p0);
end;
if i==N
   massage='mathod failed after N iteration'
end;   

       
