4

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}

Plot of fx[x]

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
user39464
  • 153
  • 3

5 Answers5

8

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]]

enter image description here

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]]

enter image description here

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]]

enter image description here

Interpolation Reference:

How does Interpolation really work?

Young
  • 7,495
  • 1
  • 20
  • 45
  • What version of Mathematica are you using? I am having trouble duplicating your results in V10.4.1 – m_goldberg Jul 14 '16 at 02:50
  • Same version, Windows-64bit ... Which graph? – Young Jul 14 '16 at 02:51
  • The simple, first one. I'm getting an error message and no evaluation. – m_goldberg Jul 14 '16 at 02: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 02:57
  • 2
    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 03:02
6

Perhaps linear interpolation will suit your needs:

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

Plot[fx2[x], {x, 0.0, 0.9}, Epilog -> Point[tst2]]

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
6

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}]

plot of Steffen interpolant

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
3

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]}]

plot

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
0

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]]

Mathematica graphics

Eric Towers
  • 3,040
  • 12
  • 14