Is this a bug in lsqcurvefit?

3 views (last 30 days)
Catalytic
Catalytic on 29 Mar 2019
Commented: Matt J on 4 Apr 2019
When I run this simple test of lsqcurvefit (this is R2018a), I get errors.
opts=optimoptions(@lsqcurvefit,'SpecifyObjectiveGradient',true,...
'JacobianMultiplyFcn',@Jfun);
p=lsqcurvefit(@modelfun,2,10,11,[],[],opts)
function [y,Jinfo]=modelfun(p,xdata)
y=xdata-p;
Jinfo=0;
end
function out=Jfun(Jinfo,Y,flag)
out=0;
end
The errors are
Too many input arguments.
Error in lsqcurvefit/jacobmult (line 291)
W = feval(mtxmpy_xdata,Jinfo,Y,flag,XDATA,varargin{:});
Error in snls (line 199)
g = feval(mtxmpy,A,fvec(:,1),-1,varargin{:});
Error in lsqncommon (line 167)
snls(funfcn,xC,lb,ub,flags.verbosity,options,defaultopt,initVals.F,initVals.J,caller,
...
Error in lsqcurvefit (line 271)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,allDefaultOpts,caller,...
Error in test1 (line 6)
p=lsqcurvefit(@modelfun,2,10,11,[],[],opts)
Looking at line 291 in lsqcurvefit shows that it is in fact trying to pass xdata as a 4th argument to the JacobMult function
function W = jacobmult(Jinfo,Y,flag,varargin)
W = feval(mtxmpy_xdata,Jinfo,Y,flag,XDATA,varargin{:});
end
I can see why it would make sense to pass xdata to the user-provided JacobMult function, in addition to Jinfo,Y, and flag, but nowhere in the documentation does it say to format the JacobMult function this way. Is this a coding bug or a documentation bug?
  1 Comment
Matt J
Matt J on 4 Apr 2019
Another question, sort of on the same subject. When the JacobianMutiplyFcn is used, what does the solver return for the jacobian output in the following?
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(___)

Sign in to comment.

Answers (0)

Categories

Find more on Physics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!