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.

Answers (3)

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
Thanks Alan for quick reply.
I know your description, but the problem still occurs. I think it is better to describe the matter in detail:
I want to solve the following function:
function F = cable(x)
xA=0;
xB=100;
zA=0;
zB=0;
E=1.5E11;
A0=5e-4;
L0=100.107;
qc=40;
F(1) = -xB+xA+x(1)*L0/(E*A0)+x(1)*(asinh((qc*L0-x(2))/x(1))-asinh(-1*x(2)/x(1)))/qc;
F(2) = -zB+zA+L0*(qc*L0/2-x(2))/(E*A0)+((x(1)^2+(qc*L0-x(2))^2)^0.5-(x(1)^2+x(2)^2)^0.5)/qc;
end
and the initial guess is x0=[10,10]
in the optimization app if the FunctionTolerance be 1E-6 (the default value) the fsolve will result following answers:
20837.163672394345 2002.1056198294377
and if I change it to 1E-10 these are the results:
22095.196553832655 2002.1400000000078
which is the satisfactory answers for me.
But if I try this in command prompt I could get the same result for 1E-6 for the FunctionTolerance but if I change it to 1E-10 fsolve will not work and I will get the previous again.
I checked the value of FunctionTolerance in options and the value is correct as 1E-10, but fsolve return "No Solution Found".

1 Comment

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

Sign in to comment.

Thanks Alan for your nice attention.
Hopefully it works now.

Categories

Asked:

on 28 Mar 2018

Answered:

on 30 Mar 2018

Community Treasure Hunt

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

Start Hunting!