Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am getting strange behavior when I try to calculate the inverse of an interpolating function for two similar data sets.

My data sets are:

Array1 = {25, 425, 825, 1175, 1575, 1975, 2025, 2625, 3225, 3775, 4375, 4975, 5250, 9250, 
          13250, 16750, 20750, 24750, 27500, 47500, 67500, 82500, 102500}

Array2 = {13, 88, 188, 263, 338, 413, 513, 588, 613, 688, 788, 863, 938, 1013, 1113, 1188, 
         1250, 1950, 2650, 3350, 4050, 4750, 5450, 6150, 6700, 13700, 20700, 27700, 34700, 41700, 
         48700, 55700}

Let's define:

int1 = Interpolation[Array1];
int2 = Interpolation[Array2];

inv1 = InverseFunction[int1];
inv2 = InverseFunction[int2];

Now if these are behaving, then taking the inverse of the interpolating function's value for X should return X. Here's what happens when we try that for, say, 5:

N[inv1[int1[5]]]

Out: 5.

N[inv2[int2[5]]

Out: -1.73315

Err...this makes no sense. Is there any reason that the inverse of an interpolating function would behave as expected with one data set but not another? These data sets aren't very different so it isn't clear to me what about the second set could be causing the routine heartburn.

share|improve this question
    
Quick update on this: apparently, it is the second value in Array2 that offends Mathematica's delicate sensibilities. If I change it from 88 to 89, still get gobbledygook. If I change it to 90 or greater, then inv2[int2[x]] = x, as expected. (If I keep it below 89, it stays weird). –  Jeff Jun 13 '13 at 18:22
    
I cannot reproduce this. Can you try a fresh session and see if it persists? What version are you in? Also, I (simultaneously with @belisarius it seems) had to edit your post so that the code is indented. See mathematica.stackexchange.com/editing-help for some help with this in the future. –  gpap Jun 13 '13 at 18:32
    
Try N[inv2[int2[5.]]] and let us know the result –  belisarius Jun 13 '13 at 18:36
2  
I think - as a general rule - it is safer to invert the dataset and THEN interpolate it. Here inv2 = Interpolation[ Reverse /@ Range[Length@Array2]~Riffle~Array2~Partition~2]; gives the desired inv2[int2[5.]] (*OUT: 5.*) and is designed to be better behaved. –  gpap Jun 13 '13 at 21:38
1  
@belisarius :) ok, then a fun-preserving compromise; setting InterpolationOrder->1 fixes the above issue –  gpap Jun 14 '13 at 8:20
show 7 more comments

1 Answer

I think this is an issue of the interpolation order being too high and the resulting function not being 1 - 1. A way is to set the InterpolationOrder to 1 or (safer) to create the inverse function by inverting the data and then interpolating:

inv2 = Interpolation[Reverse /@ Range[Length@Array2]~Riffle~Array2~Partition~2];

so that

inv2[int2[5.]]

5.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.