fsolve options generate different results

조회 수: 16 (최근 30일)
Alex Tekin
Alex Tekin 2020년 9월 24일
편집: Michael Croucher 2020년 9월 25일
Dear All,
I attach to this message 3 files, and if I run "Version16" without removing % comments in lines 23 and 24, I get one set of results. Once I remove %, I get different results. Can you please help why so?
Thank you,
Alex.
  댓글 수: 2
Matt J
Matt J 2020년 9월 25일
I see no difference in the results. What Matlab version are you running?
Michael Croucher
Michael Croucher 2020년 9월 25일
편집: Michael Croucher 2020년 9월 25일
Not sure about OP but I'm using 2020b on Windows and I see different results too.

댓글을 달려면 로그인하십시오.

채택된 답변

Michael Croucher
Michael Croucher 2020년 9월 24일
We can learn a little more by asking for more output from fsolve
[x,~,~,output_no_options] = fsolve(fun,x0);
opts = optimoptions('fsolve');
[x,~,~,output_with_options]=fsolve(fun,x0,opts);
My vaue for the options input is slightly different from yours in that it shouldn't change any of the options to fsolve at all. I ask to explicity create the default set of options for fsolve and then I use them. As far as I know, it should be a pointless exercise that changes nothing. However, it changes the results exactly as you describe. Furthermore, I can now see the following
> output_no_options
output_no_options =
struct with fields:
iterations: 105
funcCount: 952
algorithm: 'trust-region-dogleg'
firstorderopt: 6.136896434454735e-07
message: '↵Equation solved.↵↵fsolve completed because the vector of function values is near zero↵as measured by the value of the function tolerance, and↵the problem appears regular as measured by the gradient.↵↵<stopping criteria details>↵↵Equation solved. The sum of squared function values, r = 4.279418e-14, is less than↵sqrt(options.FunctionTolerance) = 1.000000e-03. The relative norm of the gradient of r,↵6.136896e-07, is less than options.OptimalityTolerance = 1.000000e-06.↵↵'
>> output_with_options
output_with_options =
struct with fields:
iterations: 99
funcCount: 901
algorithm: 'trust-region-dogleg'
firstorderopt: 0.086853308408590
message: '↵Solver stopped prematurely.↵↵fsolve stopped because it exceeded the function evaluation limit,↵options.MaxFunctionEvaluations = 9.000000e+02.↵↵'
So, passing in an options structure limits the number of function evaluations to 900 and thus fsolve stops prematurely. This number is mentioned as the default in the documentation. What I don't understand is why this isn't respected in in the call with no options structure.
The practical upshot is that to recover your original result but with your options set the way you want them (You had Display set to off), you need to do
opts = optimoptions('fsolve','Display','off','MaxFunctionEvaluations',2000);
[x,~,~,output_with_options]=fsolve(fun,x0,opts);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by