Derivada e integral
# -----------------------------------------------------------------------------
# Cálculo
# -----------------------------------------------------------------------------
# Derivada
f = expression(2 * x + 3)
f
## expression(2 * x + 3)
## [1] 2
D(expression(2 * x + 3),
'x')
## [1] 2
## expression({
## .value <- 2 * x + 3
## .grad <- array(0, c(length(.value), 1L), list(NULL, c("x")))
## .grad[, "x"] <- 2
## attr(.value, "gradient") <- .grad
## .value
## })
deriv(expression(2 * x^2 + x + 4),
'x')
## expression({
## .value <- 2 * x^2 + x + 4
## .grad <- array(0, c(length(.value), 1L), list(NULL, c("x")))
## .grad[, "x"] <- 2 * (2 * x) + 1
## attr(.value, "gradient") <- .grad
## .value
## })
# Integral
f1 = function(x){
x/2 * (0 < x & x <= 5)
}
integrate(f1,
1,
3)
## 2 with absolute error < 2.2e-14
# Para uma álgera mais avançada, consulte o pacote Ryacas.