find the least positive root of the equation y=cos(sqrt(abs(polyval(p,x))))-sin(x)/2 with the use of fzero
Show older comments
what function should i create and what i should do after
Accepted Answer
More Answers (1)
Walter Roberson
on 9 Jan 2016
0 votes
A difficulty with the linspace approach is that when you ask fzero for a root and supply an initial positive guess, there is no guarantee that the resulting root will be positive even if there are positive roots. For any fixed spacing like linspace(0,5,100) you can come up with a function which will project all of those values to negative roots even though positive roots exist.
It is tempting to use fzero with an interval of eps(realmin) to realmax. The difficulty with that is that fzero requires that the endpoints have opposite signs, which we can certainly not guarantee in general.
You can fzero adjacent intervals over a range hoping for some root, if you check the exitflag. But if the function is sufficiently wiggly then you might still run into the sign-change problem.
Some other methods of finding roots:
Categories
Find more on Optimization 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!