fzero function calculating all zeros within interval

56 ビュー (過去 30 日間)
Rick
Rick 2014 年 7 月 28 日
編集済み: mostafa 2019 年 8 月 17 日
Hello,
I was thinking about the function fzero. If you have a function that has multiple roots within an interval of your choice, is there a way to show all the roots as an array, instead of only one root closest to the guess?

採用された回答

Star Strider
Star Strider 2014 年 7 月 28 日
You can first get an estimate of the zeros (if any) in your interval-of-interest by calculating it in that interval, then multiplying the function by circshift of the function to detect any zero-crossings that might be present. After that, use those estimates as your initial guesses for fzero
To illustrate:
x = linspace(0,50,200);
y = @(x) sin(x);
zx = x(y(x).*circshift(y(x),[0 -1]) <= 0); % Estimate zero crossings
zx = zx(1:end-1); % Eliminate any due to ‘wrap-around’ effect
for k1 = 1:length(zx)
fz(k1) = fzero(y, zx(k1));
end
  1 件のコメント
mostafa
mostafa 2019 年 8 月 17 日
編集済み: mostafa 2019 年 8 月 17 日
It should be corrected to this.
x = linspace(0,50,200);
y = @(x) sin(x);
zx = y(x).*circshift(y(x),[-1]) <= 0; % Estimate zero crossings
zx = zx(1:end-1); % Eliminate any due to ‘wrap-around’ effect
zx = x(zx);
for k1 = 1:length(zx)
fz(k1) = fzero(y, zx(k1));
end
fz

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

その他の回答 (2 件)

Ben11
Ben11 2014 年 7 月 28 日
If you have the Curve Fitting Toolbox you might want to use
fnzeros

Matt J
Matt J 2014 年 7 月 28 日
編集済み: Matt J 2018 年 10 月 31 日
Not for general functions. Certain functions, for example, have infinite roots in a finite interval, e.g., f(x)=0 or f(x)=sin(1/x). So of course the routine won't find all of them for you.
You can't reliably find multiple roots without exploiting some specific apriori known thing about the structure of the function, e.g., that it's a polynomial.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by