Does fzero returns the first zero in an intervall with multiple zeros?
Show older comments
Background: In my code I calculate in each loop some function f(x). I don't know exactly how it looks. But I have an interval [a,b] in which I look for zeros. There may be none, one, or more then one.
Question: I am concerned about the case with more then one zero. How does fzero work exactly? The output of fzero is one zero, but which one if there are multiple? What does it depend on? I need to get the first zero in the interval (the zero with the smallest value x, with a < x < b).
My experience was so far, that it will give me the first zero, but can I rely on the code providing me the first zero or do I have to find an own routine to check for that?
Answers (1)
John D'Errico
on 5 Oct 2017
0 votes
No. Fzero does NOT return the FIRST zero. How would it be able to do that, unless it also knew all of the zeros?
Fzero is a numerical solver. You might want to read about basic rootfinding algorithms in 1-dimension. Start with methods like bisection, the secant method, etc. Fzero is just an extension of such methods, although a little more sophisticated.
Fzero finds SOME root. There is no assurance of which root it will find. And if there are two roots in a bracket, or any even number of roots, then it will find no root at all, since there there is no zero crossing that it will see.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!