📄 plus_step_search.m
字号:
function [vec,times,minip]=plus_step_search(str,ini,step,multiple)
% File name:plus_step_search.m
% Author:Yan Anxin
% ID number:081810
% Date:finished on 2008.11.24
% Description:
% Here defines a function,to determine the initial search interval by plus-step-search-method
% In the syntax [vec,times,minip]=plus_step_search(str,ini,step,multiple),
% str----input,means the expression of objective function
% ini----input,sets the initial searching point to ini
% step----input,sets initial searching step
% multiple----input,sets multiple of the plusing step
% vec=plus_step_search(str,ini,step,multiple) attempts to find vec, i.e. the initial search interval
% [vec,times]=plus_step_search(str,ini,step,multiple) returns times, i.e. the times of iterative
% [vec,times,minip]=plus_step_search(str,ini,step,multiple) returns minip, i.e. the minimum of sorting point
f=sym(str);
syms x
times=0;h(1)=step; %setting initial value
y(1)=ini;y(2)=y(1)+h(1);
if subs(f,x,y(2))<subs(f,x,y(1)) %searching forward
k=3;
while 1
h(k-1)=h(k-2)*multiple;times=times+1;
y(k)=y(k-1)+h(k-1);
if subs(f,x,y(k))>=subs(f,x,y(k-1)),break,end
k=k+1;
end
else %searching backward
y(3)=y(1)-h(1);k=3;
while subs(f,x,y(k))<subs(f,x,y(k-1))
k=k+1;times=times+1;
h(k-2)=h(k-3)*multiple;
y(k)=y(k-1)-h(k-2);
end
end
y(k+1)=0.5*(y(k)+y(k-1)); %sorting of four points
b=[k-2:k-1 k+1 k];
B=[subs(f,x,y(b))];
[C,D]=min(B);
if y(b(D-1))<=y(b(D+1)),vec=y(b([D-1 D+1]));else vec=[y(b(D+1)) y(b(D-1))];end
minip=y(b(D));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -