# AUC between different size curves

3 views (last 30 days)
Suzuki on 7 Sep 2021
Edited: Suzuki on 11 Sep 2021
How can I calculate the area between 2 curves of unequal data size, as in the photo? Julius Muschaweck on 7 Sep 2021
I would use interp1 to interpolate both functions so they have the same high resolution x support. You can easily replace the 0.01 step by a 1e-6 step size in the code below.
Look for interp1 options, to control the interpolation algorithm (you might prefer 'linear' to avoid overshoots), and to control extrapolation (in your probability distribution case, you might want to set the value for extrapolation to 1 if one of your distributions has shorter x range).
Then use trapz to compute the signed integral of the difference or unsigned area between the curves. See code.
x1 = 0:0.2:1.4;
y1 = x1.^2;
x2 = 0:0.14:1.4;
y2 = sqrt(x2);
figure();
hold on;
plot(x1,y1,'-x');
plot(x2,y2,'-x'); xq = 0:0.01:1.4;
y1q = interp1(x1,y1,xq);
y2q = interp1(x2,y2,xq);
my_signed_integral = trapz(xq,y2q-y1q)
my_signed_integral = 0.1701
my_unsigned_area = trapz(xq,abs(y2q-y1q))
my_unsigned_area = 0.4631
test_signed = trapz(xq,sqrt(xq) - xq.^2)
test_signed = 0.1894
test_unsigned= trapz(xq,abs(sqrt(xq) - xq.^2))
test_unsigned = 0.4768
Suzuki on 11 Sep 2021
Edited: Suzuki on 11 Sep 2021
thank you very much for the kind and detailed explanation.
@Julius Muschaweck I really appreciate your help, I would have not done it without your generous help.