# Find the difference between two empirical curves

there are 2 list of data . i need to compare both in an uniqe curve and calculate the difference between them numerically and by curves to approach something like this:model=data2-data1

for this purpose i'm tried import both data list in mathematica then create the model such as :

my code:

'data1 = Import[
"C:\\Users\\Farkhondeh\\Desktop\\data\\txt data - \
data2 = Import[
"C:\\Users\\Farkhondeh\\Desktop\\data\\txt data - \
model = data2 - data1
ListPlot[{data1, data2, model}, Joined -> True]'


but it is not enough to find the difference... a sample of my data is:data1={{400.47, 0.}, {400.84, 0.}, {401.21, 0.}, {401.58, 0.}, {401.95, 0.}, {402.32, 0.}, {402.69, 0.}, {403.06, 0.}, {403.43, 0.}, {403.8, 0.}, {404.17, 0.}, {404.54, 0.}, {404.91, 0.}, {405.28, 0.}, {405.65, 0.}, {406.02, 0.}, {406.39, 0.}, {406.76, 0.}, {407.13, 0.}, {407.5, 0.}, {407.87, 0.}, {408.24, 0.}, {408.61, 0.}, {408.98, 0.}, {409.35, 0.}, {409.72, 0.}, {410.08, 0.}, {410.45, 0.}, {410.82, 0.}, {411.19, 0.}, {411.56, 0.}, {411.93, 0.}, {412.3, 0.}, {412.67, 0.}, {413.04, 0.}, {413.41, 0.}, {413.77, 0.}, {414.14, 0.}, {414.51, 0.}, {414.88, 0.}, {415.25, 2.345}, {415.62, 1.655}, {415.99, 1.46}, {416.36, 1.251}, {416.72, 1.208}, {417.09, 1.152}, {417.46, 1.097}, {417.83, 1.052}, {418.2, 1.031}, {418.57, 1.034}, {418.93, 1.008}, {419.3, 0.995}, {419.67, 0.967}, {420.04, 0.941}, {420.41, 0.922}, {420.78, 0.9}, {421.14, 0.886}, {421.51, 0.874}, {421.88, 0.848}, {422.25, 0.831}, {422.62, 0.819}, {422.98, 0.808}, {423.35, 0.795}, {423.72, 0.789}, {424.09, 0.779}, {424.45, 0.777}, {424.82, 0.77}, {425.19, 0.762}, {425.56, 0.757}, {425.92, 0.755}, {426.29, 0.749}, {426.66, 0.74}, {427.03, 0.731}, {427.39, 0.723}, {427.76, 0.719}, {428.13, 0.712}, {428.5, 0.706}, {428.86, 0.7}, {429.23, 0.696}, {429.6, 0.691}, {429.97, 0.686}, {430.33, 0.684}, {430.7, 0.68}, {431.07, 0.677}, {431.43, 0.675}, {431.8, 0.671}, {432.17, 0.668}, {432.53, 0.665}, {432.9, 0.664}, {433.27, 0.66}, {433.64, 0.656}, {434., 0.654}, {434.37, 0.65}, {434.74, 0.647}, {435.1, 0.644}, {435.47, 0.641}, {435.84, 0.638}, {436.2, 0.635}, {436.57, 0.631}, {436.93, 0.627}, {437.3, 0.623}, {437.67, 0.621}, {438.03, 0.618}, {438.4, 0.614}, {438.77, 0.609}, {439.13, 0.606}, {439.5, 0.603}, {439.86, 0.6}, {440.23, 0.597}, {440.6, 0.593}, {440.96, 0.591}, {441.33, 0.589}, {441.69, 0.586}, {442.06, 0.583}, {442.43, 0.58}, {442.79, 0.578}, {443.16, 0.576}, {443.52, 0.574}, {443.89, 0.571}, {444.26, 0.569}, {444.62, 0.567}, {444.99, 0.565}, {445.35, 0.562}, {445.72, 0.56}, {446.08, 0.558}, {446.45, 0.556}, {446.81, 0.553}, {447.18, 0.55}, {447.54, 0.548}, {447.91, 0.546}, {448.28, 0.543}, {448.64, 0.541}, {449.01, 0.538}, {449.37, 0.536}, {449.74, 0.534}, {450.1, 0.532}, {450.47, 0.529}} and data2={{400.84, 0.}, {401.21, 0.}, {401.58, 0.}, {401.95, 0.}, {402.32, 0.}, {402.69, 0.}, {403.06, 0.}, {403.43, 0.}, {403.8, 0.}, {404.17, 0.}, {404.54, 0.}, {404.91, 0.}, {405.28, 0.}, {405.65, 0.}, {406.02, 0.}, {406.39, 0.}, {406.76, 0.}, {407.13, 0.}, {407.5, 0.}, {407.87, 0.}, {408.24, 0.}, {408.61, 0.}, {408.98, 0.}, {409.35, 0.}, {409.72, 0.}, {410.08, 0.}, {410.45, 0.}, {410.82, 0.}, {411.19, 0.}, {411.56, 0.}, {411.93, 0.}, {412.3, 0.}, {412.67, 0.}, {413.04, 0.}, {413.41, 0.}, {413.77, 0.}, {414.14, 1.957}, {414.51, 1.46}, {414.88, 1.34}, {415.25, 1.208}, {415.62, 1.107}, {415.99, 1.071}, {416.36, 0.982}, {416.72, 0.97}, {417.09, 0.959}, {417.46, 0.918}, {417.83, 0.887}, {418.2, 0.897}, {418.57, 0.893}, {418.93, 0.88}, {419.3, 0.865}, {419.67, 0.851}, {420.04, 0.823}, {420.41, 0.812}, {420.78, 0.787}, {421.14, 0.776}, {421.51, 0.766}, {421.88, 0.768}, {422.25, 0.754}, {422.62, 0.753}, {422.98, 0.745}, {423.35, 0.738}, {423.72, 0.735}, {424.09, 0.73}, {424.45, 0.73}, {424.82, 0.733}, {425.19, 0.732}, {425.56, 0.727}, {425.92, 0.721}, {426.29, 0.716}, {426.66, 0.707}, {427.03, 0.702}, {427.39, 0.701}, {427.76, 0.697}, {428.13, 0.693}, {428.5, 0.689}, {428.86, 0.685}, {429.23, 0.682}, {429.6, 0.681}, {429.97, 0.675}, {430.33, 0.674}, {430.7, 0.671}, {431.07, 0.668}, {431.43, 0.664}, {431.8, 0.662}, {432.17, 0.661}, {432.53, 0.657}, {432.9, 0.655}, {433.27, 0.653}, {433.64, 0.65}, {434., 0.648}, {434.37, 0.645}, {434.74, 0.645}, {435.1, 0.643}, {435.47, 0.641}, {435.84, 0.637}, {436.2, 0.634}, {436.57, 0.632}, {436.93, 0.63}, {437.3, 0.626}, {437.67, 0.623}, {438.03, 0.621}, {438.4, 0.618}, {438.77, 0.614}, {439.13, 0.611}, {439.5, 0.609}, {439.86, 0.606}, {440.23, 0.604}, {440.6, 0.602}, {440.96, 0.6}, {441.33, 0.598}, {441.69, 0.595}, {442.06, 0.593}, {442.43, 0.591}, {442.79, 0.589}, {443.16, 0.588}, {443.52, 0.586}, {443.89, 0.584}, {444.26, 0.582}, {444.62, 0.58}, {444.99, 0.578}, {445.35, 0.575}, {445.72, 0.574}, {446.08, 0.572}, {446.45, 0.57}, {446.81, 0.568}, {447.18, 0.566}, {447.54, 0.563}, {447.91, 0.562}, {448.28, 0.56}, {448.64, 0.558}, {449.01, 0.556}, {449.37, 0.554}, {449.74, 0.552}, {450.1, 0.551}, {450.47, 0.549}, {450.83, 0.547}} 

