azure011328

导航

 

今天学习了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);

  

posted on 2024-05-24 10:50  淮竹i  阅读(13)  评论(0)    收藏  举报