Extrapolation gives wrong values when using interp1

조회 수: 17 (최근 30일)
Espen Mikkelsen
Espen Mikkelsen 2018년 3월 27일
댓글: John D'Errico 2019년 5월 11일
I have two different arrays and want to do interpolation and extrapolation.
X-value = [0 386.5 446.1 526.6 621.5 660.6 711.4 734.9 792.8 810.2 817.9 893.7 1136.8 1317 1420.2 1426.2]
Y-value = [1.225 1.216 1.203 1.194 1.182 1.178 1.171 1.169 1.161 1.160 1.160 1.151 1.122 1.101 1.091 1.091]
The y-value have a linear decrease with larger x-values. I want to do interpolation and extrapolation so I can find the y-value of any x-values. I have tried this code when I want to find the y-value when x- value is f.eks 2000:
interp1(Height,Density,2000,'linear','extrap');
When I try to extrapolation for x-values higher than the largest x-value value which is 1426.2, the y-value is not decreasing. Instead y-value stays nearly flat and even slightly increasing when x-value is increasing. The original curve is clearly decreasing linearly. I have no idea whats the problem. Hope someone can help.

채택된 답변

Stephen23
Stephen23 2018년 3월 27일
편집: Stephen23 2018년 3월 28일
"Extrapolation gives wrong values when using interp1"
interp1 is giving the right value.
The problem is simple: the last two points have the same Y value, so any linear extrapolation will simply continue with that value. Linear interpolation/extrapolation of a new point takes into account (at most) only two data points, which means that the overall downward trend of your data is irrelevant, because the last two points are these:
X = [... 1420.2 1426.2];
Y = [... 1.091 1.091];
So all larger X values will simply return Y = 1.091, no matter how large you make X.
To resolve this you might want to add some smoothing, or do some subsampling, or fit a line (e.g. using least squares), or merge points that are close together, or ... whatever makes sense for your data.
  댓글 수: 12
Yixuan Ren
Yixuan Ren 2019년 5월 11일
Yes finally I solve it with polyfit. Actually this is an even more straightforward idea, but the assignment misleads me by saying "extrapolate" so I directly rushed into interp1 at the beginning.
Thank you so much for the detailed explanations. (Btw it‘s my first time saysing something in this forum and the speed of responses here shocks me. Thank you again guys. XD)
John D'Errico
John D'Errico 2019년 5월 11일
Polyfit is generally a good choice, as long as you do not use too high an order model for the fit.
Remember that if extrapolation was an easy thing to do, we would be able to predict the weather out years in advance. At best, you can say about the next summer is that it will be sunny some days, rainy on other days.
I'll add what is my favorite quote about mathematics:
"In the space of one hundred and seventy six years the Lower Mississippi has shortened itself two hundred and forty-two miles. That is an average of a trifle over a mile and a third per year. Therefore, any calm person, who is not blind or idiotic, can see that in the Old Oölitic Silurian Period, just a million years ago next November, the Lower Mississippi was upwards of one million three hundred thousand miles long, and stuck out over the Gulf of Mexico like a fishing-pole. And by the same token any person can see that seven hundred and forty-two years from now the Lower Mississippi will be only a mile and three-quarters long, and Cairo [Illinois] and New Orleans will have joined their streets together and be plodding comfortably along under a single mayor and a mutual board of aldermen. There is something fascinating about science. One gets such wholesale returns of conjecture out of such a trifling investment of fact."
(Mark Tain, Life on the Mississippi)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by