You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to replace my optimset with equivalent optimoptions ?
4 views (last 30 days)
Show older comments
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
Accepted Answer
Matt J
on 3 Jul 2019
Edited: Matt J
on 3 Jul 2019
Why not just,
options = optimoptions(@fsolve, 'Display','iter','MaxFunEvals',1e6,'MaxIter',1e6,...
'TolFun',1e-3,'DerivativeCheck','on','Diagnostics','on');
22 Comments
Matt J
on 3 Jul 2019
For the Jacobian, set 'SpecifyObjectiveGradient' to true, and follow instructions and examples here,
farzad
on 3 Jul 2019
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.
farzad
on 3 Jul 2019
that is as you said, the problem is that Matlab does not accept 'on' for Jacobian
farzad
on 3 Jul 2019
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 ?
Torsten
on 3 Jul 2019
@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
on 3 Jul 2019
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 ?
farzad
on 3 Jul 2019
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.
farzad
on 3 Jul 2019
Still not clear
I don't understand the C ,D and E matrix size selection , also in c ,d, and e
Matt J
on 3 Jul 2019
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
on 3 Jul 2019
Are you Sure diff is symbolic ?
and why can't I use symbolic ? shall you help me understand ?
Matt J
on 3 Jul 2019
Edited: Matt J
on 4 Jul 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.
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)