Learn R Programming

modello (version 0.1.1)

dfun.numeric: Finite Differences

Description

Estimates the derivate (or gradient) of the function fn with respect to the argument x

Usage

# S3 method for numeric
dfun(x, fn)

# S3 method for array dfun(x, fn)

dfun(x, fn)

Arguments

x

input numeric

fn

function

Value

Returns the gradient of x

Examples

Run this code
# NOT RUN {
fn = function(x)x**2
## On scalar arguments
dx_scalar = dfun(3, fn)
print(dx_scalar)
## On matrix (or arrays)
dx_array = dfun(matrix(c(3, 3, 3, 3), 2, 2), fn)
print(dx_array)
# }

Run the code above in your browser using DataLab