vc_plot_differential: Plot a differential and the actual finite change

View source: R/plot_local_models.R

vc_plot_differentialR Documentation

Plot a differential and the actual finite change

Description

Show dx, the approximate differential dy, and the finite change delta_y. Dy and delta_y are shown at the same endpoint: use hover and legend controls to compare overlapping segments.

Usage

vc_plot_differential(
  result,
  f,
  xlim = NULL,
  n = 401L,
  colors = c(curve = "#24476b", line = "#c44736", point = "#222222", differential =
    "#188367", change = "#8250a3"),
  title = NULL,
  xlab = "x",
  ylab = "y"
)

Arguments

result

Plain result list from the corresponding calculation function.

f

The same deterministic scalar function used for the calculation. Function values at the stored anchor points must match the result.

xlim

Optional increasing pair of finite real plot limits, containing the anchor points. NULL derives limits around the anchors.

n

Integer number of curve samples, at least 2. The curve is a sampled visualization, not an exact representation or a continuity test.

colors

Named character vector with entries curve, line, point, differential, and change; values are Plotly/CSS colors.

title

Optional scalar plot title. NULL uses a descriptive default.

xlab, ylab

Scalar axis labels.

Details

All sampling limitations of vc_plot_secant() apply. The subtitle identifies derivative sensitivity status and the selected method. The differential endpoint uses y0 + dy at the representable x1; dx is the requested increment, which can differ slightly from x1 - x0 in doubles.

Value

An interactive plotly htmlwidget with the function, approximate tangent, anchors, and separate labeled increment segments.

Examples

if (requireNamespace("plotly", quietly = TRUE)) {
  f <- function(x) x^2
  vc_differential(f, 1, 0.2) |> vc_plot_differential(f = f)
}

vectorialcalculus documentation built on Nov. 17, 2026, 1:09 a.m.