Same data - different answers

2 visualizzazioni (ultimi 30 giorni)
Arkadiusz
Arkadiusz il 11 Giu 2025
Commentato: Arkadiusz il 12 Giu 2025
In the first scenario i type the values in by hand and get this outcome:
In the second scenario i type the values in like this:
And my output is then:
I change nothing more, but these two parameters, but the outputs are completely different. Why is that? I'd rather type the values in by hand, but the second output is the one i expect to have

Risposta accettata

Walter Roberson
Walter Roberson il 11 Giu 2025
In the first case, you are typing in 14 significant digits; MATLAB stores at most 15 1/2 significant digits.
In the second case, the gain is displayed rounded to 2 decimal places. We do not know immediately whether it is only stored to two decimal places, or if the display is rounding. The actual numbers might be up to 15 1/2 significant digits.
In the second case, the coefficients are displayed with 5 significant places. We do not know immediately whether it is only stored to 5 decimal places, or if the display is rounding. The gain was displayed to 5 signicant places, so possibly it is a display artificat. The actual numbers might be up to 15 1/2 significant digits.
At the very least, we run into the possibility that the actual coefficients are stored to 15 1/2 significant digits, but that you only typed in 14 significant digits -- which would be consistent with the possibility that you displayed them with "format long g" turned on and typed what you saw there, instead of using fprintf() to get all 15 1/2 digits.
  3 Commenti
Walter Roberson
Walter Roberson il 12 Giu 2025
fprintf('%.1100g\n', kp(7))
will show kp(7) in all of its glory details .
fprintf('%.17g\n', kp(7))
will show kp(7) to enough significant digits to be unique. (There are a few numbers where %.16g would not be unique.)
Arkadiusz
Arkadiusz il 12 Giu 2025
That's cool! I will probably use that in future, thanks again!

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by