Interp1 wrong answer

조회 수: 13 (최근 30일)
Shahzadeario
Shahzadeario 2016년 3월 4일
답변: Carlos Felipe Rengifo 2018년 7월 7일
Hi I am using MATLAB for long time and recently I face very simple line which I can't understand why MATLAB provide this, maybe it is only in my PC. I want to know if you know the reason or it happens in your version as well. I used Interp1 function with input below:
X = [-6.913 0 6.913];
Y = [-9286 0 9286];
xi = -2.612482811810200e-17;
yi = interp1(X,Y,xi)
If you rund it it will give you: yi = 0 which I think it is wrong.
If I run it for xi = 2.612482811810200e-17 the answer will be 3.5093e-14 which should be the same value with negative sign for initial yi.
Thanks in advance
  댓글 수: 1
Roger Stafford
Roger Stafford 2016년 3월 4일
@Shahzadeario: On my ancient version of matlab I get the opposite to your result. For xi = -2.612482811810200e-17 I get yi = -3.5093e-14 and with xi = 2.612482811810200e-17 I get yi = 0. However, you should not worry about such small errors as these. They are differences in rounding errors in computing the linear interpolation, depending on different ways the code happened to be written for 'interp1'. Double precision floating point numbers have 53 bits in their significands (mantissas) giving accuracy of computation to approximately 16 decimal places, and the above error is well within that range.

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

답변 (1개)

Carlos Felipe Rengifo
Carlos Felipe Rengifo 2018년 7월 7일
Instead of the function interp1, you could use this sentence:
yi = polyval(polyfit(X,Y,1),xi)
In Matlab '9.4.0.885841 (R2018a) Update 3' I obtain:
yi =
3.5093e-14

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by