fsolve options generate different results
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!