Extrapolation gives wrong values when using interp1
22 views (last 30 days)
Show older comments
Espen Mikkelsen
on 27 Mar 2018
Commented: John D'Errico
on 11 May 2019
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.
0 Comments
Accepted Answer
Stephen23
on 27 Mar 2018
Edited: Stephen23
on 28 Mar 2018
"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 Comments
Yixuan Ren
on 11 May 2019
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
on 11 May 2019
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)
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!