www.gusucode.com > globaloptim 案例源码程序 matlab代码 > globaloptim/MinimizeaSimpleFunctionwithBoundsExample.m

    %% Minimize a Simple Function with Bounds  
% Minimize a simple function of two variables with bound constraints.   

%% 
% Define the objective function. 
fun = @(x)x(1)*exp(-norm(x)^2);  

%% 
% Set bounds on the variables. 
lb = [-10,-15];
ub = [15,20];  

%% 
% Call |particleswarm| to minimize the function.
rng default  % For reproducibility
nvars = 2;
x = particleswarm(fun,nvars,lb,ub)