help buscarnd Unconstrained global optimization using adaptive random search. [xo,Ot,nS]=buscarnd(S,x0,ip,nOt,samples,Lb,Ub,problem,tol,mxit,R,red,mem) S: objective function x0: initial point ip: (0): no plot (default), (>0) plot figure ip with pause, (<0) plot figure ip nOt: maximum number of optimal points (default = 1) samples: number of samples per stage (default = 3*size(x0(:),1)) Lb, Ub: lower and upper bound vectors to plot (default = x0*(1+/-2)) problem: (-1): minimum (default), (1): maximum tol: tolerance (default = 1e-4) mxit: maximum number of stages (default = 50*(1+4*~(ip>0))) R: axis vector of the hyperellipse centered in x0 (default = max(0.1*abs(x0+~x0),1)) red: factor to reduce the size of the axis vector (0,1) (default = 0.2) mem: number of stored points during the exploration phase [0, min(18,samples-1)] xo: matrix of optimal points (column vectors) Ot: vector of optimal values of S nS: number of objective function evaluations [xo,Ot,nS]=buscarnd('test9',[1 1],1,5,20,[-5 -5],[5 5],[],[],[],[],[],5) Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Warning Buscarnd: reached maximum number of stages! xo = 3.0002 2.0000 Ot = 8.7099e-007 nS = 1001 help buscarnd Unconstrained global optimization using adaptive random search. [xo,Ot,nS]=buscarnd(S,x0,ip,nOt,samples,Lb,Ub,problem,tol,mxit,R,red,mem) S: objective function x0: initial point ip: (0): no plot (default), (>0) plot figure ip with pause, (<0) plot figure ip nOt: maximum number of optimal points (default = 1) samples: number of samples per stage (default = 3*size(x0(:),1)) Lb, Ub: lower and upper bound vectors to plot (default = x0*(1+/-2)) problem: (-1): minimum (default), (1): maximum tol: tolerance (default = 1e-4) mxit: maximum number of stages (default = 50*(1+4*~(ip>0))) R: axis vector of the hyperellipse centered in x0 (default = max(0.1*abs(x0+~x0),1)) red: factor to reduce the size of the axis vector (0,1) (default = 0.2) mem: number of stored points during the exploration phase [0, min(18,samples-1)] xo: matrix of optimal points (column vectors) Ot: vector of optimal values of S nS: number of objective function evaluations [xo,Ot,nS]=buscarnd('test9',[1 1],1,5,20,[-5 -5],[5 5],[],[],5000,[],[],5) Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Error in ==> V:\cursos\pos\otimiza\aulas\buscarnd.m On line 253 ==> disp('Pause: hit any key to continue...'); pause; help buscarnd Unconstrained global optimization using adaptive random search. [xo,Ot,nS]=buscarnd(S,x0,ip,nOt,samples,Lb,Ub,problem,tol,mxit,R,red,mem) S: objective function x0: initial point ip: (0): no plot (default), (>0) plot figure ip with pause, (<0) plot figure ip nOt: maximum number of optimal points (default = 1) samples: number of samples per stage (default = 3*size(x0(:),1)) Lb, Ub: lower and upper bound vectors to plot (default = x0*(1+/-2)) problem: (-1): minimum (default), (1): maximum tol: tolerance (default = 1e-4) mxit: maximum number of stages (default = 50*(1+4*~(ip>0))) R: axis vector of the hyperellipse centered in x0 (default = max(0.1*abs(x0+~x0),1)) red: factor to reduce the size of the axis vector (0,1) (default = 0.2) mem: number of stored points during the exploration phase [0, min(18,samples-1)] xo: matrix of optimal points (column vectors) Ot: vector of optimal values of S nS: number of objective function evaluations [xo,Ot,nS]=buscarnd('test9',[1 1],-1,5,20,[-5 -5],[5 5],[],[],5000,[5 5],[],5) Warning Buscarnd: reached maximum number of stages! xo = -2.8051 3.0001 3.5846 -3.7793 3.1313 2.0001 -1.8480 -3.2830 Ot = 1.0e-005 * 0.0006 0.0292 0.1531 0.2254 nS = 100001 type test9 function S=test(x) % Himmelblau, 1972 % x0 = [1, 1]' % xo = [3, 2]', xo = [3.58443, -1.84813]', xo = [-3.7793, -3.2832]' e xo = [-2.8051, 3.1313]' % S(xo) = 0 % local maximum: xo = [-0.2708, -0.9230]', S(xo) = 181.6 S=(x(1).^2+x(2)-11).^2+(x(1)+x(2).^2-7).^2; [xo,Ot,nS]=buscarnd('test9',[1 1],-1,5,20,[-5 -5],[5 5],[],[],2000,[1 1],[],5) Warning Buscarnd: reached maximum number of stages! xo = 3.5844 -2.8051 3.0000 -1.8482 3.1313 1.9999 Ot = 1.0e-006 * 0.0117 0.2202 0.2595 nS = 40001 cd ../naturais pwd ans = V:\cursos\pos\otimiza\naturais what dir . .. Ant_Colony curso_esly swarm cd swarm dir . buscarnd.m powell.for .. ex_swarm.m swarm.for Swarm.doc naturais.m swarm.m animacao.avi otimo.for swarm6funcoes.MCD dir ../../otimiza/nat* ../../otimiza/nat* not found. dir ../../otimiza/nat*.m ../../otimiza/nat*.m not found. type naturais.m [xo,Ot,nS]=buscarnd('ex_swarm',[0 0],0,1,20,[-1 -1],[1 1],[],[],[],[2 2]) [xo,Ot,nS]=swarm('ex_swarm',[0 0],0,[1 1],[-1 -1],[1 1],[],100,20) % Para achar os dois melhores otimos [xo,Ot,nS]=buscarnd('ex_swarm',[0 0],0,2,20,[-1 -1],[1 1],[],[],[],[2 2]) % Se colocar o terceiro argumento como -1 nos dois algoritmos, entao faz o grafico. tic for i=1:100, [xo,Ot(i),nS]=buscarnd('ex_swarm',[0 0],0,1,20,[-1 -1],[1 1],[],[],[],[2 2]); end tb=toc nb=find(Ot < -17); size(nb,2) figure(1); hist(Ot); legend('buscarnd'); tic for i=1:100, [xo,Ots(i),nS]=swarm('ex_swarm',[0 0],0,[1 1],[-1 -1],[1 1],[],100,20); end ts=toc ns=find(Ots < -17); size(ns,2) figure(2); hist(Ots); legend('swarm'); cd ../../otimiza ??? Name is nonexistent or not a directory cd ../../aulas dir na*.* na*.* not found. help swarm Hard constrained global optimization using SWARM. [xo,Ot,nS]=swarm(S,x0,ip,isb,Lb,Ub,R,nger,npas,problem,c1,c2) S: objective function x0: inital point ip: (0): no plot (default), (>0) plot figure ip with pause, (<0) plot figure ip isb: isb(i)=1 is i-th variable is bounded, otherwise isb(i)=0 (default = 0) Lb, Ub: lower and upper bound vectors (default = x0*(1+/-2) for plot if isb(i)=0) R: axis vector of the hyperellipse centered in x0 (default = max(0.1*abs(x0+~x0),1)) nger: number of generations or flights (default = 50) npas: number of birds (default = 10) problem: (-1): minimum (default), (1): maximum c1: local search parameter (default = 1) c2: global search parameter (default = 1) xo: optimal point Ot: optimal values of S nS: number of objective function evaluations [xo,Ot,nS]=swarm('test9',[1 1],-1,[],[-5 -5],[5 5],[5 5],200,10) xo = 3.5844 -1.8481 Ot = 0 nS = 2010 [xo,Ot,nS]=swarm('test9',[1 1],1,[],[-5 -5],[5 5],[5 5],200,10) Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Error in ==> V:\cursos\pos\otimiza\aulas\swarm.m On line 178 ==> disp('Pause: hit any key to continue...'); pause; cd ../../naturais ??? Name is nonexistent or not a directory cd ../naturais cd swarm type naturais [xo,Ot,nS]=buscarnd('ex_swarm',[0 0],0,1,20,[-1 -1],[1 1],[],[],[],[2 2]) [xo,Ot,nS]=swarm('ex_swarm',[0 0],0,[1 1],[-1 -1],[1 1],[],100,20) % Para achar os dois melhores otimos [xo,Ot,nS]=buscarnd('ex_swarm',[0 0],0,2,20,[-1 -1],[1 1],[],[],[],[2 2]) % Se colocar o terceiro argumento como -1 nos dois algoritmos, entao faz o grafico. tic for i=1:100, [xo,Ot(i),nS]=buscarnd('ex_swarm',[0 0],0,1,20,[-1 -1],[1 1],[],[],[],[2 2]); end tb=toc nb=find(Ot < -17); size(nb,2) figure(1); hist(Ot); legend('buscarnd'); tic for i=1:100, [xo,Ots(i),nS]=swarm('ex_swarm',[0 0],0,[1 1],[-1 -1],[1 1],[],100,20); end ts=toc ns=find(Ots < -17); size(ns,2) figure(2); hist(Ots); legend('swarm'); type ex_swarm function S=func(x) v1=20*x(1); v2=20*x(2); S=-sin(v1/pi).^2 .* sin(v2/pi).^2 .* (abs(v1)+abs(v2)+0.1*(v1+v2))+(v1.*v1+v2.*v2)/30; % % [xo,Ot,nS]=swarm('ex_swarm',[0 0],0,[1 1],[-1 -1],[1 1],[],100,20) % naturais xo = 0.7411 0.7411 Ot = -17.9602 nS = 861 xo = 0.7411 0.7411 Ot = -17.9602 nS = 2020 xo = 1.2306 0.7410 0.7408 -0.7396 Ot = -15.8445 -14.9991 nS = 1561 tb = 20.1890 ans = 60 ts = 25.4470 ans = 42 cd ../../aulas help newton Unconstrained optimization using Newton. [xo,Ot,nS]=newton(S,x0,ip,G,H,Lb,Ub,problem,tol,mxit) S: objective function x0: initial point ip: (0) no plot (default), (>0) plot figure ip with pause, (<0) plot figure ip G: gradient vector function H: Hessian matrix function Lb, Ub: lower and upper bound vectors to plot (default = x0*(1+/-2)) problem: (-1): minimum (default), (1): maximum tol: tolerance (default = 1e-4) mxit: maximum number of iterations (default = 50*(1+4*~(ip>0))) xo: optimal point Ot: optimal value of S nS: number of objective function evaluations [xo,Ot,nS]=newton('test9',[1 1],1,'gtest9','htest9',[-5 -5],[5 5]) Pause: hit any key to continue... ??? Cannot find function 'htest9'. Error in ==> V:\cursos\pos\otimiza\aulas\newton.m On line 135 ==> he=feval(H,xo)*problem; dir h* hkjeeves.m htest1.m htest2.m [xo,Ot,nS]=newton('test9',[1 1],1,'gtest9',[],[-5 -5],[5 5]) Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... xo = 3.3852 0.0739 Ot = 13.3119 nS = 14 [xo,Ot,nS]=newton('test9',[0 -3],1,'gtest9',[],[-5 -5],[5 5]) Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... xo = -0.1280 -1.9537 Ot = 178.3372 nS = 6 [xo,Ot,nS]=newton('test9',[-.5 1],1,'gtest9',[],[-5 -5],[5 5]) Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... xo = 0.0867 2.8843 Ot = 67.7192 nS = 7 [xo,Ot,nS]=newton('test9',[-2 1],1,'gtest9',[],[-5 -5],[5 5]) Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... Pause: hit any key to continue... xo = -2.8051 3.1313 Ot = 8.5858e-015 nS = 14 quit