求助高手修改下程序
二元函数黄金分割法的直线搜索function =lsliu(f,z0,h)
syms x1 x2 y1 y2 z1 z2
y0=subs(f,,z0);
%n=0
z2=z0+h;
y2=subs(f,,z2);
if(y2>=y0)
z1=z2;
y1=y2;
h=-h;
else
z1=z0;
y1=y0;
z0=z2;
y0=y2;
h=2*h;
end
z2=z0+h;
y2=subs(f,,z2);
while(y2<=y0)
z1=z0;
y1=y0;
z0=z2;
y0=y2;
h=2*h;
z2=z0+h;
y2=subs(f,,z2);
end
z1=z0;
a=min(z1,z2);
b=max(z1,z2);
eps=0.05;
z1=a+0.382*(b-a);
y1=subs(f,,z1);
z2=a+0.618*(b-a);
y2=subs(f,,z2);
while (abs(b-a)>eps);
if (y1>=y2)
a=z1;
b=b;
z1=a+0.382*(b-a);
y1=subs(f,,z1);
z2=a+0.618*(b-a);
y2=subs(f,,z2);
elseif y2>y1
a=a;
b=z2;
x1=a+0.382*(b-a);
y1=subs(f,,z1);
z2=a+0.618*(b-a);
y2=subs(f,,z2);
end
end
z=(z1+z2)/2;
运行后 :
??? Function 'ge' is not defined for values of class 'sym'.
Error in ==> lsliu at 38
if (y1>=y2)
为什么不能比较
[ 本帖最后由 xinyuxf 于 2007-7-22 16:10 编辑 ]
页:
[1]