共轭梯度法的调用函数在Matlab里是什么? fminunc是不是共轭梯度法的调用格式
1个回答
展开全部
共轭梯度法
function f=conjugate_grad_2d(x0,t)
%please input this:conjugate_grad_2d([2,2],0.05)
x=x0;
syms xi yi a
f=xi^2-xi*yi+3*yi^2;
fx=diff(f,xi);
fy=diff(f,yi);
fx=subs(fx,{xi,yi},x0);
fy=subs(fy,{xi,yi},x0);
fi=[fx,fy];
count=0;
while double(sqrt(fx^2+fy^2))>t
s=-fi;
if count<=0
s=-fi;
else
s=s1;
end
x=x+a*s;
f=subs(f,{xi,yi},x);
f1=diff(f);
f1=solve(f1);
if f1~=0
ai=double(f1);
else
break
x,f=subs(f,{xi,yi},x),count
end
x=subs(x,a,ai);
f=xi^2-xi*yi+3*yi^2;
fxi=diff(f,xi);
fyi=diff(f,yi);
fxi=subs(fxi,{xi,yi},x);
fyi=subs(fyi,{xi,yi},x);
fii=[fxi,fyi];
d=(fxi^2+fyi^2)/(fx^2+fy^2);
s1=-fii+d*s;
count=count+1;
fx=fxi;
fy=fyi;
end
x,f=subs(f,{xi,yi},x),count
function f=conjugate_grad_2d(x0,t)
%please input this:conjugate_grad_2d([2,2],0.05)
x=x0;
syms xi yi a
f=xi^2-xi*yi+3*yi^2;
fx=diff(f,xi);
fy=diff(f,yi);
fx=subs(fx,{xi,yi},x0);
fy=subs(fy,{xi,yi},x0);
fi=[fx,fy];
count=0;
while double(sqrt(fx^2+fy^2))>t
s=-fi;
if count<=0
s=-fi;
else
s=s1;
end
x=x+a*s;
f=subs(f,{xi,yi},x);
f1=diff(f);
f1=solve(f1);
if f1~=0
ai=double(f1);
else
break
x,f=subs(f,{xi,yi},x),count
end
x=subs(x,a,ai);
f=xi^2-xi*yi+3*yi^2;
fxi=diff(f,xi);
fyi=diff(f,yi);
fxi=subs(fxi,{xi,yi},x);
fyi=subs(fyi,{xi,yi},x);
fii=[fxi,fyi];
d=(fxi^2+fyi^2)/(fx^2+fy^2);
s1=-fii+d*s;
count=count+1;
fx=fxi;
fy=fyi;
end
x,f=subs(f,{xi,yi},x),count
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询