How do I find all the zeros of a function?

39 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 11 月 13 日
コメント済み: Walter Roberson 2022 年 4 月 10 日
The FZERO function only finds a single zero near a specified point. How can I get different zeros over a wider range?

採用された回答

MathWorks Support Team
MathWorks Support Team 2013 年 10 月 18 日
The example below describes one way to find zeros between 0 and 2*pi.
lb = 0;             % Set a lower bound for the function.
ub = 2*pi;          % Set an upper bound for the function.
x = NaN*ones(100,1);             % Initializes x.
starting_points=linspace(0,2*pi,100);
for i=1:100
        % Look for the zeros in the function's current window.
        x(i)=fzero(@(x)sin(10*x), starting_points(i));
end
x_unique=x(diff(x)>1e-12)
%compare to theory values
transpose(((0:19)*pi)/10)-x_unique
Changing the step value of the loop (0.01) to a larger value will result in faster execution, but less accuracy, and vice versa when the specified step value is smaller.
The tolerance for duplicates, in this example 1e-12, should be specified depending on the problem at hand, an inappropriate setting for a certain problem might result in some of the zeros not being found.
Alternately, you can use the SOLVE function from the Symbolic Math Toolbox. 
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 8 月 9 日
Note: solve() from the Symbolic Math Toolbox will only return all zeros for polynomial functions, not for nonlinear functions.
Walter Roberson
Walter Roberson 2022 年 4 月 10 日
Time = 2:.1:4;
Dirac3 = zeros(size(Time));
Dirac3(Time==3) = 1;
stem(Time, Dirac3)

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by