/usr/lib/R/site-library/numDeriv/doc/Guide.Stex is in r-cran-numderiv 2016.8-1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | \documentclass[english]{article}
\begin{document}
%\VignetteIndexEntry{numDeriv Guide}
\SweaveOpts{eval=TRUE,echo=TRUE,results=hide,fig=FALSE}
\begin{Scode}{echo=FALSE,results=hide}
options(continue=" ")
\end{Scode}
\section{Functions to calculate Numerical Derivatives and Hessian Matrix}
In R, the functions in this package are made available with
\begin{Scode}
library("numDeriv")
\end{Scode}
The code from the vignette that generates this guide can
be loaded into an editor with \emph{edit(vignette("Guide", package="numDeriv"))}.
This uses the default editor, which can be changed using \emph{options()}.
Here are some examples of grad.
\begin{Scode}
grad(sin, pi)
grad(sin, (0:10)*2*pi/10)
func0 <- function(x){ sum(sin(x)) }
grad(func0 , (0:10)*2*pi/10)
func1 <- function(x){ sin(10*x) - exp(-x) }
curve(func1,from=0,to=5)
x <- 2.04
numd1 <- grad(func1, x)
exact <- 10*cos(10*x) + exp(-x)
c(numd1, exact, (numd1 - exact)/exact)
x <- c(1:10)
numd1 <- grad(func1, x)
exact <- 10*cos(10*x) + exp(-x)
cbind(numd1, exact, (numd1 - exact)/exact)
\end{Scode}
Here are some examples of jacobian.
\begin{Scode}
func2 <- function(x) c(sin(x), cos(x))
x <- (0:1)*2*pi
jacobian(func2, x)
\end{Scode}
Here are some examples of hessian.
\begin{Scode}
x <- 0.25 * pi
hessian(sin, x)
fun1e <- function(x) sum(exp(2*x))
x <- c(1, 3, 5)
hessian(fun1e, x, method.args=list(d=0.01))
\end{Scode}
Here are some examples of genD.
\begin{Scode}
func <- function(x){c(x[1], x[1], x[2]^2)}
z <- genD(func, c(2,2,5))
z
\end{Scode}
\end{document}
|