How to avoid unrecognized option names using optimget

I am using lsqcurvefit and receiving errors related to the function lsqncommon. I did not have these errors in the past, so this may be due to changes with more recent versions of Matlab. How can I edit the lines below to avoid these errors? Thank you.
Error 1. "Unrecognized option name 'InitDamping'. See OPTIMSET for possibilities."
Relevant lines of lsqncommon:
algorithm = optimget(options,'Algorithm',defaultopt,optimgetFlag);
initDamping = optimget(options,'InitDamping',defaultopt,optimgetFlag);
if ~iscell(algorithm)
initLMparam = initDamping;
else
initLMparam = algorithm{2}; % Initial Levenberg-Marquardt parameter
algorithm = algorithm{1}; % Algorithm string
end
Error 2. "Unrecognized option name 'ProblemdefOptions'. See OPTIMSET for possibilities."
Relevant lines of lsqncommon:
ProblemdefOptions = optimget(options, 'ProblemdefOptions',defaultopt,optimgetFlag);
FromEqnSolve = false;
if ~isempty(ProblemdefOptions) && isfield(ProblemdefOptions, 'FromEqnSolve')
FromEqnSolve = ProblemdefOptions.FromEqnSolve;
end

8 Comments

You should not edit MathWorks-authored files. Show us the code that you wrote and are running, and let's discuss changes to that.
Thank you for getting back to me. This is the structure of the code I am using that is related to lsqcurvefit. It worked with previous versions of Matlab in 2016-2019. I am seeing the errors above with the 2023 and 2024 versions. The errors above refer to specific lines of the function lsqncommon, not my own code. What do I have to do to avoid those errors? Thank you.
options = optimoptions('lsqcurvefit', ...
'Display', 'off', ...
'MaxFunctionEvaluations', MaxFunEvals, ...
'MaxIterations', MaxIter, ...
'FunctionTolerance', TolFun, ...
'StepTolerance', TolX, ...
'OptimalityTolerance', TolOpt, ...
'Algorithm', 'trust-region-reflective');
[Parameters_Fit, RSS, residual, exitflag, output, ~, jacobian] = ...
lsqcurvefit(function_handle, Parameters_Guess, ...
X_data, Y_data, ...
Parameters_Lower, Parameters_Upper, ...
options);
I wonder whether those are options that are present only if you have Global Optimization Toolbox installed?
It could be, I am not sure. Is there a way to find out?
You need to provide a simplification of your code that we can run and reproduce the error. The code structure you've outlined looks fine, and works fine in the online Matlab engine, as demonstrated below,
[MaxFunEvals,MaxIter,TolFun,TolX,TolOpt]=deal(1e6,100,1e-6,1e-6,1e-6);
function_handle=@(p,xd) xd+p;
X_data=1:5;
Y_data=X_data+pi;
Parameters_Guess=3;
[Parameters_Lower, Parameters_Upper]=deal(0,10);
options = optimoptions('lsqcurvefit', ...
'Display', 'off', ...
'MaxFunctionEvaluations', MaxFunEvals, ...
'MaxIterations', MaxIter, ...
'FunctionTolerance', TolFun, ...
'StepTolerance', TolX, ...
'OptimalityTolerance', TolOpt, ...
'Algorithm', 'trust-region-reflective');
[Parameters_Fit, RSS, residual, exitflag, output, ~, jacobian] = ...
lsqcurvefit(function_handle, Parameters_Guess, ...
X_data, Y_data, ...
Parameters_Lower, Parameters_Upper, ...
options)
Parameters_Fit = 3.1416
RSS = 1.8063e-25
residual = 1×5
1.0e-12 * -0.1901 -0.1901 -0.1901 -0.1901 -0.1901
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
exitflag = 1
output = struct with fields:
firstorderopt: 6.5179e-12 iterations: 3 funcCount: 8 cgiterations: 0 algorithm: 'trust-region-reflective' stepsize: 4.3841e-07 message: 'Local minimum found....' bestfeasible: [] constrviolation: []
jacobian = 5x1 sparse double column vector (5 nonzeros)
(1,1) 1.0000 (2,1) 1.0000 (3,1) 1.0000 (4,1) 1.0000 (5,1) 1.0000
Note that the user is using R2024a, but MATLAB Answers is using R2024b. The lsqncommon routine was rewritten between the two versions, and no longer has the problematic call.
The lsqncommon routine was rewritten between the two versions, and no longer has the problematic call.
I can't find any documentation of that. I don't think we've even identified what the "problematic call" is, because we haven't seen the OP's actual code.
When I run the hypothetical code that I proposed in R2024a, it still runs fine.
Thank you both. Although I am using R2024a, that particular code still uses an older (2016-2019) version of lsqcurvefit. This older version of lsqcurvefit gives me the same error when I try the simplified code above:
Error using optimget
Unrecognized option name 'InitDamping'. See OPTIMSET for possibilities.
Error in lsqncommon
initDamping = optimget(options,'InitDamping',defaultopt,optimgetFlag);
Error in lsqcurvefit
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,allDefaultOpts,caller,...
The current version of lsqcurvefit does not give me these errors, and the simplified code above runs just fine.
Something has changed in lsqcurvefit between 2016-2019 and now that is causing this different behavior.

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 31 Oct 2024
Edited: Matt J on 31 Oct 2024
Although I am using R2024a, that particular code still uses an older (2016-2019) version of lsqcurvefit.
If so, problem solved. Use the version of lsqcurvefit that accompanies R2024a. It is obviously dangerous and unpredictable to mix Mathworks-authored files from different Matlab releases.

More Answers (0)

Products

Release

R2024a

Asked:

on 31 Oct 2024

Commented:

on 31 Oct 2024

Community Treasure Hunt

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

Start Hunting!