Approximates the double integral of a scalar function over a planar region using an N-by-M rectangular partition and rectangular prisms with constant height on each cell. The region is defined by an x-interval and two functions giving the lower and upper y-limits. Each valid cell produces a prism whose height corresponds to a chosen estimate of the function on that cell: lower value, upper value, or mean value.
When plot = TRUE, a 3D visualization of the prisms is produced using
plotly. Optionally, the actual surface z = F(x, y) can also be
drawn over the rectangular bounding box that contains the region.
riemann_prisms3d(
f,
f1,
f2,
a,
b,
N,
M,
plot = TRUE,
estimate = c("lower", "upper", "mean", "all"),
sample_n = 6,
show_surface = FALSE,
surface_colorscale = "Viridis",
surface_opacity = 0.35,
show_surface_grid = TRUE,
surface_grid_color = "rgba(60,80,200,0.25)",
surface_grid_width = 1,
color_by = c("mean", "lower", "upper"),
top_colorscale = "YlOrBr",
top_opacity = 0.85,
side_color = "rgba(60,60,60,0.25)",
side_opacity = 0.35,
frame_color = "rgba(0,0,0,0.55)",
frame_width = 1.5,
scene = list(aspectmode = "data", xaxis = list(title = "x"), yaxis = list(title = "y"),
zaxis = list(title = "z")),
bg = list(paper = "white", plot = "white")
)A list containing:
sum_lowerLower Riemann sum for the chosen partition.
sum_upperUpper Riemann sum.
sum_meanMean-value Riemann sum.
cellsA tibble describing all valid cells.
figA plotly object if plot = TRUE, otherwise NULL.
estimateWhen estimate != "all", the selected
Riemann sum (lower/upper/mean) is repeated here for convenience.
A function f(x, y) returning a numeric scalar.
Functions returning the lower and upper y-boundaries for each x. The valid y-range at each x is the interval between the minimum and maximum of these two functions.
Numeric endpoints of the x-interval. Must satisfy a < b.
Integer numbers of subdivisions in x and y for the rectangular partition.
Logical. If TRUE, the 3D visualization is generated.
Character. One of "lower", "upper",
"mean", or "all", indicating which estimate to highlight.
Integer. Number of evaluation points per direction inside each cell when computing lower, upper, and mean values.
Logical. If TRUE, draws the surface
z = F(x, y) over the entire rectangular bounding box.
Colorscale used for the surface.
Opacity for the surface.
Logical. If TRUE, draws a grid on the surface.
Color of the grid lines.
Width of the grid lines.
Character. Determines the value used to color the top of
each prism: "mean", "lower", or "upper".
Colorscale for the prism tops.
Opacity of the prism tops.
Color for the vertical faces of the prisms.
Opacity of the prism sides.
Color for the prism frame lines.
Width of the frame lines.
A list with plotly 3D scene settings.
A list with background colors for the figure.
f <- function(x, y) x * y
f1 <- function(x) 0
f2 <- function(x) 1 - x
riemann_prisms3d(f, f1, f2, 0, 1, N = 10, M = 10, plot = FALSE)
Run the code above in your browser using DataLab