Initial Vector in Fsolve
显示 更早的评论
Hey guys! I have problem with f-solve to solve my equations; When I change my Initial vector(x(0)), f-solve gives me different answers! Although the answers are not too far apart,but I need a Reliable answer; What's the problem? What should I do to have a unique answer?
Thank you!
回答(1 个)
John D'Errico
2014-7-25
0 个投票
The fact is on many such problems there are multiple solutions, all equally good. The only requirement for fsolve is that the function returns zero. So why is one zero better than another? A function with multiple zeros would surely allow different solutions, based on different starting values.
If fsolve has converged to essentially the same solution, but the tolerance is large enough that it is slightly different, what can you expect? If you need a tighter tolerance, then use a tighter tolerance! Again, different starting values mean a different path to the solution, so slightly different results will be achieved.
4 个评论
milad
2014-7-25
John D'Errico
2014-7-25
Sorry, but the fact that you WANT something is not sufficient to ensure it will happen. If it was, there would be many more lottery winners on this earth.
As far as reliability goes, IF the result solves the problem, i.e., it yields all zeros to within a realistic tolerance, it is PERFECTLY acceptable. That you get more than one answer is not unreliable. It is just life, but it does mean that you may need to learn more about how numerical optimizers & root solvers work, about floating point arithmetic, and about numerical methods in general.
Since we have not seen your function, it is impossible to know more. Are there infinitely many solutions? It is trivial to devise a problem that has exactly that. Are there finitely many solutions, scattered around? Again, not at all hard to do. Is the problem a difficult one, in that the solution may be unique, but merely poorly conditioned, so that it is quite difficult to arrive at an exact solution? Again, trivial to devise such a problem.
So don't blame the solver, calling it unreliable, when you don't know yourself what the real issue is. Instead, spend some time understanding your function to know what is happening. Only then can you say a result is "reliable" or not.
John D'Errico
2014-7-26
For example, consider the function x.^2-x. A simple function that has two roots. If I start fsolve (or ANY solver) near the root at 1, it will tell me the root is 1. If I start it near 0, I will get 0 out as the answer.
Both answers are EQUALLY good. There is absolutely NO question of reliability. The answer is completely dependent on my starting value.
Next, consider the function
f = @(x) 1 - 16*x + 120*x^2 - 560*x^3 + 1820*x^4 - ...
4368*x^5 + 8008*x^6 - 11440*x^7 + 12870*x^8 - ...
11440*x^9 + 8008*x^10 - 4368*x^11 + 1820*x^12 - ...
560*x^13 + 120*x^14 - 16*x^15 + x^16
It has one root, and only one root. That root is 1. (All I did was expand the expression (x-1)^16.) However, near zero, if x is any value in the interval [-0.1,0.1], I expect to get floating point garbage.
f(.1)
ans =
0.185302018885184
f(.05)
ans =
0.440126668651766
f(-.01)
ans =
1.1725786449237
f(0.00001)
ans =
0.99984001199944
As you see, I get essentially random numbers out. In fact, I get surprisingly large "random" numbers, even for pretty small inputs. Fsolve will not be able to find the root to within any reasonable tolerance.
Any numerical solver that uses only the values of the above function in floating point arithmetic will be confused. Even roots will perform poorly, although we might hope to do better since it understands that this is a polynomial since we give it the explicit coefficients.
roots([1 -16, 120, -560, 1820, -4368, 8008, -11440, 12870, -11440, 8008, -4368,1820, -560 , 120, -16, 1])
ans =
1.20544696162485 + 0.0404140931296177i
1.20544696162485 - 0.0404140931296177i
1.17516606828456 + 0.120236226496492i
1.17516606828456 - 0.120236226496492i
1.1101519314409 + 0.181057590408548i
1.1101519314409 - 0.181057590408548i
1.02663491346744 + 0.205586117602183i
1.02663491346744 - 0.205586117602183i
0.945660537807805 + 0.193076208309854i
0.945660537807805 - 0.193076208309854i
0.881116914661137 + 0.153005081757738i
0.881116914661137 - 0.153005081757738i
0.838336540547859 + 0.0967263530524888i
0.838336540547859 - 0.0967263530524888i
0.817486132165448 + 0.0329288145084962i
0.817486132165448 - 0.0329288145084962i
Again, numerical garbage, as you should expect.
This is not an issue of the "reliability" of the solver. It is an issue of understanding numerical methods and how they work! (The symbolic toolbox using solve will work nicely though.)
Until you do the work to understand what is happening with your function, ONLY you can determine if the result is "reliable". We have seen NOTHING to tell you more, and trying to do so would be a waste of time until that happens.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!