find roots through iterative method
3 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Matt J
2015-4-5
编辑:Matt J
2015-4-5
You can use FZERO, e.g.,
>> f=@(x) exp(x)-3*x.^2
>> [xroot,res]=fzero(f,.1)
You will need to provide an initial guess of each of the three roots, which you can obtain by plotting the function f(x)=e^x-3*x^2
10 个评论
James Tursa
2015-4-8
编辑:James Tursa
2015-4-8
f = @(x) 3*x.^2-exp(x)
x = -5:.01:5;
plot(x,f(x))
grid on
All three roots are on the plot.
更多回答(1 个)
paula ro
2015-4-8
2 个评论
James Tursa
2015-4-8
Sounds like you are asking quite a lot from this algorithm. Determining good starting guesses for an arbitrary function is not at all trivial. Even determining just how many roots there are is not trivial. You are certainly not going to get some simple code on this forum that does this for you for an arbitrary function. Seems like there is going to have to be some manual work from you up front for doing this for any particular function you are interested in.
Matt J
2015-4-9
编辑:Matt J
2015-4-9
But I need an iteration algorithm that finds these 3 roots without me manually extracting the intervals from the plot.
You've wasted a lot of time by concealing that requirement. I advised you to find the 3 roots in this manual way in my very first response and in several subsequent comments. You didn't even blink.
As James says, though, there is no method for finding all roots of an arbitrary function. One reason that this is impossible is because some functions have infinite roots, arbitrarily close together, even on a finite interval. Examples are f(x)=0 or f(x)=sin(1/x)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
