Incorrectly reported Func-count in lsqcurvefit. Also, MaxIterations not obeyed
Show older comments
In R2020b and R20201a, I have done the following test of lsqcurvefit. The test function below test(M) uses lsqcurvefit to solve a simple linear equation A*x=y under the assumption that the first M variables are known (enforced by setting lb(1:M)=ub(1:M)) and counts the number of function evaluations. I find, strangely, that for any M>1, an additional N=100 function evaluations are done beyond what is reported by lsqcurvefit (and beyond what should be necessary). Also, even though I have specified MaxIterations=5, six iterations are sometimes done. Does anyone know why this occurs?
TRUECOUNTS= test(0),
TRUECOUNTS=test(1),
TRUECOUNTS=test(99),
function TRUECOUNTS=test(M)
if nargin<1, M=0; end
N=100;
xtrue=(1:N).'; %true parameter values
Adata=rand(N);
TRUECOUNTS=0;
ydata=F(xtrue,Adata);
lb=-inf(N,1); ub=+inf(N,1);
known=1:M; %The first M variables are known
lb(known)=xtrue(known);
ub(known)=xtrue(known);
opts=optimoptions(@lsqcurvefit, 'Display','iter','MaxIterations',5);
TRUECOUNTS=0;
lsqcurvefit(@F,zeros(N,1),Adata,ydata,lb,ub,opts);
disp ' '
function y=F(x,A)
y=A*x;
TRUECOUNTS=TRUECOUNTS+1;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!