Error while using Polyval

조회 수: 5 (최근 30일)
Dyuman Joshi
Dyuman Joshi 2021년 1월 2일
댓글: Dyuman Joshi 2021년 1월 3일
While solving a problem using polyval, I encountered an error. Here is the screenshot of the code attached (just the part which focuses on the use of polyval)
It seems that polyval isn't accurate when number of digits of the array exceed 15. I am unable to understand what is the cause of this discrepancy.

채택된 답변

Steven Lord
Steven Lord 2021년 1월 2일
편집: Steven Lord 2021년 1월 2일
Not all numbers in the vicinity of large values can be exactly represented in double precision. In particular 12345678901234567 is not exactly representable in double.
v = [1:9 0:7];
format longg
p = polyval(v, 10)
p =
1.23456789012346e+16
s = sym(p)
s = 
12345678901234568
What's the distance between p and the next largest representable number?
eps(p)
ans =
2
If we add something smaller than eps(p) to p it's not enough to get us to the next largest double precision number.
p2 = p + 0.5;
p == p2 % true
ans = logical
1
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2021년 1월 3일
Thank you for your answer, @Steven!
I still have another query - Is there a way to represent such large number in string format rather than just typing them directly?

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by