Description Usage Arguments Details Value Author(s) References Examples
These are three different utility functions that create matrices containing the symbolic partial derivatives of first (makeGrad
) and second (makeHess
) order and a function for evaluating these matrices in an environment. The evaluations of the symbolic derivatives are used within the propagate
function to calculate the propagated uncertainty, but these functions may also be useful for other applications.
1 2 3 |
expr |
an expression, such as |
order |
order of creating partial derivatives, i.e. |
deriv |
a matrix returned from |
envir |
an environment to evaluate in. By default the workspace. |
Given a function f(x_1, x_2, …, x_n), the following matrices containing symbolic derivatives of f are returned:
makeGrad:
\nabla(f) = ≤ft[\frac{\partial f}{\partial x_1}, …, \frac{\partial f}{\partial x_n}\right]
makeHess:
H(f) = ≤ft[ \begin{array}{cccc} \frac{\partial^2 f}{\partial x_1^2} & \frac{\partial^2 f}{\partial x_1\,\partial x_2} & \cdots & \frac{\partial^2 f}{\partial x_1\,\partial x_n} \\ \frac{\partial^2 f}{\partial x_2\,\partial x_1} & \frac{\partial^2 f}{\partial x_2^2} & \cdots & \frac{\partial^2 f}{\partial x_2\,\partial x_n} \\ \vdots & \vdots & \ddots & \vdots \\ \frac{\partial^2 f}{\partial x_n\,\partial x_1} & \frac{\partial^2 f}{\partial x_n\,\partial x_2} & \cdots & \frac{\partial^2 f}{\partial x_n^2} \end{array} \right]
The symbolic or evaluated Gradient/Hessian matrices.
Andrej-Nikolai Spiess
The Matrix Cookbook (Version November 2012).
Petersen KB & Pedersen MS.
http://ais.informatik.uni-freiburg.de/teaching/ws12/mapping/pdf/imm3274.pdf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | EXPR <- expression(a^b + sin(c))
ENVIR <- list(a = 2, b = 3, c = 4)
## First-order partial derivatives: Gradient.
GRAD <- makeGrad(EXPR)
## This will evaluate the Gradient.
evalDerivs(GRAD, ENVIR)
## Second-order partial derivatives: Hessian.
HESS <- makeHess(EXPR)
## This will evaluate the Hessian.
evalDerivs(HESS, ENVIR)
## Change derivatives order.
GRAD <- makeGrad(EXPR, order = c(2,1,3))
evalDerivs(GRAD, ENVIR)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.