Message-ID: <4D3EC2DD.2040407@unige.ch>
Date: 2011-01-25T12:32:29Z
From: Xavier Robin
Subject: Integration of two lines
Hello,
I need to integrate the absolute difference between two lines measured
on different points.
# For example :
x <- seq(0, 1, 1/100)
f_x <- runif(101) + x
y <- seq(0, 1, 1/23)
f_y <- runif(24) + (1 - y)
plot(x, f_x, type="l")
lines(y, f_y)
Then I would like to compute Integral( | f_x - f_y | )dx.
(This is not the same as | Integral(f_x)dx - Integral(f_y)dx |.)
Computing this integral looks non trivial. I guess I should interpolate
the points of f_y over x and integrate both lines on these intervals.
Even then I would miss points where the lines cross.
There are functions to integrate below *one* line (I'm thinking about
the trapz function in caTools).
Do you know if there is a function to do this integration properly with
two lines (and especially their absolute difference)?
Regards,
Xavier