Learn R Programming

Deriv (version 2.0)

Deriv-package: Symbolic Differentiation

Description

R already contains two differentiation functions: D and deriv.

R's existing functions have several limitations. Limitations include:

  • The derivatives table can't be modified at runtime, and is only available in C.
  • Function cannot substitute function calls. eg: f <- function(x, y) x + y; deriv(~f(x, x^2), "x")

Here are the advantages this implementation:

  • It is entirely written in R, so would be easier to maintain.
  • Can differentiate function calls: - if the function is in the derivative table, then the chain rule is applied. For example, if you declared that the derivative of sin is cos, then it would figure out how to call cos correctly. - if the function is not in the derivative table (or it is anonymous), then the function body is substituted in. - these two methods can be mixed. An entry in the derivative table need not be self-contained -- you don't need to provide an infinite chain of derivatives.
  • It's easy to add custom entries to the derivatives table, e.g. drule[["cos"]] <- list(quote(-._d1*sin(._1)))
  • The output can be an executable function, which makes it suitable for use in optimization problems.

Arguments

Details

ll{ Package: Deriv Type: Package Version: 2.0 Date: 2015-02-05 License: GPL (>= 3) } The package contains two useful functions: Deriv() for differentiating expressions, Simplify() for simplifying symbolically.

References

https://andrewclausen.net/computing/deriv.html

See Also

D, deriv, package Ryacas

Examples

Run this code
f <- function(x) x^2
Deriv(f)
# function (x)
# 2 * x

Run the code above in your browser using DataLab