Compute column vector of first derivatives and matrix of second derivatives of univariate function.

score(expr, vars, simplify = TRUE)

hessian(expr, vars, simplify = TRUE)

Arguments

expr

'caracas expression'.

vars

variables to take derivative with respect to.

simplify

Try to simplify result using simplify(); may be time consuming.

See also

Examples


if (has_sympy()) {
  def_sym(b0, b1, x, x0)
  f <- b0 / (1 + exp(b1*(x-x0)))
  S <- score(f, c(b0, b1))
  S
  H <- hessian(f, c(b0, b1))
  H
}
#> c: ⎡                                                (-x + x₀)⋅exp(b₁⋅(x - x₀))   
#>    ⎢            0                                   ──────────────────────────   
#>    ⎢                                                                       2     
#>    ⎢                                                 (exp(b₁⋅(x - x₀)) + 1)      
#>
#>    ⎢                                         2                                 2 
#>    ⎢(-x + x₀)⋅exp(b₁⋅(x - x₀))    b₀⋅(x - x₀) ⋅exp(b₁⋅(x - x₀))   2⋅b₀⋅(x - x₀) ⋅
#>    ⎢──────────────────────────  - ───────────────────────────── + ───────────────
#>    ⎢                       2                               2                     
#>    ⎣ (exp(b₁⋅(x - x₀)) + 1)          (exp(b₁⋅(x - x₀)) + 1)            (exp(b₁⋅(x
#>    
#>
#>
#>
#>
#>
#>
#>    exp(2⋅b₁⋅(x - x₀))⎥
#>    ──────────────────⎥
#>                3     ⎥
#>     - x₀)) + 1)      ⎦