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

 Réponse acceptée

Matt J
Matt J le 3 Juil 2019
Modifié(e) : Matt J le 3 Juil 2019
Why not just,
options = optimoptions(@fsolve, 'Display','iter','MaxFunEvals',1e6,'MaxIter',1e6,...
'TolFun',1e-3,'DerivativeCheck','on','Diagnostics','on');

22 commentaires

thank you
what about Hessian and Jacob ?
For the Jacobian, set 'SpecifyObjectiveGradient' to true, and follow instructions and examples here,
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 le 3 Juil 2019
Modifié(e) : Torsten le 3 Juil 2019
options = optimoptions(@fsolve,'SpecifyObjectiveGradient',true)
That is a documentation error. You should set to true.
that is as you said, the problem is that Matlab does not accept 'on' for Jacobian
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 le 3 Juil 2019
Modifié(e) : Matt J le 3 Juil 2019
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.
@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
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 le 3 Juil 2019
Modifié(e) : Torsten le 3 Juil 2019
Of course, where else ?
And with the if statement about the number of output arguments.
I didn't understand your last phrase
Torsten
Torsten le 3 Juil 2019
Modifié(e) : Torsten le 3 Juil 2019
Look at the function file provided in the link:
if nargout > 1
Supply Jacobian
end
And, why can't I just do : jacobian(f,x)
Matt J
Matt J le 3 Juil 2019
Modifié(e) : Matt J le 3 Juil 2019
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.
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 le 3 Juil 2019
Modifié(e) : Matt J le 3 Juil 2019
From the terms.
Still not clear
I don't understand the C ,D and E matrix size selection , also in c ,d, and e
How about the following ?
[diff(f1,x), diff(f1, y); diff(f2, x), diff(f2, y)]
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.
Are you Sure diff is symbolic ?
and why can't I use symbolic ? shall you help me understand ?
Matt J
Matt J le 3 Juil 2019
Modifié(e) : Matt J le 4 Juil 2019
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by