• What is the data? Or at least give us a small sample of how it's formatted. It doesn't look live you've put a tremendous amount of thought and effort into this, have you tried anything else?
– ktm
Jan 13, 2017 at 1:39
• f1 = Interpolation[data1]; f2 = Interpolation[data2]; Δf[x_] := f1[x] - f2[x]; Plot[{f1[x], f2[x], Δf[x]}, ... , PlotLegends -> "Expressions"] Jan 13, 2017 at 2:21

Use Interpolation to obtain your functions:

    f1 = Interpolation[data1];
f2 = Interpolation[data2];
Plot[{f1[x], f2[x], f1[x] - f2[x]},
{x, 415, 450},
Filling -> {{1 -> {2}}, 3 -> Axis},
PlotLegends -> "Expressions" ]


NIntegrate[f1[x] - f2[x], {x, 415, 450}]


(* 1.70542 *)

I truncated your data to be greater than 415, since it was noisy and essentially zero for values lower than that.

truncateddata1 = Select[data1, #[[1]] > 415 &]


If you need an algebraic expression for your data, you much choose a model. Here's a simple third-order model:

FindFit[truncateddata1, a + b x + c x^2 + d x^3 , {a, b, c, d}, x]


(* {a -> 7769.13, b -> -53.3395, c -> 0.122071, d -> -0.0000931173} *)

• yes, exactly i need find a proper fit for the difference Jan 13, 2017 at 3:31
• and the noise related to my experimen in labratory Jan 13, 2017 at 3:33