0
$\begingroup$

I want to find an interpolation function for data in which the x-variable is repeated (example below). The repetition in data is natural and cannot not be eliminated.

Can I somehow use Interpolation or is there any alternative?

tb = {{1, 1.83014}, {2, 8.58075}, {3, 7.51278}, {4, 6.12041}, {5, 
    2.35631}, {6, 9.5376}, {7, 6.58829}, {8, 3.11074}, {9, 
    9.39695}, {10, 8.3102}, {1, 6.51489}, {2, 3.94981}, {3, 
    8.27251}, {4, 7.03619}, {5, 4.06204}, {6, 0.662478}, {7, 
    7.5016}, {8, 7.84269}, {9, 5.64659}, {10, 7.54041}, {1, 
    6.51489}, {2, 3.94981}, {3, 8.27251}, {4, 7.03619}, {5, 
    4.06204}, {6, 0.662478}, {7, 7.5016}, {8, 7.84269}, {9, 
    5.64659}, {10, 7.54041}};

Interpolation[tb, InterpolationOrder -> 1]
(* Interpolation: The point 1 in dimension 1 is duplicated *)
$\endgroup$
1
  • 2
    $\begingroup$ Which value should Interpolation[tb,...][1] return, 1.83014 or 6.51489??? $\endgroup$ Sep 27, 2023 at 10:17

2 Answers 2

2
$\begingroup$

Maybe this helps:

par = Interpolation /@ Partition[tb, 10];

ListLinePlot[par]

enter image description here

par[[1]][1.5]

6.65115

par[[1]][Range @ 9 + 0.5] // ListLinePlot

enter image description here

It should be noted that the middle partition and the last partition are identical:

tb[[11 ;; 20]] == tb[[21 ;; 30]]

True

$\endgroup$
2
$\begingroup$

If it makes sense for your objective to identify the first 10 values as category 0 and the second 10 as category 1, then the following might be considered:

tb = {{1, 1.83014}, {2, 8.58075}, {3, 7.51278}, {4, 6.12041}, {5, 2.35631}, 
      {6, 9.5376}, {7, 6.58829}, {8, 3.11074}, {9, 9.39695}, {10, 8.3102},
      {1, 6.51489}, {2, 3.94981}, {3, 8.27251}, {4, 7.03619}, {5, 4.06204}, 
      {6, 0.662478}, {7, 7.5016}, {8, 7.84269}, {9, 5.64659}, {10, 7.54041}};
data = Flatten[#] & /@ Transpose[{Join[ConstantArray[0, 10], ConstantArray[1, 10]], tb}]

f = Interpolation[data, InterpolationOrder -> 1]

f[1, 1]
(* 6.51489 *)
f[0,10]
(* 8.3102 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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