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,

0 件のコメント
採用された回答
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)
C2 = 3 - (-134680438.5 / 86885000)
C1 - C2
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 Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!