MATLAB's fsolve function
20 views (last 30 days)
Show older comments
I'm currently trying to understand MATLAB's fsovle function. I have two simultaneous equations and if I take an initial guess quite close to the solution, the result from fsovle would be correct. If I, however, take an initial guess quite far from the actual solution, MATLAB's fsolve result would yield an incorrect answer.
I'm not entirely sure why MATLAB gives this incorrect answer, as I thought that it would just take MATLAB longer to solve, going through more iterations until it finds a result close to the solution but it doesn't appear to do this. Can anyone explain to me what is going on here or at least some of the possible reasons if it isn't possible to say exactly why?
1 Comment
Walter Roberson
on 14 Feb 2017
I have not seen fsolve give incorrect solutions, except to the extent that sometimes the true root is between two representable numbers so back substituted does not always give 0.
Oh wait, yes, I have seen fsolve give a solution that is not a true root in the case where the function does not cross 0 but comes within round off error of doing so.
More common is that fsolve returns a different (actual) root than expected. The basic newton's algorithm used can end up over projecting to the point where it picks up a root fairly different than the starting point. Oddly enough that happens more when the guess is close to the correct solution but on the steep part of the hump.
Answers (1)
Star Strider
on 14 Feb 2017
Your equations have more than one root or set of roots. The fsolve function finds those closest to your initial parameter estimates.
2 Comments
Star Strider
on 14 Feb 2017
I don’t know what your system consists of. If you have one equation defined on the (x,y) plane and want to find the (x,y) values where the equations evaluate to zero, use the contour function. You can tell it to output the (x,y) coordinates of a specific value. This is the way I always use to find the roots (zeros) of a bivariate funciton.
See the contour documentation for Display Single Contour Line and note the documentation allow you to recover those values:
- [C,h] = contour(...) returns the contour matrix C containing the data that defines the contour lines, and the contour object h.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!