今天学习了0.618黄金分割进退法,并编写了代码
function[section]=JT(fx,x0,h0,t)
f= inline(fx);h = h0;a=x0;k=0;
judge=1;
while judge==1
x1=x0+h;
k = k+1;
if f(x1)<f(x0)
h=t*h;
a=x0;
x0=x1;
else
if k==1
h=-h;
else
judge=0;
end
end
end
m=min(a,x1);n=max(a,x1);
section=sprintf('[%.4f,%.4f]',m,n);
浙公网安备 33010602011771号