|
function [xmin,fmin,m]=multi_min(fx,a,b,Nt)
[~, f0]=fminbnd(fx,a,b)
m=1;
ij=1;
while 1
m=2*m;
d=(b-a)/m;
x=a:d:b;
ii=0;
xc=zeros(1,m);
fc=xc;
for k=1:m
[w,f,eflag]=fminbnd(fx,x(k),x(k+1));
if eflag>0
ii=ii+1;
xc(ii)=w;
fc(ii)=f;
end
end
[fmin,kk]=min(fc);
xmin=xc(kk);
if abs(f0-fmin)<1e-6
ij=ij+1;
if ij>Nt
break
end
elseif f0-fmin>1e-6
f0=fmin;
ij=1;
end
end |
|