📄 danchunxin.asv
字号:
function [fx,fy,iter,out] = DanchunXin(Init,dim,N,U,Y,R,E,rou)
if size(Init) ~= [dim,dim+1]
error('error input length of parament Init!');
end
%initialization
alp = 1;
gamma = 2;
beta = 0.5;
%
Fval = zeros(1,dim+1);
Point = Init;%输入4个点
iter = 0;
while 1
iter = iter+1;
for m=1:dim+1
Fval(m) = myfun(U,Y,R,E,N,Point(:,m));
end
maxIndex = find(Fval==max(Fval));
maxp = Point(:,maxIndex);
minp = Point(:,find(Fval==min(Fval)));
subfval = [Fval(1:maxIndex-1),Fval(maxIndex+1:dim+1)];
subp = Point(:,find(subfval==max(subfval)));
FsubVal = myfun(U,Y,R,E,N,subp);
%center
centp = (sum(Point')'-maxp)./dim;
FcentVal = myfun(U,Y,R,E,N,centp);
%reflection
new2p = centp+alp*(centp - maxp);
Fnew2Val = myfun(U,Y,R,E,N,new2p);
%step4
if Fnew2Val < FsubVal
%expend
new3p = centp + gamma*(new2p - centp);
Fnew3Val = myfun(U,Y,R,E,N,new3p);
%step5
if Fnew3Val<Fnew2Val
%maxp = new3p;
Point(:,maxIndex) = new3p;
else
%maxp = new2p;
Point(:,maxIndex) = new2p;
end
elseif and(myfun(U,Y,R,E,N,minp)<=Fnew2Val,Fnew2Val<=FsubVal)
%maxp = new2p;
Point(:,maxIndex) = new2p;
elseif Fnew2Val>FsubVal
%compress
FnewpVal = min(myfun(U,Y,R,E,N,maxp),Fnew2Val);
if FnewpVal == Fnew2Val
xh = new2p;
else
xh = maxp;
end
new4p = centp+beta*(xh - centp);
Fnew4Val = myfun(U,Y,R,E,N,new4p);
%step6
if Fnew4Val<=myfun(U,Y,R,E,N,xh)
%maxp = new4p;
Point(:,maxIndex) = new4p;
else
%condense
for m = 1:dim+1
Point(:,m) = Point(:,m)+0.5*(minp-Point(:,m));
end
end
end
%step7
if converge(Point, centp,U,Y,R,E,N)<eps*10^10
break;
else
continue;
end
end
fx = minp;
[fy,out] = myfun(U,Y,R,E,N,minp);
function sumf = converge(Point, centp,U,Y,R,E,N)
Psize = size(Point);
dim = Psize(1);
%fval = zeros(1,dim+1);
fcentpVal = myfun(U,Y,R,E,N,centp);
sumf = 0;
for m = 1:dim+1
%fval(m) = myfun(Point(:,m));
sumf = sumf+(myfun(U,Y,R,E,N,Point(:,m)) - fcentpVal)^2;
end
sumf = (sumf/(dim+1))^0.5;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -