-
大小: 3KB文件類型: .m金幣: 1下載: 0 次發(fā)布日期: 2021-01-11
- 語言: Matlab
- 標(biāo)簽: matlab??隨機(jī)尋優(yōu)??
資源簡介
隨機(jī)搜索最優(yōu)值(最大或者最小),matlab的m文件格式
代碼片段和文件信息
function?[Xf_X]=Random_Search_Opt
global?n?m?a?b??epsilong?alpha0?Nmax????????%全局變量
format?short?e??????????????????????????%定義結(jié)果顯示精度
init=menu(‘參數(shù)重新初始化,還是默認(rèn)?‘‘重置‘‘默認(rèn)‘);???%彈出初始化參數(shù)
if?init==1
????n=input(‘輸入設(shè)計(jì)變量數(shù):n=‘);
????m=input(‘輸入約束條件數(shù)目,并請重新定義get_initShape文件中約束條件:m=‘);
????a=input(‘設(shè)計(jì)變量下限,如[1?2?3?...n]:a=‘);
????b=input(‘設(shè)計(jì)變量上限,如[2?3?4?...n+1]:b=‘);
????epsilong=input(‘精度等級,如0.0001:epsilong=‘);
????alpha0=input(‘輸入初始步長:alpha0=‘);
????Nmax=input(‘輸入隨機(jī)方向的最大數(shù)目如50--500:Nmax=‘);
else
????n=2;m=3;
????a=[-3-10];b=[610];
????epsilong=0.0001;alpha0=1;Nmax=50;
end
who
X0=enable_random_Point;?????????%產(chǎn)生可行隨機(jī)點(diǎn)X0
X=X0;f0=f(X);alpha=alpha0;
while?1
????k=1;jj=0;
????do2=1;
????while?do2|~(k>Nmax)
????????[XS]=get_S_X(alphaX0);????????%S為隨機(jī)搜索方向
????????while?Justy_
評論
共有 條評論