Get Jacobian when using problem-based approach in Optimization Toolbox

4 次查看(过去 30 天)
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?

采纳的回答

Alan Weiss
Alan Weiss 2021-2-21
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 个评论
Philipp Glira
Philipp Glira 2021-2-21
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 2021-2-21
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by