Initial Vector in Fsolve

7 visualizzazioni (ultimi 30 giorni)
milad
milad il 25 Lug 2014
Modificato: milad il 27 Lug 2014
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!

Risposte (1)

John D'Errico
John D'Errico il 25 Lug 2014
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 Commenti
John D'Errico
John D'Errico il 26 Lug 2014
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.
milad
milad il 27 Lug 2014
Modificato: milad il 27 Lug 2014
Tank you for your suggestions. I know that every initial vector or point gives a unique answer. But we want to use it to another functions. As I search the book and journals, I found that the answer is dependent on the good Initial vector. I try to find the best one and get the best answer.
Best Regards!

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by