funSumSquare

PURPOSE ^

% Sum Square function

SYNOPSIS ^

function [p,dp,infos] = funSumSquare(xx,dim)

DESCRIPTION ^

% Sum Square function
L. LAURENT -- 16/09/2011 -- luc.laurent@lecnam.net

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Sum Square function
0002 %L. LAURENT -- 16/09/2011 -- 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 global: f(xi)=0 pour (x1,x2,x3,x4)=(0,...,0)
0026 %
0027 %design space: -10<xi<10
0028 
0029 
0030 function [p,dp,infos] = funSumSquare(xx,dim)
0031 
0032 % demo mode
0033 dem=false;
0034 if nargin==0
0035     pas=50;
0036     borne=10;
0037     [x,y]=meshgrid(linspace(-borne,borne,pas));
0038     xx=zeros(pas,pas,2);
0039     xx(:,:,1)=x;xx(:,:,2)=y;
0040     dem=true;
0041 end
0042 if ~isempty(xx)
0043     % number of design variables
0044     nbvar=size(xx,3);
0045     
0046     if nbvar==1
0047         error(['Wrong input variables ',mfilename]);
0048     else
0049         nu(1,1,:)=1:nbvar;
0050         nu=repmat(nu,[size(xx,1),size(xx,2),1]);
0051         cal=nu.*xx.^2;
0052         p=sum(cal,3);
0053         
0054         if nargout==2||dem
0055             dp=2*nu.*xx;
0056         end
0057         
0058     end
0059 else
0060     nbvar=dim;
0061     p=[];
0062     dp=[];
0063 end
0064 % output: information about the function
0065 if nargout==3
0066     pts=zeros(1,nbvar);
0067     infos.min_glob.X=pts;
0068     infos.min_glob.Z=0;
0069     infos.min_loc.Z=NaN;
0070     infos.min_loc.X=NaN;
0071 end
0072 
0073 % demo mode
0074 if nargin==0
0075     figure
0076     subplot(1,3,1)
0077     surf(x,y,p);
0078     axis('tight','square')
0079     xlabel('x'), ylabel('y'), title(mfilename)
0080     subplot(1,3,2)
0081     surf(x,y,dp(:,:,1));
0082     axis('tight','square')
0083     xlabel('x'), ylabel('y'), title('Grad. X Sum square')
0084     subplot(1,3,3)
0085     surf(x,y,dp(:,:,2));
0086     axis('tight','square')
0087     xlabel('x'), ylabel('y'), title('Grad. Y Sum square')
0088     p=[];
0089 end
0090 
0091 end

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