一维搜索---黄金分割法

参考网址

https://blog.csdn.net/shenziheng1/article/details/51317801

https://www.jianshu.com/p/beea2b4447c8

原理

算法流程

算法

a = 1;
b = 4;
Err = 0.001;
T = 0.618;
c = a+(1-T)*(b-a);
d = b-(1-T)*(b-a);
Fc = Fx(c);
Fd = Fx(d);
while(1)
    if(abs(b-a)<Err)
        x=0.5*(a+b);
        break;
    end
    if(Fc<Fd)
        a = a;
        b = d;
        d = c;
        Fd = Fc;
        c = a+(1-T)*(b-a);
        Fc = Fx(c);
    else %Fc>Fd
        b = b;
        a = c;
        c = d;
        Fc = Fd;
        d = b-(1-T)*(b-a);
        Fd = Fx(d);
    end    
end
x
minFx = Fx(x)
 
function y = Fx(x)
y = x*x-6*x+9;
end

猜你喜欢

转载自blog.csdn.net/LYKymy/article/details/84842564