independent: Set independent variable for first order derivatives

Description Usage Arguments Value Examples

View source: R/rad.R

Description

Set independent variable for first order derivatives

Usage

1

Arguments

x

numeric vector to be differentiated with respect to

Value

a fAD vector with value being x and jacobian being the identity

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
x <- independent(c(0,1))
y <- sum(square(x))/2
print(gradient(y)) # should be c(0,1)

# define some function
f <- function(x){ 
M <- matrix(x,2,2)
return(sum(solve(M,c(-1,2))))
}

# run function with regular variables
print(f(c(1,-1,2,4)))

# run function with AD-variables
x <- independent(c(1,-1,2,4))
y <- f(x)
print(value(y))
print(gradient(y))

torekleppe/RAutoDiff documentation built on Dec. 23, 2021, noon