最优化方法 | 【线搜索:斐波那契法Fibonacci】的Matlab实现
程序员文章站
2022-03-31 21:45:04
...
最优化方法 | 【线搜索:斐波那契法Fibonacci】的Matlab实现
MATLAB代码实现:
function [num,temp,alpha] = method_Fibonacci(a0,b0,L,epsilon)
% epsilon = 1e-9;
ak =a0;
bk =b0;
%% 找到 满足 >= temp的第一个 斐波那契数
temp = (bk-ak)/L;
f = [1 1];
n = 1;
while f(n)< temp
f(n+2)=f(n)+f(n+1);
n = n+1;
end
%%
k = 0;
num=1;
temp(1) = phi(0.5*(ak+bk));
i = 2;
while bk-ak>= L
lamudak = ak +(bk-ak)* (f(n-k-1)/f(n-k+1));
muk = ak +(bk-ak)* (f(n-k)/f(n-k+1));
if phi(lamudak)<phi(muk)
ak = ak;
bk = muk;
else
ak = lamudak;
bk = bk;
end
k=k+1;
num = num+1;
temp(i) = phi(0.5*(ak+bk));
disp(['这是Fibonacci--->第', num2str(num),'次迭代,当前目标函数最优值为',num2str(temp(i))])
i=i+1;
end
alpha = (ak+bk)/2;
end
上一篇: numpy矩阵添加一行或一列
下一篇: orcale 多行多列合并为多行一列