|
楼主 |
发表于 2006-11-22 10:43
|
显示全部楼层
这个也是这样
function [a,b,z]=lsliu(f,z0,h)
syms x1 x2 y1 y2 z1 z2
y0=subs(f,[x1,x2],z0);
%n=0
z2=z0+h;
y2=subs(f,[x1,x2],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,[x1,x2],z2);
while(y2<=y0)
z1=z0;
y1=y0;
z0=z2;
y0=y2;
h=2*h;
z2=z0+h;
y2=subs(f,[x1,x2],z2);
end
z1=z0;
a=min(z1,z2);
b=max(z1,z2);
eps=0.05;
z1=a+0.382*(b-a);
y1=subs(f,[x1,x2],z1);
z2=a+0.618*(b-a);
y2=subs(f,[x1,x2],z2);
while (abs(b-a)>eps);
if (y1>=y2)
a=z1;
b=b;
z1=a+0.382*(b-a);
y1=subs(f,[x1,x2],z1);
z2=a+0.618*(b-a);
y2=subs(f,[x1,x2],z2);
elseif y2>y1
a=a;
b=z2;
x1=a+0.382*(b-a);
y1=subs(f,[x1,x2],z1);
z2=a+0.618*(b-a);
y2=subs(f,[x1,x2],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) |
|