if (interactive()) {
f <- function(x, y) exp(-(x^2 + y^2)) * (1 + 0.3 * cos(3*x) * sin(2*y))
out <- riemann_sum_2d_plot(
f, xlim = c(-2, 2), ylim = c(-2, 2),
nx = 8, ny = 7, methods = c("lower","mid","upper"),
show_surface = TRUE, surface_res = c(80, 80),
surface_colorscale = "YlGnBu", surface_opacity = 0.45
)
out$lower_sum; out$mid_sum; out$upper_sum
}
Run the code above in your browser using DataLab