Message-ID: <4D3FFC3D.4080606@unige.ch>
Date: 2011-01-26T10:49:33Z
From: Xavier Robin
Subject: Integration of two lines
In-Reply-To: <3306DAD6-034A-4107-AF13-259DC6DD92F5@temple.edu>
Hans W Borchers wrote :
> First define a function from those points:
>
> fx <- approxfun(x, f_x)
> fy <- approxfun(y, f_y)
> f <- function(x) abs(fx(x)-fy(x))
>
> and now you can apply integrate() or trapz():
>
> xx <- sort(c(x, y))
> yy <- f(xx)
> trapz(xx, yy)
>
> trapz() should return the more accurate (i.e. exact) result.
Thanks a lot Hans!
I didn't know about the 'approx' functions and that was exaclty what I
needed!
Regards,
Xavier