fcts_add_fct {dfdr}R Documentation

appending a S4 class of type fcts

Description

A function which appends a S4 class of type fcts with a new function-derivative pair.

Usage

fcts_add_fct(lst, f, f_deriv, keep = FALSE)

Arguments

lst

is the S4 class of type fcts. Newly created by fcts()

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 d(). The default value is FALSE.

Details

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.

Value

a S4 class of type fcts extended by the new function-derivative pair.

Note

The body of f and f_deriv have to be defined without curly brackets.

Examples

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

[Package dfdr version 0.2.0 Index]