Convenience constructor for the independent variable when computing derivatives. Sets deriv = 1 so that the output's derivative slot contains \(df/dx\).

dual_variable(x)

Arguments

x

A numeric value.

Value

A dual with value = x and deriv = 1.

Examples

x <- dual_variable(2)
deriv(x^2)  # 4 = 2*x evaluated at x=2
#> [1] 4