fsolve not working in command window but working in Optimization Tool
显示 更早的评论
Hi I have a system of two nonlinear equations to solve by fsolve. Fsolve is working properly in Optimization Tool as I change the default value of FunctionTolerance, but this is not true if I run the fsolve in command window. As I decrease the tolerance (say from 1E-6 to 1E-10) fsolve could not find the answer.
回答(3 个)
Alan Weiss
2018-3-28
0 个投票
Because the Optimization app internally calls the command-line version of fsolve, there can be no difference between their behavior unless your setup for the command-line version differs from your setup in the app.
In other words, the results are different because the setup is different. Carefully check ALL inputs that you give to fsolve at the command line to ensure that they are what you want.
Alan Weiss
MATLAB mathematical toolbox documentation
Ali Meimandi
2018-3-29
编辑:Walter Roberson
2018-3-29
1 个评论
Alan Weiss
2018-3-29
Ah, I see your situation now. The tolerance that used to be called TolFun has been split in recent software versions to OptimalityTolerance and FunctionTolerance, and these are different. OptimalityTolerance relates to the first-order optimality measure, while FunctionTolerance relates to changes in the objective function value. When these were split, the Optimization app did not get a new tolerance. Instead, its old TolFun was changed to apply to OptimalityTolerance for those situations where it made sense, and to FunctionTolerance otherwise. This was explained in the Release Notes to R2016a, "Option Changes: Distinguish between function tolerance and optimality tolerance, specify Hessians differently, more".
So at the command line, do not set TolFun, but follow the recommendations and use optimoptions as follows:
x0=[10,10];
opts = optimoptions('fsolve','OptimalityTolerance',1e-10);
[xs2,res2,ef2,outp2] = fsolve(@cable,x0,opts)
You will get the answer you want, same as the Optimization app.
Alan Weiss
MATLAB mathematical toolbox documentation
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!