Code covered by the BSD License

# Files for the 2012 Webinar "Tips and Tricks - Getting Started Using Optimization with MATLAB"

### Seth DeLand (view profile)

These are the files that were used for the demonstrations in the webinar.

compareApproaches.m
```%% Compare performance of Global Optimization Solvers

% Copyright (c) 2012, The MathWorks, Inc.
%% Setup Problem
options = optimset('Disp','none','Algorithm','interior-point');
x0 = [0 1.5];
lb = [-3 -3];
ub = [ 3  3];

%% MultiStart
fprintf('MultiStart Running ...\n\n');
tic
problem = createOptimProblem('fmincon','objective',@peaksObj,'x0',x0,...
'lb',lb,'ub',ub,'nonlcon',@peaksCon,'options',options);
ms = MultiStart;
ms.Display = 'none';
[x,fval,exitflag,output] = run(ms, problem, 10);
msTot = output.funcCount;
tms = toc;

%% GlobalSearch
fprintf('GlobalSearch Running ...\n\n');
tic
problem = createOptimProblem('fmincon','objective',@peaksObj,'x0',x0,...
'lb',lb,'ub',ub,'nonlcon',@peaksCon,'options',options);
gs = GlobalSearch;
gs.Display = 'none';
[x,fval,exitflag,output] = run(gs, problem);
gsTot = output.funcCount;
tgs = toc;

%% Pattern Search
fprintf('Pattern Search Running ...\n\n');
tic
options = psoptimset('Display','none');
[x,fval,exitflag,output] = patternsearch(@peaksObj,x0,[],[],[],[],lb,ub,@peaksCon,options);
psTot = output.funccount;
tps = toc;

%% Simulated Annealing
fprintf('Simulated Annealing Running ...\n\n');
tic
options = saoptimset('Display','none');
[x,fval,exitflag,output] = simulannealbnd(@peaksObj,x0,lb,ub,options);
saTot = output.funccount;
tsa = toc;

%% Genetic Algorithm
fprintf('Genetic Algorithm Running ...\n\n');
tic
options = gaoptimset('Disp','none');
[x,fval,exitflag,output] = ga(@peaksObj,2,[],[],[],[],lb,ub,@peaksCon,options);
gaTot = output.funccount;
tga = toc;

%% Tabulate Results
fprintf('\n\nResults from different Global Optimization solvers (default settings):\n');
fprintf('\nSolver\t\t\t\t\tFcn Calls\tTime(s)\n');
fprintf('--------------------------------------------------------------\n')
fprintf('MultiStart              \t%d \t\t%f\n',msTot,tms);
fprintf('GlobalSearch            \t%d \t\t%f\n',gsTot,tgs);
fprintf('Pattern Search          \t%d \t\t%f\n',psTot,tps);
fprintf('Simulated Annealing     \t%d \t\t%f\n',saTot,tsa);
fprintf('Genetic Algorithm       \t%d \t\t%f\n',gaTot,tga);

```