As further evidence of this problem, I've applied DerivativeCheck to the simplified example in my initial post, but looping over a range of values for DiffMinChange/DiffMaxChange. The code fails to find settings that succeed. I don't think I have the formulas for the Jacobian wrong. Is there something I'm missing about how to make this work?
N=100;
delta=logspace(-12,-1,N);
count=0;
for i=1:length(delta)
options=optimoptions(@lsqnonlin,'DerivativeCheck','on',...
'Jacobian','on',...
'DiffMinChange',delta(i)/1000,'DiffMaxChange',delta(i));
try
lsqnonlin(@fun,0,[],[],options);
catch ME
if strcmp(ME.identifier,'optimlib:validateFirstDerivatives:InvalidGrad')
count=count+1;
end
end
end
if count==N, disp 'All delta choices failed'; end
function [F,J]=fun(x)
F=[1000+0.9*x ; cos(100*x)];
J=[0.9;-100*sin(100*x)];