Learn R Programming

vectorialcalculus (version 1.0.5)

riemann_rectangles2d: Animate Riemann rectangles under a curve (2D)

Description

Builds an interactive Plotly animation of Riemann sums approximating the area under a function on a closed interval.

Usage

riemann_rectangles2d(
  f,
  a,
  b,
  n_vals = NULL,
  method = c("midpoint", "left", "right"),
  n_curve = 400L,
  frame_ms = 900L,
  transition_ms = 0L,
  title = NULL,
  show_sum = TRUE,
  y0 = 0
)

Value

A plotly object (htmlwidget) with animation frames.

Arguments

f

Function. A real-valued function. It must accept a numeric vector and return a numeric vector of the same length.

a

Numeric scalar. Left endpoint.

b

Numeric scalar. Right endpoint. Must satisfy b > a.

n_vals

Integer vector. Values of the number of subintervals used as animation frames. If NULL, a default increasing sequence is used.

method

Character. Rule used for rectangle heights: "midpoint" (default), "left", or "right".

n_curve

Integer. Number of points used to draw the base curve.

frame_ms

Integer. Frame duration in milliseconds.

transition_ms

Integer. Transition duration in milliseconds.

title

Character. Plot title. If NULL, a default title is used.

show_sum

Logical. If TRUE, show n and the value of the Riemann sum in hover text.

y0

Numeric scalar. Baseline for rectangles (default 0).

Examples

Run this code
# \donttest{
library(plotly)
f <- function(x) x^2
riemann_rectangles2d(f, 0, 1)
# }

Run the code above in your browser using DataLab