Same data - different answers

조회 수: 2 (최근 30일)
Arkadiusz
Arkadiusz 2025년 6월 11일
댓글: Arkadiusz 2025년 6월 12일
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

채택된 답변

Walter Roberson
Walter Roberson 2025년 6월 11일
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
Walter Roberson
Walter Roberson 2025년 6월 12일
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 2025년 6월 12일
That's cool! I will probably use that in future, thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by