⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex0406.m

📁 基于MATLAB的微粒群工具箱
💻 M
字号:
function [optx,fval] = simplex2
bounds = ones(10,1) * [-5.12 5.12];
numvars = size(bounds,1);
rng = (bounds(:,2)-bounds(:,1))';
options = optimset('LargeScale','off');
options = optimset(options,'MaxFunEvals',500);
for i = 1 : 100
    x0 = rng.*(rand(1,numvars)) + bounds(:,1)';
    [x,lbest,exitflag] = fminsearch(@f,x0,options);
    if(i == 1)
        fval = lbest;
        optx = x;
    else
        fval = min(fval,lbest);
        if(fval == lbest)
            optx = x;
        end
    end
end
return

function y = f(x)
len=length(x);A=8;
y=0;
for i=1:len
    y=y+x(i)^2-A*cos(2*pi*x(i));
end
y=y+len*A;
return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -