Finding the multiple zeros within a prescribed interval

8 ビュー (過去 30 日間)
Matthew Hunt
Matthew Hunt 2018 年 11 月 13 日
コメント済み: Torsten 2018 年 11 月 14 日
I wish to solve the nonlinar function:
=0
within a prescribed interval, say (0,100] say, I'm aware of using an annonymous function and using fzero or fsolve, but how do I get say multiple solutions?

回答 (1 件)

Torsten
Torsten 2018 年 11 月 13 日
編集済み: Torsten 2018 年 11 月 13 日
deltax = 1e-4;
xright = 100;
n = floor(xright/pi);
fun = @(x)tan(x)-x;
for i=1:n
left = (2*i-1)*pi/2.0 + deltax;
right = (2*i+1)*pi/2.0 - deltax;
sol(i) = fzero(fun,[left right]);
end
sol
fun(sol)
  7 件のコメント
Matt J
Matt J 2018 年 11 月 13 日
編集済み: Matt J 2018 年 11 月 13 日
No, the strategy to find all zeros of a function in a specified interval will always depend on the behaviour of the function itself. So no general guideline can be given.
Imagine, for example, that you were instead trying to find all roots of contained in the interval [0,a]. No matter what you choose, there would always be infinite roots in the interval.
Torsten
Torsten 2018 年 11 月 14 日
@Matthew Hunt:
You know that tan(x) -x -> -Inf for x->2*(k-1)*pi/2 from the right and tan(x) - x -> +Inf for x->2*(k+1)*pi/2 from the left. So there must be a root in the interval 2*(k-1)*pi/2 : 2*(k+1)*pi/2. Plotting the function tan(x) - x you can see that there is exactly one root in this interval. This explains my code and the fact that it captures all roots in a specified interval.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by