chop doesn't chop very small numbers

6 vues (au cours des 30 derniers jours)
Alec Poulin
Alec Poulin le 1 Oct 2018
Modifié(e) : Alec Poulin le 2 Oct 2018

I have a small number, say 1e-14, and I want to chop it to three decimals. In this case, it should give 0. Yet:

>> chop(1e-14, 3)
ans =
   1.0000e-14

What is going on?

  3 commentaires
Star Strider
Star Strider le 1 Oct 2018
The only reference I can find on an InterWeb search is the Wolfram function Chop—Wolfram Language Documentation (link).
I cannot find any documentation for a function of that exact name in MATLAB in a similar search.
Alec Poulin
Alec Poulin le 2 Oct 2018
Modifié(e) : Alec Poulin le 2 Oct 2018
That is weird, I cannot remember where I learned about this function. Anyway, on my computer, the file chop.m is located in /usr/local/MATLAB/R2018a/toolbox/control/ctrlobsolete. But then, I just saw that there is the word "obsolete" in the directory name...

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 1 Oct 2018
I believe chop is an old function from Control System Toolbox. I recommend using round instead. The default behavior of round is to round to N decimals but you can also use it to round to N significant digits (which is what chop(X, N) does.)
>> x = 1e-14;
>> round(x, 3)
ans =
0
>> round(x, 3, 'significant')
ans =
1.0000e-14

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by