Does matlab have a function that says "If zero is near?

28 ビュー (過去 30 日間)
Muhendisleksi
Muhendisleksi 2017 年 8 月 12 日
コメント済み: Walter Roberson 2017 年 8 月 12 日
I need a command that checks that the number is near zero.
  1 件のコメント
Jan
Jan 2017 年 8 月 12 日
編集済み: Jan 2017 年 8 月 12 日
Note that "near zero" is not well defined. Is 0.00001 near zeros or only 1e-100?

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

回答 (1 件)

Star Strider
Star Strider 2017 年 8 月 12 日
There is not built-in MATLAB function for that.
It is possible to create one easily enough:
nearZero = @(x,tol) abs(x) < tol; % Test If ‘x’ Is Within ‘tol’ OF Zero
tol = 0.5;
x = rand(1,6) .* (-2:3);
Test = [x; nearZero(x,tol)]
Test =
-0.87571 -0.057386 0 0.090743 1.0487 0.082315
0 1 1 1 0 1
  2 件のコメント
John D'Errico
John D'Errico 2017 年 8 月 12 日
+1. Or you can make it an m-file, if this is something you wish to keep around forever because you use it often. To be honest, I think most of us don't bother, just writing the test like (abs(x)<tol) in our sleep as we need it. That is why there is no function to do this explicitly in MATLAB.
Walter Roberson
Walter Roberson 2017 年 8 月 12 日
ismembertol can also be used for this purpose

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by