Description Usage Arguments Details Value Author(s) Examples
Calculate the x and y gradients for a 2D matrix
1 | gradient(f, x, y, dx, dy)
|
f |
the 2D field for which to calculate the gradient |
x,y |
vectors of the |
dx,dy |
scalar giving the |
Calculates the gradient in each of the two directions, x
and
y
, corresponding to rows and columns of f
. Uses
centred differencing in the interior, and forward/backward
differencing at the edges. Is more or less equivalent to Matlab's
gradient function, except that the sense of x,y
is different
in that they correspond to rows/columns.
A list containing the directional gradients corresponding to the x,y
directions.
Clark Richards
1 2 3 4 5 6 7 8 9 | library(oce) # for drawDirectionFields
x <- seq(-2, 2, 0.2)
y <- seq(-2, 2, 0.2)
X <- matrix(expand.grid(x,y)[,1], nrow=length(x))
Y <- matrix(expand.grid(x,y)[,2], nrow=length(x))
F <- X * exp(-X^2 - Y^2)
g <- gradient(F, dx=0.2, dy=0.2)
contour(x, y, F)
drawDirectionField(as.vector(X), as.vector(Y), g$gx, g$gy, scalex=1, add=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.