powered by
y
x
trapz(x, y)
min(x)
max(x)
(x, 0)
(x, y)
polyarea
This approach matches exactly the approximation for integrating the function using the trapezoidal rule with basepoints x.
# 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