vc_tangent: Construct an approximate tangent line

View source: R/local_models.R

vc_tangentR Documentation

Construct an approximate tangent line

Description

Use vc_derivative() to construct the local line y0 + slope * (x - x0). The numerical line is not proof that a mathematical tangent exists.

Usage

vc_tangent(
  f,
  x0,
  method = c("central", "forward", "backward"),
  h = NULL,
  atol = 1e-08,
  rtol = 1e-04,
  warn = TRUE
)

Arguments

f

Deterministic function accepting a real scalar and returning one finite real scalar. Vectorization is not required.

x0

Finite real scalar evaluation point of the local model.

method

One of "central", "forward", or "backward".

h

Positive finite real initial derivative step, or NULL for the heuristic used by vc_derivative(), evaluated with x = x0.

atol

Nonnegative finite absolute tolerance for sensitivity comparisons.

rtol

Nonnegative finite relative tolerance for sensitivity comparisons.

warn

Logical scalar; warn when sensitivity diagnostics fail.

Details

A two-sided tangent requires differentiability at x0. One-sided methods instead construct a one-sided approximation, which may differ from a two-sided tangent. All limitations of vc_derivative apply.

Value

Plain list with type ("tangent"), x0, y0, slope, derivative (the full vc_derivative result), and note. Inspect derivative$reliable and its diagnostics before interpreting the slope. Failed diagnostics retain the approximation, with a warning unless warn = FALSE.

Examples

vc_tangent(function(x) x^2, 1)
sin |> vc_tangent(x0 = 0)
vc_tangent(abs, 0, warn = FALSE)$derivative$reliable

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