View source: R/fct_deriv_pairs.R
fcts_add_fct | R Documentation |
A function which appends a S4 class of type fcts with a new function-derivative pair.
fcts_add_fct(lst, f, f_deriv, keep = FALSE)
lst |
is the S4 class of type fcts. Newly created by |
f |
is the function which should be differentiated. The argument has to be of type function. |
f_deriv |
is a function defining the derivative of f. The argument has to be of type function. |
keep |
is a logical value. If set to TRUE the function f is ignored of |
The following functions are already supported:
sin, sinh, asin, cos, cosh, acos, tan, tanh, atan, exp, log, sqrt, c, vector, numeric, rep and matrix.
Notably, for the functions: c, vector, numeric, rep and matrix the function is ignored during differentiation.
a S4 class of type fcts extended by the new function-derivative pair.
The body of f and f_deriv have to be defined without curly brackets.
library(dfdr) # Initialize list lst <- dfdr::fcts() # The function which should be added f <- function(x) x^2 # The dervative function of f f_deriv <- function(x) 2*x # add new entry to list lst <- fcts_add_fct(lst, f, f_deriv) g <- function(z) f(z) df <- d(g, z, lst) df
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.