1
$\begingroup$

How can I calculate in Mathematica the difference on average between the y-axis of two data sets such?:

data1={{0, 38.9583}, {100, 54.9419}, {33, 53.5451}, {10, 43.8448}, {45, 
  57.9104}, {88, 56.0035}, {69, 64.0202}}

data2={{0, 46.3}, {9.7868, 51.646}, {29.8381, 63.8548}, {49.8925, 
  70.7243}, {69.9485, 74.71}, {89.9136, 67.8673}, {100, 58.8}}

Manually I am getting that on average the y axis of data2 is about 8-9 bigger than data1 but I am not sure how to do it properly in Mathematica when the x values do not match exactly

$\endgroup$

1 Answer 1

2
$\begingroup$
data1 = {{0, 38.9583}, {100, 54.9419}, {33, 53.5451}, {10, 
     43.8448}, {45, 57.9104}, {88, 56.0035}, {69, 64.0202}} // Sort;

data2 = {{0, 46.3}, {9.7868, 51.646}, {29.8381, 63.8548}, {49.8925, 
     70.7243}, {69.9485, 74.71}, {89.9136, 67.8673}, {100, 58.8}} // 
   Sort;

EDIT: The value of the average difference will depend on the InterpolationOrder used in the Interpolation

Manipulate[
 Module[{f1, f2},
  f1 = Interpolation[data1, InterpolationOrder -> io];
  f2 = Interpolation[data2, InterpolationOrder -> io];
  avgDiff = (Integrate[f2[x], {x, 0, 100}] - 
      Integrate[f1[x], {x, 0, 100}])/100;
  Plot[{f2[x], f1[x]}, {x, 0, 100},
   Filling -> 1 -> {2},
   PlotLegends -> Placed[{"f2", "f1"}, {.2, .8}],
   Epilog -> {Text[StringForm["avgDiff = ``",
       avgDiff], {70, 45}],
     Red, AbsolutePointSize[4],
     Point[data1], Point[data2]}]],
 {{io, 3, "InterpolationOrder"}, 0, 5, 1,
  Appearance -> "Labeled"}]

enter image description here

$\endgroup$

Your Answer

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

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