Matlab:牛顿迭代法工具箱

function [f,L]=Newton(f,a)
%this is newton teration whic is used for solving implicit One-dimensional Euler method
%users can used it directly for solve equation.
%the code was writen by HD.dong in january 8 2017.
%--------------------------------
% syms x;
%  %         h='[x^4-4*x^2+4]';
% %     h='[x^3+2*x^2+10*x-20]';
%        h='[x^3-x-1]';
% %  h='[x^3+4*x^2-10]';
% x0=0.6;%users can set any value except zero,because diff(h,x) is Singular when x is zero.
% [X L]=Newton(h,x0);
%--------------------------------------------------------------------
lambda=1;%newton downhill factor
L(1)=lambda;
x0=a;
x1=x0-Jacoi(f,x0)\F(f,a)*lambda;
tol=1e-5;
ttol=1e-8;
i=1;
 while norm(x1-x0,1)>=tol                
         lambda=1;
 while abs(F(f,x1))>=abs(F(f,x0)) & lambda>=ttol
 lambda=lambda/2;
 x1=x0-Jacoi(f,x0)\F(f,x0)*lambda;
 end
   x0=x1;
       x1=x0-Jacoi(f,x0)\F(f,x0)*lambda;
       i=i+1;
       L(i)=lambda;
 end
 f=x1;
function G=Jacoi(f,x0)
syms x;
G=vpa(subs(diff(f,x),'x',x0));
function H=F(f,x0)
H=vpa(subs(f,'x',x0));