Is this a bug? different results when performing simple math operation (A * (B - C)) with scalars or variables

1 回表示 (過去 30 日間)
Hello everybody,
I am performing same operation A * (B - C) two times. First with variables, then with numbers (scalars). I get different results.
I am providing the output from the command window.
Can somebody please help on this issue?
Thank you,

採用された回答

Walter Roberson
Walter Roberson 2022 年 1 月 11 日
If you use
format long g
you will see that ptfDur is not exactly the same as the constant 4.5501 . For example, test
ptfDur - 4.5501
and you will see that the result is non-zero.
Working backwards
C1 = 3 - (-134684353.5829 / 86885000)
C1 =
4.55014506051562
C2 = 3 - (-134680438.5 / 86885000)
C2 =
4.5501
C1 - C2
ans =
4.50605156236961e-05
Your actual value is about 4E-5 larger than was being displayed, because the default format short only displays 4 digits.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by