clc;clear;
syms x
h = 4;
x0 = 0;
f =3*x^4-16*x^3+30*x^2-24*x+8;
while(1)
x1 = x0+h;
f0 = subs(f,x,x0);
f1 = subs(f,x,x1);
if f1<f0
x0 = x1;
h = 2*h;
else
if abs(h)<1e-4
break;
else
h = 1/4*h;
end
end
end
fprintf('成功失败法求得的极小值为%9.9f\n',x0)
程序输出结果:
成功失败法求得的极小值为1.999969482