fsolve not working in command window but working in Optimization Tool
Ältere Kommentare anzeigen
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.
Antworten (3)
Alan Weiss
am 28 Mär. 2018
0 Stimmen
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
am 29 Mär. 2018
Bearbeitet: Walter Roberson
am 29 Mär. 2018
1 Kommentar
Alan Weiss
am 29 Mär. 2018
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
Ali Meimandi
am 30 Mär. 2018
0 Stimmen
Kategorien
Mehr zu Systems of Nonlinear Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!