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

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,

 Risposta accettata

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.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Centro assistenza e File Exchange

Prodotti

Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by