[R] Integration of two lines
Xavier Robin
Xavier.Robin at unige.ch
Wed Jan 26 11:49:33 CET 2011
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
More information about the R-help
mailing list