Get Jacobian when using problem-based approach in Optimization Toolbox

4 visualizzazioni (ultimi 30 giorni)
When using lsqnonlin to solve a least squares problem, the jacobian gets returned as last argument:
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(___)
However, when using the problem-based approach, the jacobian isn't returned:
[sol,fval,exitflag,output,lambda] = solve(___)
Is there any way to get the jacobian also in this case?

Risposta accettata

Alan Weiss
Alan Weiss il 21 Feb 2021
Unfortunately, you cannot get the Jacobian output when using the problem-based approach. If you need it, then convert your problem using prob2struct and sove using lsqnonlin.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Commenti
Philipp Glira
Philipp Glira il 21 Feb 2021
Thank you.
I've tried to use the prob2struct. It works!
However, it seems that AD is used with solve(...), but not with lsqnonlin(...).
Here the output for solve(...)
Solving problem using lsqnonlin.
Norm of First-order
Iteration Func-count f(x) step optimality
0 1 3.47967 604
1 2 0.0755244 0.0178525 2.96
2 3 0.075441 8.92775e-05 7.32e-05
3 4 0.075441 2.21069e-09 9.17e-12
Optimization completed: The first-order optimality measure, 9.170276e-12,
is less than options.OptimalityTolerance = 1.000000e-06.
and here for lsqnonlin(...):
Norm of First-order
Iteration Func-count f(x) step optimality
0 3 3.47967 604
1 6 0.0755244 0.0178525 2.96
2 9 0.075441 8.92774e-05 7.32e-05
3 12 0.075441 2.5088e-09 5.66e-08
Optimization completed: The first-order optimality measure, 5.656498e-08,
is less than options.OptimalityTolerance = 1.000000e-06.
Is there any way to activate AD also in the lsqnonlin-Version?
I'm using the beta of Matlab 2021a.
Alan Weiss
Alan Weiss il 21 Feb 2021
You are quite right, AD does not apply to the lsqnonlin version. The only thing that I can think to try sounds terrible: run using solve first, then feed that solution as a starting point into lsqnonlin in order to get a Jacobian estimate.
By the way, if you are showing me results from your real problem, then the first-order optimality output shows that the Jacobian is either zero or you have some bound constraints.
Alan Weiss
MATLAB mathematical toolbox documentation

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Systems of Nonlinear Equations in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by