# Interpolation gone awry?

Here's a simple example of an interpolation function that seems to me to have gone awry. Maybe someone would be so kind as to tell my what's going on with this?

tst2 = {{0, 0}, {0.0057269, 0.2}, {0.0366617, 0.4}, {0.158682,
0.6}, {0.50688, 0.8}, {0.938627, 1.}};

MatrixForm[tst2]
fx = Interpolation[tst2];
Plot[fx[x], {x, 0.0, 0.9}]


\begin{array}{cc} 0 & 0 \\ 0.0057269 & 0.2 \\ 0.0366617 & 0.4 \\ 0.158682 & 0.6 \\ 0.50688 & 0.8 \\ 0.938627 & 1. \\ \end{array} • All: I know there is a Q&A that already describes the algorithm used by Interpolation that I believe would explain this apparently strange behavior, but I cannot find it. Does anyone recall? – Mr.Wizard Jul 14 '16 at 2:18
• – Young Jul 14 '16 at 2:21
• @Young Thanks! I also found this possible duplicate: (104037) – Mr.Wizard Jul 14 '16 at 2:35
• The data doesn't behave much like a polynomial. Perhaps a power law fit will do? Behavior is close to x^.3 – m_goldberg Jul 14 '16 at 3:28
• The suggested vertical asymptote at zero indicates working with the inverse function may be better behaved. – Eric Towers Jul 14 '16 at 15:24

It seems that any InterpolationOrder greater than 1 using the default method (Hermite) yields an unsatisfactory curve.

Maybe a simple regression fit would suit your purposes:

tst2 = {{0.0057269, 0.2},{0.0366617, 0.4},{0.158682, 0.6},{0.50688, 0.8}, {0.938627, 1.}};
model = a x^b;
nlm = NonlinearModelFit[tst2, model, {a, b}, x];
Plot[nlm[x], {x, 0.00, 1}, Epilog -> Point[tst2]] or a more complicated fit:

tst2 = {{0, 0}, {0.0057269, 0.2}, {0.0366617, 0.4},
{0.158682, 0.6}, {0.50688, 0.8}, {0.938627, 1.}};
model = a x^(3/2) - b x + c x^(1/2) + d;
nlm = NonlinearModelFit[tst2, model, {a, b, c, d}, x];
Plot[nlm[x], {x, 0.00, 1}, Epilog -> Point[tst2]] Example of Method "Spline" at the same order as the default.

fx = Interpolation[tst2, Method -> "Spline", InterpolationOrder -> 3];
Plot[fx[x], {x, 0.0, 1.0}, Epilog -> Point[tst2]] Interpolation Reference:

How does Interpolation really work?

• What version of Mathematica are you using? I am having trouble duplicating your results in V10.4.1 – m_goldberg Jul 14 '16 at 2:50
• Same version, Windows-64bit ... Which graph? – Young Jul 14 '16 at 2:51
• The simple, first one. I'm getting an error message and no evaluation. – m_goldberg Jul 14 '16 at 2:55
• As shown in the answer, I deleted point {0,0} for the simple fit ... {0,0} isn't used in the data set for the last graph either. – Young Jul 14 '16 at 2:57
• Ah, so. I failed to notice that. Interestingly, NonlinearModelFit[tst2, {a x^b, 0 < b <= .5}, {a, b}, x, Method -> "NMinimize"] works with the original data and gives the same fit as yours. – m_goldberg Jul 14 '16 at 3:02

Perhaps linear interpolation will suit your needs:

fx2 = Interpolation[tst2, InterpolationOrder -> 1];

Plot[fx2[x], {x, 0.0, 0.9}, Epilog -> Point[tst2]] Using the Steffen monotonic interpolation routine from this answer:

tst2 = {{0, 0}, {0.0057269, 0.2}, {0.0366617, 0.4}, {0.158682, 0.6},
{0.50688, 0.8}, {0.938627, 1.}};
fx = SteffenInterpolation[tst2];

Plot[fx[x], {x, 0.0, 0.9}] • (N.B. Fritsch-Carlson will also work here.) – J. M. will be back soon Jul 14 '16 at 2:52
• It's nice to know there even exist such types of interpolation. – Ruslan May 23 '17 at 19:02

This makes a good fit and includes the point at zero.

data =
{{0, 0}, {0.0057269, 0.2}, {0.0366617, 0.4}, {0.158682, 0.6}, {0.50688, 0.8},
{0.938627, 1.}};
Clear[fx]
fx =
NonlinearModelFit[data, {a x^b, 0 < b <= .5}, {a, b}, x,
Method -> "NMinimize"]["Function"]


1.0077 #1^0.293795 &

Plot[fx[x], {x, 0., 1.},
Epilog -> {PointSize[Scaled[.01]], Point[data]}] • Now that I think about it, OP could probably clarify if what he wants is a fit or an interpolant, as those do different things. – J. M. will be back soon Jul 14 '16 at 3:15
• @J.M. Good point, but there a 3rd position on the matter: doesn't care which. Perhaps you make a query to the OP on this as a comment to the question. – m_goldberg Jul 14 '16 at 3:23

Following up on my comment about inverse functions, a simple implementation ...

tst2 = {{0, 0}, {0.0057269, 0.2}, {0.0366617, 0.4}, {0.158682, 0.6}, {0.50688, 0.8}, {0.938627, 1.}};
ifx = Interpolation[Reverse /@ tst2];
fx = InverseFunction[FunctionInterpolation[ifx[y], {y, 0, 1}]];
Plot[fx[x], {x, 0, 1}, Epilog -> Point[tst2]]
{"ft_lang_label":"__label__en","ft_lang_prob":0.8407476,"math_prob":0.9830179,"size":682,"snap":"2019-51-2020-05","text_gpt3_token_len":276,"char_repetition_ratio":0.107669614,"word_repetition_ratio":0.0,"special_character_ratio":0.51466274,"punctuation_ratio":0.26857144,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9890382,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"im_url_duplicate_count":[null,9,null,5,null,5,null,5,null,5,null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-15T07:36:03Z\",\"WARC-Record-ID\":\"<urn:uuid:7eb27fb2-a869-46a4-a991-f6a012ba3fc5>\",\"Content-Length\":\"176225\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:72b301ff-1e9c-42b3-a784-480cb8df0e02>\",\"WARC-Concurrent-To\":\"<urn:uuid:b3851e4a-f6b2-4ad2-90e3-74e9ad2ff638>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/questions/120665/interpolation-gone-awry/120667\",\"WARC-Payload-Digest\":\"sha1:INW2SGBOJYXTIOVVVJ7FT2QZXC5HDCMU\",\"WARC-Block-Digest\":\"sha1:RPFQZMTCUHNRCZOV4EYSRA6QB53PCQIR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575541307797.77_warc_CC-MAIN-20191215070636-20191215094636-00001.warc.gz\"}"}