How to replace my optimset with equivalent optimoptions ?

Hi all
using Fsolve, I am getting into difficulties and want to use Jacobian and Hessian as well , but first I need to pass from optimset to optimoptions
currently my Options are :
options = optimset('Display','iter','MaxFunEvals',1e6,'MaxIter',1e6,'TolFun',1e-3,'DerivativeCheck','on','Diagnostics','on');
so first, I need to have the equivalent optimoptions and then include Jacobian and Hessian.
since for some of my input data no solution is found ( Func-Count = 1.5e+7 ) , I need to imrpove my solution

 採用された回答

Matt J
Matt J 2019 年 7 月 3 日
編集済み: Matt J 2019 年 7 月 3 日

1 投票

Why not just,
options = optimoptions(@fsolve, 'Display','iter','MaxFunEvals',1e6,'MaxIter',1e6,...
'TolFun',1e-3,'DerivativeCheck','on','Diagnostics','on');

22 件のコメント

farzad
farzad 2019 年 7 月 3 日
thank you
what about Hessian and Jacob ?
Matt J
Matt J 2019 年 7 月 3 日
For the Jacobian, set 'SpecifyObjectiveGradient' to true, and follow instructions and examples here,
farzad
farzad 2019 年 7 月 3 日
thank you
this is suggested in the page :
options = optimoptions('fsolve','SpecifyObjectiveGradient','on')
I get
Error: Invalid value for OPTIONS parameter SpecifyObjectiveGradient: must be logical TRUE or FALSE.
Torsten
Torsten 2019 年 7 月 3 日
編集済み: Torsten 2019 年 7 月 3 日
options = optimoptions(@fsolve,'SpecifyObjectiveGradient',true)
Matt J
Matt J 2019 年 7 月 3 日
That is a documentation error. You should set to true.
farzad
farzad 2019 年 7 月 3 日
that is as you said, the problem is that Matlab does not accept 'on' for Jacobian
farzad
farzad 2019 年 7 月 3 日
Now I did :
options = optimoptions(@fsolve,'Display','iter','MaxFunEvals',1e6,'MaxIter',1e6,'TolFun',1e-3,'DerivativeCheck','on','Diagnostics','on', 'SpecifyObjectiveGradient',true);
but now I get the error :
too many output arguments ! is the definition right ? and how to ask for more output arguments ?
Matt J
Matt J 2019 年 7 月 3 日
編集済み: Matt J 2019 年 7 月 3 日
Without code and the full error message, the problem is undiagnosable. However, I suspect you forgot to provide the Jacobian computation in your objective function code.
Torsten
Torsten 2019 年 7 月 3 日
@farzad:
Did you ask for the number of output arguments in your code ?
https://de.mathworks.com/help/optim/ug/nonlinear-equations-with-jacobian.html
farzad
farzad 2019 年 7 月 3 日
I can't share my full code. I hope this way I resolve it..
I have a bit of diffulty in using your link @Torsten , since I have defined my function in another m file and I call the
[x,fval,exitflag,output] = fsolve(fun,xstart,options);
in my main file. So based on this tutorial you shared, I should add thos Jacobian calc lines in the function definition m file ?
Torsten
Torsten 2019 年 7 月 3 日
編集済み: Torsten 2019 年 7 月 3 日
Of course, where else ?
And with the if statement about the number of output arguments.
farzad
farzad 2019 年 7 月 3 日
I didn't understand your last phrase
Torsten
Torsten 2019 年 7 月 3 日
編集済み: Torsten 2019 年 7 月 3 日
Look at the function file provided in the link:
if nargout > 1
Supply Jacobian
end
farzad
farzad 2019 年 7 月 3 日
And, why can't I just do : jacobian(f,x)
Matt J
Matt J 2019 年 7 月 3 日
編集済み: Matt J 2019 年 7 月 3 日
jacobian(f,x) is a Symbolic Math Toolbox function. It only takes symbolic variables f and x as input and only returns symbolic results. And it is slow.
farzad
farzad 2019 年 7 月 3 日
Thank you, but from the link you shared, I could not learn how to calculate my own function's Jacobian. Where did that 4 coefficient come from in the jacobian when all the main function coeffs are 3.
Matt J
Matt J 2019 年 7 月 3 日
編集済み: Matt J 2019 年 7 月 3 日
From the terms.
farzad
farzad 2019 年 7 月 3 日
Still not clear
I don't understand the C ,D and E matrix size selection , also in c ,d, and e
farzad
farzad 2019 年 7 月 3 日
How about the following ?
[diff(f1,x), diff(f1, y); diff(f2, x), diff(f2, y)]
Matt J
Matt J 2019 年 7 月 3 日
No, diff(f1,x) is also a symbolic function. It is probably better for you to use the fundamental definition of the Jacobian,
to compute the Jacobian for your specific function.
farzad
farzad 2019 年 7 月 3 日
Are you Sure diff is symbolic ?
and why can't I use symbolic ? shall you help me understand ?
Matt J
Matt J 2019 年 7 月 3 日
編集済み: Matt J 2019 年 7 月 4 日
Do you understand the difference between symbolic and numeric computation? In symbolic computation, you present the expression for a function, and the software tries to take its derivatives analytically, as you or I would in a calculus course. The result is an analytical expression for the derivative, not a number.
But fsolve is a numeric solver. It puts in numbers for x and expects your code to give back numbers for the resulting Jacobian(x). On top of that, it does this repeatedly with different x, in its search for a solution. For the sake of speed, therefore, you don't want your code redoing the calculus to get expressions for the Jacobian every time it is called.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2019 年 7 月 3 日

編集済み:

2019 年 7 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by