function [x]=gefx(f,x0,e,var)
syms x1 x2 t
d=-jacobian(f,var);%负梯度
p0=subs(d,var,x0);%负梯度值
v=p0*p0.';%求梯度模
v=v^0.5;
while(v>e)
h=x0+t.*p0;%h=x+Ld
fai=subs(f,var,h);%f(x+Ld)=fai(L)
df=diff(fai);%求导
t1=solve(df,t);%导函数为0时t的值
x1=subs(h,t1);%新的点
p0=subs(d,var,x1);%新的负梯度值
v1=p0*p0.';
v1=v1^0.5;
if(v1>e)
a=subs(d,var,x0);
L=(v1^2)/(a*a.');%求λ的值
p0=subs(d,var,x1)+L.*p0;
x0=x1;v=v1;%进入下一个循环
else
break;
end
end
x=vpa(x1);
end