最优化方法 | 【线搜索:黄金分割法】的Matlab实现

最优化方法 | 【线搜索:黄金分割法】的Matlab实现

MATLAB代码实现:

function [num,temp,alpha] = method_0618(a0,b0,L,epsilon,t)
ak =a0;
bk =b0;
num=1;
temp(1) = phi(0.5*(ak+bk));
i = 2;
while bk-ak>= L
    lamudak = ak+(1-t)*(bk-ak);
    muk = ak + t*(bk-ak);
    if phi(lamudak)<phi(muk)
        ak = ak;
        bk = muk;
    else
        ak = lamudak;
        bk = bk;
    end
    num = num+1;
    temp(i) = phi(0.5*(ak+bk));
    disp(['这是黄金分割法--->第', num2str(num),'次迭代,当前目标函数最优值为',num2str(temp(i))]);
    i=i+1;
end
alpha = (ak+bk)/2;
end

你可能感兴趣的:(最优化方法 | 【线搜索:黄金分割法】的Matlab实现)