Learn R Programming

vectorialcalculus (version 1.0.5)

riemann_prisms3d: Riemann rectangular prisms over a planar region

Description

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.

Usage

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")
)

Value

A list containing:

sum_lower

Lower Riemann sum for the chosen partition.

sum_upper

Upper Riemann sum.

sum_mean

Mean-value Riemann sum.

cells

A tibble describing all valid cells.

fig

A plotly object if plot = TRUE, otherwise NULL.

estimate

When estimate != "all", the selected Riemann sum (lower/upper/mean) is repeated here for convenience.

Arguments

f

A function f(x, y) returning a numeric scalar.

f1, f2

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.

a, b

Numeric endpoints of the x-interval. Must satisfy a < b.

N, M

Integer numbers of subdivisions in x and y for the rectangular partition.

plot

Logical. If TRUE, the 3D visualization is generated.

estimate

Character. One of "lower", "upper", "mean", or "all", indicating which estimate to highlight.

sample_n

Integer. Number of evaluation points per direction inside each cell when computing lower, upper, and mean values.

show_surface

Logical. If TRUE, draws the surface z = F(x, y) over the entire rectangular bounding box.

surface_colorscale

Colorscale used for the surface.

surface_opacity

Opacity for the surface.

show_surface_grid

Logical. If TRUE, draws a grid on the surface.

surface_grid_color

Color of the grid lines.

surface_grid_width

Width of the grid lines.

color_by

Character. Determines the value used to color the top of each prism: "mean", "lower", or "upper".

top_colorscale

Colorscale for the prism tops.

top_opacity

Opacity of the prism tops.

side_color

Color for the vertical faces of the prisms.

side_opacity

Opacity of the prism sides.

frame_color

Color for the prism frame lines.

frame_width

Width of the frame lines.

scene

A list with plotly 3D scene settings.

bg

A list with background colors for the figure.

Examples

Run this code
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