How to replace my optimset with equivalent optimoptions ?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Share a link to this question
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
Why not just,
options = optimoptions(@fsolve, 'Display','iter','MaxFunEvals',1e6,'MaxIter',1e6,...
'TolFun',1e-3,'DerivativeCheck','on','Diagnostics','on');
22 Comments
farzad
on 3 Jul 2019
thank you
what about Hessian and Jacob ?
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.
options = optimoptions(@fsolve,'SpecifyObjectiveGradient',true)
Matt J
on 3 Jul 2019
That is a documentation error. You should set to true.
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 ?
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
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 ?
Of course, where else ?
And with the if statement about the number of output arguments.
farzad
on 3 Jul 2019
I didn't understand your last phrase
Look at the function file provided in the link:
if nargout > 1
Supply Jacobian
end
farzad
on 3 Jul 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.
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.
From the
terms.
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
farzad
on 3 Jul 2019
How about the following ?
[diff(f1,x), diff(f1, y); diff(f2, x), diff(f2, y)]
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 ?
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)
Categories
Find more on Calculus in Help Center and File Exchange
See Also
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)