function xx = TM2(f,x)
%Thiele 2 Method
nmax=500;
tolerance=1.0e-8;
i=0;
f_x=1;
while   abs(f_x)>=tolerance && i<=nmax
   f_x=f(x);
   df_x=dnf(f,x,1);
   d2f_x=dnf(f,x,2);
   d3f_x=dnf(f,x,3);
   P2=f_x*(6.0*df_x*df_x*d2f_x-3.0*f_x*d2f_x*d2f_x+2*f_x*df_x*d3f_x);
   Q2=2.0*df_x*(3.0*df_x*df_x*d2f_x-3.0*f_x*d2f_x*d2f_x+f_x*df_x*d3f_x);
   x=x-P2/Q2;
   i=i+1;
  end
if(i>=nmax) fprintf('Maximum number of iteration is exceeded in Thiele 2 method\nresults may not be valid');end
xx=x;
end


