% Griewank function L. LAURENT -- 16/11/2016 -- luc.laurent@lecnam.net
0001 %% Griewank function 0002 %L. LAURENT -- 16/11/2016 -- luc.laurent@lecnam.net 0003 0004 % sources available here: 0005 % https://bitbucket.org/luclaurent/optigtest/ 0006 % https://github.com/luclaurent/optigtest/ 0007 0008 % optiGTest - set of testing functions A toolbox to easy manipulate functions. 0009 % Copyright (C) 2017 Luc LAURENT <luc.laurent@lecnam.net> 0010 % 0011 % This program is free software: you can redistribute it and/or modify 0012 % it under the terms of the GNU General Public License as published by 0013 % the Free Software Foundation, either version 3 of the License, or 0014 % (at your option) any later version. 0015 % 0016 % This program is distributed in the hope that it will be useful, 0017 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0018 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0019 % GNU General Public License for more details. 0020 % 0021 % You should have received a copy of the GNU General Public License 0022 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0023 0024 % 0025 %global minimum : f(x1,x2)=0 for (0,...,0) 0026 % 0027 %Design space: -100<xi<100 0028 0029 function [p,dp]=funGriewank(xx) 0030 0031 %constants 0032 a=1/4000; 0033 b=1; 0034 0035 %evaluation and derivatives 0036 dim=size(xx,3); 0037 div=sqrt(reshape(1:dim,1,1,dim)); 0038 pa=bsxfun(@times,xx,1./div); 0039 p=a*sum(xx.^2,3)-prod(cos(pa),3)+b; 0040 % 0041 if nargout==2 0042 funP=@(i)prod(cos(pa(:,:,[1:i-1 i+1:end])),3); 0043 pb=arrayfun(funP,1:dim,'UniformOutput',false); 0044 pb=cell2mat(reshape(pb,1,1,dim)); 0045 % 0046 dp=2*a*xx... 0047 +bsxfun(@times,sin(pa),1./div).*pb; 0048 end 0049 end