grad.func | R Documentation |
Returns the vector gradient, \nabla f
, of a function, f(\vec{r})
, at aspecific point, \vec{r} = \vec{r}_o
, in its domain, once the tolerance, \epsilon
, for the calculation of the gradient has been provided.
Mathematically speaking, the function returns the expression shown below.
\nabla f(\vec{r})\bigg|_{\vec{r} = \vec{r}_o}
grad.func(f, pt, epsilon)
f |
The function, |
pt |
The point, |
epsilon |
This epsilon or
|
The value of epsilon
, \epsilon
, should be chosen wisely, depending on context.
The rate of rise or fall of the function between f(x_1 + \epsilon, \dots)
and f(x_1 - \epsilon, \dots)
should be considered.
See example below.
#build the function expfun <- function(X){ return(2*X^12) } #call grad.func grad.func(f = expfun, pt = 2*10^-9, epsilon = 10^-6) grad.func(f = expfun, pt = 2*10^-9, epsilon = 10^-15) #output > grad.func(f = expfun, pt = 2*10^-9, epsilon = 10^-6) [1] 4.800352e-68 > grad.func(f = expfun, pt = 2*10^-9, epsilon = 10^-15) [1] 4.9152e-95
The exact answer is 4.9152 \times 10^{-95}
, but \epsilon = 10^{-6}
is too large for a highly increasing function like f(x) = 2x^{12}
.
The returned value, \nabla f
, is always a vector whose length is equal to the length of the argument pt
or \vec{r}_o
Chitran Ghosal
https://en.wikipedia.org/wiki/Gradient
https://math.stackexchange.com/questions/2744497/what-does-gradient-actually-mean
##define the paraboloid function centered at (3,5)
para <- function(p){
return( (p[1] - 3)^2 + (p[2] - 5)^2)
}
#call the grad.func functions
grad.func(f=para, pt = c(3,5), epsilon = 10^-1)
grad.func(f=para, pt = c(0,0), epsilon = 10^-1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.