
y
at the points
x
.trapz(x, y)
min(x)
to max(x)
.(x, 0)
and (x, y)
are taken as vertices of a
polygon and the area is computed using polyarea
. This approach matches exactly the approximation for integrating the
function using the trapezoidal rule with basepoints x
.
polyarea
# Calculate the area under the sine curve from 0 to pi:
x <- seq(0, pi, len=101)
y <- sin(x)
trapz(x, y) #=> 1.999836
Run the code above in your browser using DataLab