www.pudn.com > pid-adjust.zip > conjugate_gradient.m, change:2010-07-15,size:745b


function f=conjugate_gradient(x0,eps) %输入初始值与要求精度 
x=x0; 
syms xi yi a     %a为步长 
f=ISE99;%fun; 
fx=diff(f,xi);  %分别对各变量进行求偏导 
fy=diff(f,yi); 
fx=subs(fx,[xi,yi],x0);     %将初值带入 
fy=subs(fy,[xi,yi],x0); 
fi=[fx,fy]; 
n=0; 
while double(norm(fi))>eps    %最优判别 
s=-fi; 
if n<=0 
s=-fi; 
else 
s=s1; 
end 
x=x+a*s;% 
f=subs(f,[xi,yi],x);        %新值代入 
f1=diff(f);             %最优步长a求解 
f1=solve(f1); 
if f1~=0 
ai=double(f1); 
else 
break 
x,n 
end 
x=subs(x,a,ai); 
f=ISE99;%fun; 
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;  %搜索方向 
n=n+1;        %搜索次数 
fx=fxi; 
fy=fyi; 
fi=[fx,fy]; 
end 
x,n