0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 function [p,dp]=funPenalty2(xx)
0033
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
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
0058
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