Grad

Grad[f,{x1,,xn}]

gives the gradient .

Grad[f,{x1,,xn},chart]

gives the gradient in the coordinates chart.

Details

  • Grad[f,x] can be input as xf. The character can be typed as del or \[Del]. The list of variables x is entered as a subscript.
  • An empty template can be entered as grad, and moves the cursor from the subscript to the main body.
  • All quantities that do not explicitly depend on the variables given are taken to have zero partial derivative.
  • If f is an array of dimensions {n1,,nk}, then Grad[f,{x1,,xm}] yields an array of dimensions {n1,,nk,m}.
  • If f is a scalar, Grad[f,{x1,x2,,xn},chart] returns a vector in the orthonormal basis associated with chart.
  • In Grad[f,{x1,,xn},chart], if f is an array, it must have dimensions {n,,n}. The components of f are interpreted as being in the orthonormal basis associated with chart.
  • Coordinate charts in the third argument of Grad can be specified as triples {coordsys,metric,dim} in the same way as in the first argument of CoordinateChartData. The short form in which dim is omitted may be used.
  • Grad works with SparseArray and structured array objects.

Examples

open allclose all

Basic Examples  (4)

The gradient in three-dimensional Cartesian coordinates:

The gradient using an orthonormal basis for three-dimensional cylindrical coordinates:

The gradient in two dimensions:

Use del to enter and to enter the list of subscripted variables:

Use grad to enter the template ; press to move between inputs:

Scope  (7)

The gradient of a vector field in Cartesian coordinates, the Jacobian matrix:

Compute the Hessian of a scalar function:

In a curvilinear coordinate system, a vector with constant components may have a nonzero gradient:

Gradient specifying metric, coordinate system, and parameters:

Grad works on curved spaces:

The gradient of the coordinates with respect to themselves:

This is the identity matrix in n dimensions:

The gradient of the norm in n dimensions:

Specialize to the result in three dimensions:

Applications  (4)

Compute the force from a potential function:

Find the critical points of a function of two variables:

Compute the signs of and the Hessian determinant:

By the second derivative test, the first two pointsred and blue in the plotare minima, and the thirdgreen in the plotis a saddle point:

Find the critical points of a function of three variables:

Compute the Hessian matrix of f:

When the eigenvalues of a critical point all have the same sign, the point is a local extremum; if there are both positive and negative values, it is a saddle point:

Since the third and fourth points have all positive eigenvalues, they are local minima, and the global minimum can be determined by evaluating f at those two points:

For this function, any three of the critical points are linearly dependent, so they all lie in a single plane:

Compute the normal to that plane:

Visualize the function, with the minima green and the non-extreme critical points red:

Compute the gradients at the origin of a vector-valued function up to order 6:

View the value of the function and its first three derivatives at the origin:

Compute the third-order Maclaurin series of f by hand:

Programmatically compute the sixth-order Maclaurin series:

Properties & Relations  (4)

Grad[f,vars] is effectively equivalent to D[f,{vars}]:

Grad adds a new tensor slot at the end, corresponding to a new innermost dimension:

To add the new slot at the beginning, use Transpose to exchange the first and last slots:

This is relevant when working with directional derivatives of arrays:

The gradient of an array equals the gradient of its components only in Cartesian coordinates:

Grad preserves the structure of SymmetrizedArray objects:

The gradient has an additional dimension but the same symmetry as the input:

Interactive Examples  (2)

The normal vectors to the level contours of a function equal the normalized gradient of the function:

Create an interactive contour plot that displays the normal at a point:

View expressions for the gradient of a scalar function in different coordinate systems:

Introduced in 2012
 (9.0)
 |
Updated in 2014
 (10.0)