funPenalty2

PURPOSE ^

% Penalty 2 function

SYNOPSIS ^

function [p,dp]=funPenalty2(xx)

DESCRIPTION ^

% Penalty 2 function
L. LAURENT -- 21/03/2017 -- luc.laurent@lecnam.net

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Penalty 2 function
0002 %L. LAURENT -- 21/03/2017 -- 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(x)=0 for xi=-1
0026 %
0027 %Design space: -50<xi<50
0028 %
0029 
0030 
0031 
0032 function [p,dp]=funPenalty2(xx)
0033 %constants
0034 a=0.1;
0035 b=3*pi;
0036 c=1;
0037 d=2*pi;
0038 e=5;
0039 f=100;
0040 g=4;
0041 
0042 %evaluation and derivatives
0043 %
0044 pa=sin(b*xx(:,:,1));
0045 pb=xx(:,:,1:end-1)-c;
0046 sc=sin(b*xx(:,:,2:end));
0047 pc=c+sc.^2;
0048 pd=xx(:,:,end)-c;
0049 se=sin(d*xx(:,:,end));
0050 pe=c+se.^2;
0051 %
0052 u=zeros(size(xx));
0053 IXb=abs(xx)>e;
0054 u(IXb)=f*(abs(xx(IXb))-e).^g;
0055 %
0056 p=a*(pa.^2+sum(pb.^2.*pc,3)+pd.^2.*pe)+sum(u,3);
0057 %p=a*sum(pb.^2.*pc,3);
0058 %keyboard
0059 %
0060 if nargout==2
0061     %
0062     dp=zeros(size(xx));
0063     %
0064     du=zeros(size(xx));
0065     du(IXb)=f*e*sign(xx(IXb)).*(abs(xx(IXb))-b).^(f-1);
0066     %
0067     ppa=cos(b*xx(:,:,1));
0068     cc=cos(b*xx(:,:,2:end));
0069     ce=cos(d*xx(:,:,end));
0070     %
0071     dp(:,:,1)=2*a*b.*pa.*ppa...
0072         +2*a*pb(:,:,1).*pc(:,:,1)...
0073         +du(:,:,1);
0074     dp(:,:,end)=2*a*b.*sc(:,:,end).*cc(:,:,end).*pb(:,:,end).^2 ...
0075         +2*a*pd.*pe...
0076         +2*d*a*ce.*se.*pd.^2 ...
0077         +du(:,:,end);
0078     dp(:,:,2:end-1)=2*a*b*sc(:,:,1:end-1).*cc(:,:,1:end-1).*pb(:,:,1:end-1).^2 ...
0079         +2*a*pb(:,:,2:end).*pc(:,:,2:end)...
0080         +du(:,:,2:end-1);
0081 end

Generated on Tue 28-May-2019 16:00:34 by m2html © 2005