# Interpolation Problem

I have the following list:

AA1 = {{55.3346, 694.253}, {55.3373, 691.275}, {55.34,
688.323}, {55.3426, 685.396}, {55.3453, 682.494}, {55.348,
679.617}, {55.3506, 676.765}, {55.3533, 673.936}, {55.356,
671.131}, {55.3565, 668.277}, {55.3565, 665.428}, {55.3565,
662.604}, {55.3565, 659.803}}


By interpolating the data, I get an error:

AA2 = Interpolation[AA1, InterpolationOrder -> 1]


"Interpolation::inddp: The point 55.3565 in dimension 1 is duplicated. >>"

Therefore, I want to delete the duplicated terms:

DeleteDuplicates[AA1[[All, 1]]]


But how do I merge these values with the correct values of the second part in list AA1 (694.253 until 659.803?

• Based on what criterion do you chose what you call correct values? You can use Mean /@ GatherBy[AA1, First] and you get an average of the points with duplicate values.
– gpap
Aug 21, 2013 at 11:11
• Possible duplicate: (20994) Aug 21, 2013 at 18:34

Update:

Added below as appendix comparing 3 methods to do this: Using MapIndexed as shown by Mr.Wizard here and using GatherBy as suggested by gpap above, and the Union method shown here.

AA1 = Union[AA1, SameTest -> (#1[[1]] == #2[[1]] &)]
Interpolation[AA1, InterpolationOrder -> 1]


(I do not know what you mean by merging afterwords?)

The above will use Union property that no duplicates remain, but only one copy of the duplicates is left. Using DeleteDuplicates will remove all duplicates. So, this way you do not have to put anything back to the list.

Here is an example:

a= {{1, 2}, {1, 4}, {2, 4}}
Union[a, SameTest -> (#1[[1]] == #2[[1]] &)]

(*  {{1, 2}, {2, 4}}  *)


## Appendix

This shows how to use the 3 methods

original = {{55.3346, 694.253}, {55.3373, 691.275}, {55.34,
688.323}, {55.3426, 685.396}, {55.3453, 682.494}, {55.348,
679.617}, {55.3506, 676.765}, {55.3533, 673.936}, {55.356,
671.131}, {55.3565, 668.277}, {55.3565, 665.428}, {55.3565,
662.604}, {55.3565, 659.803}};
originalUnion = Union[original, SameTest -> (#1[[1]] == #2[[1]] &)];
originalGather = Mean /@ GatherBy[original, First];
originalMap = MapIndexed[{#2, #} &, original];

fGather = Interpolation[originalUnion, InterpolationOrder -> 1];
fUnion = Interpolation[originalUnion, InterpolationOrder -> 1];
fMap = Interpolation[originalMap, InterpolationOrder -> 1];


Now there are plotted

opts = {GridLines -> Automatic, GridLinesStyle -> LightGray,
Frame -> True, ImagePadding -> {{30, None}, {30, 30}}};

Grid[{
{

Plot[fUnion[x], {x, First@fUnion[[1, 1]], Last@fUnion[[1, 1]]},Evaluate@opts,
FrameLabel -> {{None, None}, {x, "Union Method"}}],

Plot[fGather[x], {x, First@fGather[[1, 1]], Last@fGather[[1, 1]]}, Evaluate@opts,
FrameLabel -> {{None, None}, {x, "Gather Method"}}],

ParametricPlot[fMap[x], {x, First@fMap[[1, 1]], Last@fMap[[1, 1]]},
AspectRatio -> 1/GoldenRatio, Evaluate@opts,
FrameLabel -> {{None, None}, {x, "Parametric Method"}}]

}}, Frame -> All]
`