fsolve and current step
13 views (last 30 days)
Show older comments
hello. i have a problem with fsolve.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fsolve stopped because the relative norm of the current step, 1.117892e-17, is less than
max(options.StepTolerance^2,eps) = 2.220446e-16. However, the sum of squared function
values, r = 7.870134e-09, exceeds sqrt(options.FunctionTolerance) = 1.000000e-25.
Optimization Metric Options
relative norm(step) = 1.12e-17 max(StepTolerance^2,eps) = 2e-16 (selected)
r = 7.87e-09 sqrt(FunctionTolerance) = 1.0e-25 (selected)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
any one can help me???
0 Comments
Answers (1)
Walter Roberson
on 28 Jul 2017
Your function is steeper than can be handled with the fsolve options you are using. fsolve has found two points separated by 1e-17 where there is a zero between the two, but the difference in function values is more than 1e-25.
I would suspect that you passed options to fsolve telling it to use a function tolerance of 1e-50, which is way way too small a tolerance unless you know your function values have absolute magnitude below 1e-35 or so.
2 Comments
Walter Roberson
on 28 Jul 2017
If you use the symbolic toolbox, you can get closed-form solutions. They are approximately
x1 x2
2980663501499.4 -1649993401.34255
693575.067371611 9.69500687359391e-16
-205267520134.293 7.94471142311242e-05
-7794733173260.32 0.0338721889970218
You only used single location initialization (1e6 and 11 respectively) so you could end up getting any of those when you work numerically.
However, the function is so steep that if you take the double-precision approximations from above and substitute them into F, then you will get results that can be quite different from 0:
F1 value F2 value
47612.8298891023 30417.6297938751
2.51664170452454e-20 0.000450530583097153
2.9726319961552e-10 26.1923721370618
-2.38857466441952e-07 120080.281965203
If you take eps() of the closed-form solutions for x1 and x2, you will find that for the 4th of the solutions, the adjacent representable numbers near that x1 are separated by 0.0009765625 . But for some reason you are expecting to be able to have fsolve calculate down to a function precision of 1E-50 .
Your TolFun', 1e-50 and 'TolX' 1e-50 simply cannot be justified numerically. If you need your values to be that precise, you need to switch to the symbolic toolbox.
I would, however, remind you that none of your input coefficients have more than 3 significant digits. For example, what does
ntr=1.23e12;
convey? Does it mean that ntr is to be exactly 1230000000000, or does it mean that the true value of ntr is somewhere between 1225000000000 and 1234999999999.99999999999 ? When you only have 3 significant figures for your coefficients, you are going to get out numeric garbage if you ask for solutions beyond (at best) 4 significant figures.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!